ActionsEduController.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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, db, ModeAcces.Lecture);
  24. return View(model);
  25. }
  26. // GET: ActionsEdu/Details/5
  27. public ActionResult Details(int? id)
  28. {
  29. if (id == null)
  30. {
  31. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  32. }
  33. ActionEduFactory fact = new ActionEduFactory(db);
  34. Entity.ActionEdu actionEdu = fact.getById(id);
  35. if (actionEdu == null)
  36. {
  37. return HttpNotFound();
  38. }
  39. actionEdu.hydrate();
  40. ActionEduViewModel model = new ActionEduViewModel(actionEdu, db);
  41. return View(model);
  42. }
  43. // GET: ActionEduAxe/Create
  44. public ActionResult Create(int? annee_id)
  45. {
  46. if (annee_id == null)
  47. {
  48. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  49. }
  50. ActionEdu actionEdu = new ActionEdu();
  51. actionEdu.AnneeId = annee_id.Value;
  52. AnneeFactory fact = new AnneeFactory(db);
  53. actionEdu.Annee = fact.getById(annee_id);
  54. actionEdu.hydrate();
  55. ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Creation);
  56. return View(model);
  57. }
  58. // POST: ActionEduAxe/Create
  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 Create(ActionEdu actionEdu)
  64. {
  65. if (ModelState.IsValid)
  66. {
  67. ActionEduFactory fact = new ActionEduFactory(db);
  68. fact.add(ref actionEdu);
  69. return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
  70. }
  71. actionEdu.hydrate();
  72. ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Creation);
  73. return View(model);
  74. }
  75. // GET: ActionEduAxe/Edit/5
  76. public ActionResult Edit(int? id)
  77. {
  78. if (id == null)
  79. {
  80. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  81. }
  82. ActionEduFactory fact = new ActionEduFactory(db);
  83. ActionEdu action = fact.getById(id.Value);
  84. if (action == null)
  85. {
  86. return HttpNotFound();
  87. }
  88. action.hydrate();
  89. ActionEduViewModel model = new ActionEduViewModel(action, db, ModeAcces.Modification);
  90. return View(model);
  91. }
  92. // POST: ActionEduAxe/Edit/5
  93. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  94. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  95. [HttpPost]
  96. [ValidateAntiForgeryToken]
  97. public ActionResult Edit(ActionEdu actionEdu)
  98. {
  99. if (ModelState.IsValid)
  100. {
  101. ActionEduFactory fact = new ActionEduFactory(db);
  102. fact.update(ref actionEdu);
  103. return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
  104. }
  105. if (actionEdu.Annee == null)
  106. {
  107. db.ActionsEdu.Attach(actionEdu);
  108. db.Entry(actionEdu).Reference(i => i.Annee).Load();
  109. }
  110. actionEdu.hydrate();
  111. ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Modification);
  112. return View(model);
  113. }
  114. // GET: ActionEduAxe/Delete/5
  115. public ActionResult Delete(int? id)
  116. {
  117. if (id == null)
  118. {
  119. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  120. }
  121. ActionEduFactory fact = new ActionEduFactory(db);
  122. ActionEdu actionEdu = fact.getById(id.Value);
  123. if (actionEdu == null)
  124. {
  125. return HttpNotFound();
  126. }
  127. actionEdu.hydrate();
  128. ActionEduViewModel model = new ActionEduViewModel(actionEdu, db);
  129. return View(model);
  130. }
  131. // POST: ActionEduAxe/Delete/5
  132. [HttpPost, ActionName("Delete")]
  133. [ValidateAntiForgeryToken]
  134. public ActionResult DeleteConfirmed(int id)
  135. {
  136. ActionEduFactory fact = new ActionEduFactory(db);
  137. ActionEdu actionEdu = fact.getById(id);
  138. fact.delete(ref actionEdu);
  139. return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
  140. }
  141. public ActionResult Up(int? id)
  142. {
  143. if (id == null)
  144. {
  145. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  146. }
  147. ActionEduFactory fact = new ActionEduFactory(db);
  148. ActionEdu actionEdu = fact.getById(id.Value);
  149. fact.Up(ref actionEdu);
  150. return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
  151. }
  152. public ActionResult Down(int? id)
  153. {
  154. if (id == null)
  155. {
  156. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  157. }
  158. ActionEduFactory fact = new ActionEduFactory(db);
  159. ActionEdu actionEdu = fact.getById(id.Value);
  160. fact.Down(ref actionEdu);
  161. return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
  162. }
  163. protected override void Dispose(bool disposing)
  164. {
  165. if (disposing)
  166. {
  167. db.Dispose();
  168. }
  169. base.Dispose(disposing);
  170. }
  171. }
  172. }