TerritoireController.cs 4.6 KB

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