ActionsEduCollegeController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 ActionsEduCollegeController : Controller
  12. {
  13. private Entities db = new Entities();
  14. // GET: ActionsEdu
  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);
  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. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  34. Entity.ActionEduCollege actionEduCollege = fact.getById(id);
  35. if (actionEduCollege == null)
  36. {
  37. return HttpNotFound();
  38. }
  39. ActionEduCollegeViewModel model = new ActionEduCollegeViewModel(actionEduCollege, db);
  40. return View(model);
  41. }
  42. // GET: ActionEduCollege/Create
  43. public ActionResult Create(int? actionEdu_id)
  44. {
  45. if (actionEdu_id == null)
  46. {
  47. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  48. }
  49. ActionEduCollege actionEduCollege = new ActionEduCollege();
  50. actionEduCollege.ActionEduId = actionEdu_id.Value;
  51. ActionEduFactory fact = new ActionEduFactory(db);
  52. actionEduCollege.ActionEdu = fact.getById(actionEdu_id);
  53. ActionEduCollegeViewModel model = new ActionEduCollegeViewModel(actionEduCollege, db, ModeAcces.Creation);
  54. return View("Edit", model);
  55. }
  56. // POST: ActionEduAxe/Create
  57. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  58. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  59. [HttpPost]
  60. [ValidateAntiForgeryToken]
  61. public ActionResult Create(ActionEduCollege actionEduCollege)
  62. {
  63. if (ModelState.IsValid)
  64. {
  65. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  66. fact.add(ref actionEduCollege);
  67. return RedirectToAction("Details", "ActionsEdu", new { Id = actionEduCollege.ActionEduId });
  68. }
  69. ActionEduCollegeViewModel model = new ActionEduCollegeViewModel(actionEduCollege, db, ModeAcces.Creation);
  70. return View("Edit", model);
  71. }
  72. // GET: ActionEduAxe/Edit/5
  73. public ActionResult Edit(int? id)
  74. {
  75. if (id == null)
  76. {
  77. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  78. }
  79. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  80. ActionEduCollege actionEduCollege = fact.getById(id.Value);
  81. if (actionEduCollege == null)
  82. {
  83. return HttpNotFound();
  84. }
  85. ActionEduCollegeViewModel model = new ActionEduCollegeViewModel(actionEduCollege, db, ModeAcces.Modification);
  86. return View(model);
  87. }
  88. // POST: ActionEduAxe/Edit/5
  89. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  90. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  91. [HttpPost]
  92. [ValidateAntiForgeryToken]
  93. public ActionResult Edit(ActionEduCollege actionEduCollege)
  94. {
  95. if (ModelState.IsValid)
  96. {
  97. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  98. fact.update(ref actionEduCollege);
  99. return RedirectToAction("Details", new { id = actionEduCollege.Id });
  100. }
  101. ActionEduCollegeViewModel model = new ActionEduCollegeViewModel(actionEduCollege, db, ModeAcces.Modification);
  102. return View(model);
  103. }
  104. // GET: ActionEduAxe/Delete/5
  105. public ActionResult Delete(int? id)
  106. {
  107. if (id == null)
  108. {
  109. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  110. }
  111. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  112. ActionEduCollege actionEduCollege = fact.getById(id.Value);
  113. if (actionEduCollege == null)
  114. {
  115. return HttpNotFound();
  116. }
  117. DeleteViewModel model = new DeleteViewModel(actionEduCollege, "Affectation", actionEduCollege.College.Libelle);
  118. return View("~/Views/Shared/_AdminDeleteWarning.cshtml", model);
  119. }
  120. // POST: ActionEduAxe/Delete/5
  121. [HttpPost, ActionName("Delete")]
  122. [ValidateAntiForgeryToken]
  123. public ActionResult DeleteConfirmed(int id)
  124. {
  125. ActionEduCollegeFactory fact = new ActionEduCollegeFactory(db);
  126. ActionEduCollege actionEduCollege = fact.getById(id);
  127. fact.delete(ref actionEduCollege);
  128. return RedirectToAction("Details", "ActionsEdu", new { id = actionEduCollege.ActionEduId });
  129. }
  130. }
  131. }