ActionsCLASController.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 ActionsCLASController : Controller
  15. {
  16. private Entities db = new Entities();
  17. // GET: ActionCLAS/Details/5
  18. public ActionResult Details(int? id)
  19. {
  20. if (id == null)
  21. {
  22. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  23. }
  24. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  25. ActionCLAS actionClas = actionClasFactory.getById(id);
  26. if (actionClas == null)
  27. {
  28. return HttpNotFound();
  29. }
  30. ActionClasViewModel model = new ActionClasViewModel(actionClas);
  31. return View(model);
  32. }
  33. // GET: ActionCLAS/Edit/5
  34. public ActionResult Edit(int? id)
  35. {
  36. if (id == null)
  37. {
  38. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  39. }
  40. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  41. Entity.ActionCLAS actionClas = actionClasFactory.getById(id);
  42. if (actionClas == null)
  43. {
  44. return HttpNotFound();
  45. }
  46. ActionClasViewModel model = new ActionClasViewModel(actionClas, ModeAcces.Modification);
  47. return View(model);
  48. }
  49. // POST: ActionCLAS/Edit/5
  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 Edit(ActionCLAS actionClas)
  55. {
  56. if (ModelState.IsValid)
  57. {
  58. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  59. actionClasFactory.update(ref actionClas);
  60. return RedirectToAction("Details", new { id = actionClas.College_Id });
  61. }
  62. db.Entry(actionClas).Reference(i => i.College).Load();
  63. ActionClasViewModel model = new ActionClasViewModel(actionClas, ModeAcces.Modification);
  64. return View(model);
  65. }
  66. protected override void Dispose(bool disposing)
  67. {
  68. if (disposing)
  69. {
  70. db.Dispose();
  71. }
  72. base.Dispose(disposing);
  73. }
  74. }
  75. }