TYPE_VIKINGController.cs 4.6 KB

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