| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Web.Mvc;
- using System.Net;
- using CD67.FicheCollege.Factory;
- using CD67.FicheCollege.Entity;
- using CD67.FicheCollege.MVC.Models;
- using System.Collections.Generic;
- using System.Web;
- using System;
- namespace CD67.FicheCollege.MVC.Controllers
- {
- public class AnneesController : Controller
- {
- private Entities db = new Entities();
- // GET: Annees
- public ActionResult Index()
- {
- AnneeFactory fact = new AnneeFactory(db);
- AnneeIndexViewModel model = new AnneeIndexViewModel(fact.getAll());
- return View(model);
- }
- // GET: Home
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- HttpCookie cookie = new HttpCookie("last_selected_year");
- cookie.Value = id.ToString();
- cookie.Expires = DateTime.Now.AddMonths(1);
- Response.SetCookie(cookie);
- AnneeFactory anneeFactory = new AnneeFactory(db);
- Entity.Annee annee = anneeFactory.getById(id);
- if (annee == null)
- {
- return HttpNotFound();
- }
- AnneeViewModel model = new AnneeViewModel(annee, db);
- return View(model);
- }
- public ActionResult Previous(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- AnneeFactory anneeFactory = new AnneeFactory(db);
- Entity.Annee annee = anneeFactory.getById(id);
- if (annee == null)
- {
- return HttpNotFound();
- }
- AnneeViewModel model = new AnneeViewModel(annee, db);
- return View(model);
- }
- public ActionResult Next(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- AnneeFactory anneeFactory = new AnneeFactory(db);
- Entity.Annee annee = anneeFactory.getById(id);
- if (annee == null)
- {
- return HttpNotFound();
- }
- AnneeViewModel model = new AnneeViewModel(annee, db);
- return View(model);
- }
- [HttpGet]
- public JsonResult GetList()
- {
- AnneeFactory fact = new AnneeFactory(db);
- List<Annee> annees = new List<Annee>();
- int max_id = 0;
- foreach (Annee annee in fact.getManyBy(a => a.Colleges.Count > 0))
- {
- annees.Add(annee.flat());
- if (annee.Id > max_id) { max_id = annee.Id; }
- }
- annees.Add(fact.getById(max_id + 1).flat());
- annees.Add(fact.getById(max_id + 2).flat());
- JsonResult res = Json(annees);
- res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
- return res;
- }
- }
- }
|