ActionsCLASController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 ActionsCLASController : Controller
  14. {
  15. private Entities db = new Entities();
  16. // GET: ActionCLAS/Details/5
  17. public ActionResult Details(int? id)
  18. {
  19. if (id == null)
  20. {
  21. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  22. }
  23. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  24. Entity.ActionCLAS actionClas = actionClasFactory.getById(id);
  25. if (actionClas == null)
  26. {
  27. return HttpNotFound();
  28. }
  29. return View(GetViewModel(actionClas, Models.ModeAcces.Lecture));
  30. }
  31. // GET: ActionCLAS/Edit/5
  32. public ActionResult Edit(int? id)
  33. {
  34. if (id == null)
  35. {
  36. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  37. }
  38. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  39. Entity.ActionCLAS actionClas = actionClasFactory.getById(id);
  40. if (actionClas == null)
  41. {
  42. return HttpNotFound();
  43. }
  44. return View(GetViewModel(actionClas, Models.ModeAcces.Modification));
  45. }
  46. // POST: ActionCLAS/Edit/5
  47. // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
  48. // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
  49. [HttpPost]
  50. [ValidateAntiForgeryToken]
  51. public ActionResult Edit(ActionCLAS Contenu)
  52. {
  53. if (ModelState.IsValid)
  54. {
  55. ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
  56. actionClasFactory.update(ref Contenu);
  57. return RedirectToAction("Index");
  58. }
  59. return View(GetViewModel(Contenu, Models.ModeAcces.Modification));
  60. }
  61. private Models.CollegeViewModel_old GetViewModel(Entity.ActionCLAS action, Models.ModeAcces Acces)
  62. {
  63. return new Models.CollegeViewModel_old()
  64. {
  65. College_Id = action.College.Id,
  66. //CodeRne = action.College.CodeRne,
  67. //Annee_Id = action.College.Annee_Id,
  68. College_Libelle = action.College.Libelle,
  69. Contenu = action,
  70. Acces = Acces,
  71. Listes = null
  72. };
  73. }
  74. protected override void Dispose(bool disposing)
  75. {
  76. if (disposing)
  77. {
  78. db.Dispose();
  79. }
  80. base.Dispose(disposing);
  81. }
  82. }
  83. }