VIKINGSController.cs 4.7 KB

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