ActionsEduCollegeController.cs 5.1 KB

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