TerritoireController.cs 4.5 KB

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