TYPE_VIKINGController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Net;
  2. using System.Web.Mvc;
  3. using CD67.ModeleMVC.Entity;
  4. using CD67.ModeleMVC.Factory;
  5. namespace CD67.ModeleMVC.MVC.Controllers
  6. {
  7. public class TYPE_VIKINGController : Controller
  8. {
  9. private Entities db = new Entities();
  10. // GET: TYPE_VIKING
  11. public ActionResult Index()
  12. {
  13. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  14. return View(typeVikingFactory.getAll());
  15. }
  16. // GET: TYPE_VIKING/Details/5
  17. public ActionResult Details(int? id)
  18. {
  19. if (id == null)
  20. {
  21. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  22. }
  23. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  24. EXEMPLE_TYPE_VIKING typeViking = typeVikingFactory.getById(id.Value);
  25. if (typeViking == null)
  26. {
  27. return HttpNotFound();
  28. }
  29. return View(typeViking);
  30. }
  31. // GET: TYPE_VIKING/Create
  32. public ActionResult Create()
  33. {
  34. EXEMPLE_TYPE_VIKING typeViking = new EXEMPLE_TYPE_VIKING();
  35. return View(typeViking);
  36. }
  37. // POST: TYPE_VIKING/Create
  38. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  39. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  40. [HttpPost]
  41. [ValidateAntiForgeryToken]
  42. public ActionResult Create([Bind(Include = "ID,TYPE")] EXEMPLE_TYPE_VIKING typeViking)
  43. {
  44. if (ModelState.IsValid)
  45. {
  46. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  47. typeVikingFactory.add(ref typeViking);
  48. return RedirectToAction("Index");
  49. }
  50. return View(typeViking);
  51. }
  52. // GET: TYPE_VIKING/Edit/5
  53. public ActionResult Edit(int? id)
  54. {
  55. if (id == null)
  56. {
  57. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  58. }
  59. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  60. EXEMPLE_TYPE_VIKING typeViking = typeVikingFactory.getById(id.Value);
  61. if (typeViking == null)
  62. {
  63. return HttpNotFound();
  64. }
  65. return View(typeViking);
  66. }
  67. // POST: TYPE_VIKING/Edit/5
  68. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  69. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  70. [HttpPost]
  71. [ValidateAntiForgeryToken]
  72. public ActionResult Edit([Bind(Include = "ID,TYPE")] EXEMPLE_TYPE_VIKING typeViking)
  73. {
  74. if (ModelState.IsValid)
  75. {
  76. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  77. typeVikingFactory.update(ref typeViking);
  78. return RedirectToAction("Index");
  79. }
  80. return View(typeViking);
  81. }
  82. // GET: TYPE_VIKING/Delete/5
  83. public ActionResult Delete(int? id)
  84. {
  85. if (id == null)
  86. {
  87. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  88. }
  89. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  90. EXEMPLE_TYPE_VIKING typeViking = typeVikingFactory.getById(id.Value);
  91. if (typeViking == null)
  92. {
  93. return HttpNotFound();
  94. }
  95. return View(typeViking);
  96. }
  97. // POST: TYPE_VIKING/Delete/5
  98. [HttpPost, ActionName("Delete")]
  99. [ValidateAntiForgeryToken]
  100. public ActionResult DeleteConfirmed(int id)
  101. {
  102. TYPE_VIKINGFactory typeVikingFactory = new TYPE_VIKINGFactory(db);
  103. EXEMPLE_TYPE_VIKING typeViking = typeVikingFactory.getById(id);
  104. typeVikingFactory.delete(ref typeViking);
  105. return RedirectToAction("Index");
  106. }
  107. protected override void Dispose(bool disposing)
  108. {
  109. if (disposing)
  110. {
  111. db.Dispose();
  112. }
  113. base.Dispose(disposing);
  114. }
  115. }
  116. }