| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Entity;
- using System.Linq;
- using System.Net;
- using System.Web;
- using System.Web.Mvc;
- using CD67.FicheCollege.Entity;
- using CD67.FicheCollege.Factory;
- using CD67.FicheCollege.MVC.Models;
- using CD67.PIMP.MVC.Internal;
- namespace CD67.FicheCollege.MVC.Controllers
- {
- [Acces(groupes = "AdminColleges")]
- public class TypeCollegeController : Controller
- {
- private Entities db = new Entities();
- // GET: TypeCollege
- public ActionResult Index()
- {
- TypeCollegeFactory fact = new TypeCollegeFactory(db);
- TypeCollegeIndexViewModel model = new TypeCollegeIndexViewModel(fact.getAll());
- return View(model);
- }
- // GET: TypeCollege/Details/5
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id.Value);
- if (typeCollege == null)
- {
- return HttpNotFound();
- }
- TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
- return View(model);
- }
- // GET: TypeCollege/Create
- public ActionResult Create()
- {
- Entity.TypeCollege typeCollege = new Entity.TypeCollege();
- TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege, ModeAcces.Creation);
- return View("Edit", model);
- }
- // POST: TypeCollege/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]
- [ValidateAntiForgeryToken]
- public ActionResult Create(TypeCollege typeCollege)
- {
- if (ModelState.IsValid)
- {
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- typeCollegeFactory.add(ref typeCollege);
- return RedirectToAction("Index");
- }
- TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege, ModeAcces.Creation);
- return View("Edit", model);
- }
- // GET: TypeCollege/Edit/5
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id.Value);
- if (typeCollege == null)
- {
- return HttpNotFound();
- }
- TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege, ModeAcces.Modification);
- return View(model);
- }
- // POST: TypeCollege/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]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(TypeCollege typeCollege)
- {
- if (ModelState.IsValid)
- {
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- typeCollegeFactory.update(ref typeCollege);
- return RedirectToAction("Index");
- }
- TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege, ModeAcces.Modification);
- return View(model);
- }
- // GET: TypeCollege/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id.Value);
- if (typeCollege == null)
- {
- return HttpNotFound();
- }
- DeleteViewModel model = new DeleteViewModel(typeCollege, "Type de Collège", typeCollege.Libelle);
- return View("~/Views/Shared/_AdminDeleteWarning.cshtml", model);
- }
- // POST: TypeCollege/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id);
- typeCollegeFactory.delete(ref typeCollege);
- return RedirectToAction("Index");
- }
- public ActionResult Up(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id.Value);
- typeCollegeFactory.Up(ref typeCollege);
- return RedirectToAction("Index");
- }
- public ActionResult Down(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
- Entity.TypeCollege typeCollege = typeCollegeFactory.getById(id.Value);
- typeCollegeFactory.Down(ref typeCollege);
- return RedirectToAction("Index");
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|