TypeCollegeController.cs 5.9 KB

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