TypeCollegeController.cs 5.2 KB

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