ActionsCLASController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ActionClasViewModel model = new ActionClasViewModel(actionClas, ModeAcces.Modification);
  63. return View(model);
  64. }
  65. protected override void Dispose(bool disposing)
  66. {
  67. if (disposing)
  68. {
  69. db.Dispose();
  70. }
  71. base.Dispose(disposing);
  72. }
  73. }
  74. }