AnneesController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Web.Mvc;
  2. using System.Net;
  3. using CD67.FicheCollege.Factory;
  4. using CD67.FicheCollege.Entity;
  5. using CD67.FicheCollege.MVC.Models;
  6. using System.Collections.Generic;
  7. using System.Web;
  8. using System;
  9. namespace CD67.FicheCollege.MVC.Controllers
  10. {
  11. public class AnneesController : Controller
  12. {
  13. private Entities db = new Entities();
  14. // GET: Annees
  15. public ActionResult Index()
  16. {
  17. AnneeFactory fact = new AnneeFactory(db);
  18. AnneeIndexViewModel model = new AnneeIndexViewModel(fact.getAll());
  19. return View(model);
  20. }
  21. // GET: Home
  22. public ActionResult Details(int? id)
  23. {
  24. if (id == null)
  25. {
  26. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  27. }
  28. HttpCookie cookie = new HttpCookie("last_selected_year");
  29. cookie.Value = id.ToString();
  30. cookie.Expires = DateTime.Now.AddMonths(1);
  31. Response.SetCookie(cookie);
  32. AnneeFactory anneeFactory = new AnneeFactory(db);
  33. Entity.Annee annee = anneeFactory.getById(id);
  34. if (annee == null)
  35. {
  36. return HttpNotFound();
  37. }
  38. AnneeViewModel model = new AnneeViewModel(annee, db);
  39. return View(model);
  40. }
  41. public ActionResult Previous(int? id)
  42. {
  43. if (id == null)
  44. {
  45. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  46. }
  47. AnneeFactory anneeFactory = new AnneeFactory(db);
  48. Entity.Annee annee = anneeFactory.getById(id);
  49. if (annee == null)
  50. {
  51. return HttpNotFound();
  52. }
  53. AnneeViewModel model = new AnneeViewModel(annee, db);
  54. return View(model);
  55. }
  56. public ActionResult Next(int? id)
  57. {
  58. if (id == null)
  59. {
  60. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  61. }
  62. AnneeFactory anneeFactory = new AnneeFactory(db);
  63. Entity.Annee annee = anneeFactory.getById(id);
  64. if (annee == null)
  65. {
  66. return HttpNotFound();
  67. }
  68. AnneeViewModel model = new AnneeViewModel(annee, db);
  69. return View(model);
  70. }
  71. }
  72. }