| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System.Net;
- using System.Web.Mvc;
- using CD67.FicheCollege.Entity;
- using CD67.FicheCollege.Factory;
- using CD67.FicheCollege.MVC.Models;
- using CD67.FicheCollege.MVC.Internal;
- namespace CD67.FicheCollege.MVC.Controllers
- {
- public class CollegesController : Controller
- {
- private Entities db = new Entities();
- // GET: Colleges
- 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: Colleges/Details/5
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- CollegeFactory collegeFactory = new CollegeFactory(db);
- Entity.College college = collegeFactory.getById(id);
- if (college == null)
- {
- return HttpNotFound();
- }
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Lecture);
- return View(model);
- }
- // GET: Colleges/Create
- public ActionResult Create(int? annee_id)
- {
- if (annee_id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Entity.College college = new Entity.College();
- college.Annee_Id = annee_id.Value;
- AnneeFactory fact = new AnneeFactory(db);
- college.Annee = fact.getById(annee_id);
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Creation);
- return View("Edit", model);
- }
- // POST: Colleges/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(Entity.College college)
- {
- if (ModelState.IsValid)
- {
- CollegeFactory collegeFactory = new CollegeFactory(db);
- collegeFactory.add(ref college);
- return RedirectToAction("Details", new { id = college.Id });
- }
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Creation);
- return View("Edit", model);
- }
- // GET: Colleges/Edit/5
- public ActionResult Edit(int? id)
- {
- CollegeFactory collegeFactory = new CollegeFactory(db);
- Entity.College college = collegeFactory.getById(id);
- if (college == null)
- {
- return HttpNotFound();
- }
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Modification);
- return View(model);
- }
- // POST: Colleges/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(Entity.College college)
- {
- if (ModelState.IsValid)
- {
- CollegeFactory collegeFactory = new CollegeFactory(db);
- collegeFactory.update(ref college);
- return RedirectToAction("Details", new { Id = college.Id });
- }
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Modification);
- return View(model);
- }
- // GET: College/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- CollegeFactory collegeFactory = new CollegeFactory(db);
- Entity.College college = collegeFactory.getById(id);
- if (college == null)
- {
- return HttpNotFound();
- }
- CollegeViewModel model = new CollegeViewModel(college, db, ModeAcces.Suppression);
- return View("Details", model);
- }
- // POST: College/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- CollegeFactory collegeFactory = new CollegeFactory(db);
- Entity.College college = collegeFactory.getById(id);
- int annee_id = college.Annee_Id;
- collegeFactory.delete(ref college);
- return RedirectToAction("Index", new { annee_id = annee_id });
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|