ActionEduThematiquesController.cs 5.3 KB

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