TypeCollegeController.cs 6.0 KB

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