ActionsEduController.cs 5.5 KB

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