IdentitesController.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 IdentitesController : Controller
  15. {
  16. private Entities db = new Entities();
  17. // GET: Identite/Details/5
  18. public ActionResult Details(int? id)
  19. {
  20. if (id == null)
  21. {
  22. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  23. }
  24. IdentiteFactory identiteFactory = new IdentiteFactory(db);
  25. Entity.Identite identite = identiteFactory.getById(id);
  26. if (identite == null)
  27. {
  28. return HttpNotFound();
  29. }
  30. IdentiteViewModel model = new IdentiteViewModel(identite);
  31. return View(model);
  32. }
  33. // GET: Identite/Edit/5
  34. public ActionResult Edit(int? id)
  35. {
  36. if (id == null)
  37. {
  38. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  39. }
  40. IdentiteFactory identiteFactory = new IdentiteFactory(db);
  41. Entity.Identite identite = identiteFactory.getById(id);
  42. if (identite == null)
  43. {
  44. return HttpNotFound();
  45. }
  46. IdentiteViewModel model = new IdentiteViewModel(identite, ModeAcces.Modification);
  47. return View(model);
  48. }
  49. // POST: Identite/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(Entity.Identite identite)
  55. {
  56. if (ModelState.IsValid)
  57. {
  58. IdentiteFactory identiteFactory = new IdentiteFactory(db);
  59. identiteFactory.update(ref identite);
  60. return RedirectToAction("Details", new { Id = identite.College_Id });
  61. }
  62. IdentiteViewModel model = new IdentiteViewModel(identite, 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. }