| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using CD67.FicheCollege.Entity;
- using CD67.FicheCollege.Factory;
- using CD67.FicheCollege.MVC.Models;
- using CD67.PIMP.MVC.Internal;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Web;
- using System.Web.Mvc;
- namespace CD67.FicheCollege.MVC.Controllers
- {
- public class ActionsEduController : Controller
- {
- private Entities db = new Entities();
- // GET: Actions
- public ActionResult Index(int? annee_id)
- {
- if (annee_id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- AnneeFactory fact = new AnneeFactory(db);
- Annee annee = fact.getById(annee_id);
- AnneeViewModel model = new AnneeViewModel(annee, db, ModeAcces.Lecture);
- return View(model);
- }
- // GET: ActionsEdu/Details/5
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ActionEduFactory fact = new ActionEduFactory(db);
- Entity.ActionEdu actionEdu = fact.getById(id);
- if (actionEdu == null)
- {
- return HttpNotFound();
- }
- ActionEduViewModel model = new ActionEduViewModel(actionEdu, db);
- return View(model);
- }
- // GET: ActionEduAxe/Create
- [Acces(groupes = "AdminActionsEdu")]
- public ActionResult Create(int? annee_id)
- {
- if (annee_id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ActionEdu actionEdu = new ActionEdu();
- actionEdu.AnneeId = annee_id.Value;
- AnneeFactory fact = new AnneeFactory(db);
- actionEdu.Annee = fact.getById(annee_id);
- actionEdu.TokenId = Guid.NewGuid();
- ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Creation);
- return View("Edit", model);
- }
- // POST: ActionEduAxe/Create
- // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
- // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [Acces(groupes = "AdminActionsEdu")]
- [ValidateAntiForgeryToken]
- public ActionResult Create(ActionEdu actionEdu)
- {
- if (ModelState.IsValid)
- {
- ActionEduFactory fact = new ActionEduFactory(db);
- fact.add(ref actionEdu);
- return RedirectToAction("Details", new { id = actionEdu.Id });
- }
- ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Creation);
- return View("Edit", model);
- }
- // GET: ActionEduAxe/Edit/5
- [Acces(groupes = "AdminActionsEdu")]
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ActionEduFactory fact = new ActionEduFactory(db);
- ActionEdu action = fact.getById(id.Value);
- if (action == null)
- {
- return HttpNotFound();
- }
- ActionEduViewModel model = new ActionEduViewModel(action, db, ModeAcces.Modification);
- return View(model);
- }
- // POST: ActionEduAxe/Edit/5
- // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
- // plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [Acces(groupes = "AdminActionsEdu")]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(ActionEdu actionEdu)
- {
- if (ModelState.IsValid)
- {
- ActionEduFactory fact = new ActionEduFactory(db);
- fact.update(ref actionEdu);
- return RedirectToAction("Details", new { id = actionEdu.Id });
- }
- if (actionEdu.Annee == null)
- {
- db.ActionsEdu.Attach(actionEdu);
- db.Entry(actionEdu).Reference(i => i.Annee).Load();
- }
- ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Modification);
- return View(model);
- }
- // GET: ActionEduAxe/Delete/5
- [Acces(groupes = "AdminActionsEdu")]
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ActionEduFactory fact = new ActionEduFactory(db);
- ActionEdu actionEdu = fact.getById(id.Value);
- if (actionEdu == null)
- {
- return HttpNotFound();
- }
- ActionEduViewModel model = new ActionEduViewModel(actionEdu, db, ModeAcces.Suppression);
- return View("Details", model);
- }
- // POST: ActionEduAxe/Delete/5
- [HttpPost, ActionName("Delete")]
- [Acces(groupes = "AdminActionsEdu")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- ActionEduCollegeFactory aec_fact = new ActionEduCollegeFactory(db);
- aec_fact.deleteMany(a => a.ActionEduId == id);
- ActionEduFactory fact = new ActionEduFactory(db);
- ActionEdu actionEdu = fact.getById(id);
- int annee_id = actionEdu.AnneeId;
- fact.delete(ref actionEdu);
- return RedirectToAction("Index", new { annee_id = annee_id });
- }
- public List<ActionEdu> actions_non_importees(int annee_id)
- {
- List<ActionEdu> non_importees = new List<ActionEdu>();
- AnneeFactory fact = new AnneeFactory(db);
- Annee annee_prec = fact.getById(annee_id - 1);
- foreach (ActionEdu actionEdu in annee_prec.ActionsEdu)
- {
- // Pour chaque college de l'année précédente, on vérifie s'il existe dans l'année en cours en se basant sur le TokenId
- if (!db.ActionsEdu.Any(a => a.TokenId == actionEdu.TokenId && a.AnneeId == annee_id))
- {
- non_importees.Add(actionEdu);
- }
- }
- return non_importees;
- }
- [Acces(groupes = "AdminActionsEdu")]
- public ActionResult Import(int? annee_id)
- {
- if (annee_id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ImportActionEduViewModel model = new ImportActionEduViewModel();
- model.Annee_Id = annee_id.Value;
- model.Annee_Lib = db.Annees.Where(a => a.Id == annee_id.Value).First().Libelle;
- List<ActionEdu> non_importes = actions_non_importees(annee_id.Value);
- model.set_liste(non_importes);
- for (int i = 0; i < non_importes.Count; i++)
- {
- ActionEdu actionEdu = non_importes[i];
- foreach (ActionEduCollege aec in actionEdu.ActionsEduColleges)
- {
- if (!db.Colleges.Where(c=>c.TokenId==aec.College.TokenId && c.Annee_Id == annee_id.Value).Any())
- {
- model.actionsEdu_averts[i].Add(aec.College.Libelle);
- }
- }
- }
- return View(model);
- }
- [HttpPost]
- [Acces(groupes = "AdminActionsEdu")]
- [ValidateAntiForgeryToken]
- public ActionResult Import(int Annee_Id, List<int> actionsEdu_ids, List<bool> selection)
- {
- ActionEduFactory fact = new ActionEduFactory(db);
- for (int i = 0; i < selection.Count; i++)
- {
- if (selection[i])
- {
- int actionEdu_id = actionsEdu_ids[i];
- ActionEdu actionEdu = fact.getById(actionEdu_id);
- fact.clone_to_year(actionEdu, Annee_Id);
- }
- }
- return RedirectToAction("Index", new { annee_id = Annee_Id });
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|