|
|
@@ -0,0 +1,120 @@
|
|
|
+using CD67.FicheCollege.Entity;
|
|
|
+using CD67.FicheCollege.Factory;
|
|
|
+using CD67.FicheCollege.MVC.Models;
|
|
|
+using System.Net;
|
|
|
+using System.Web.Mvc;
|
|
|
+
|
|
|
+namespace CD67.FicheCollege.MVC.Controllers
|
|
|
+{
|
|
|
+ public class GroupesController : Controller
|
|
|
+ {
|
|
|
+ private Entities db = new Entities();
|
|
|
+
|
|
|
+ // GET: Groupes
|
|
|
+ public ActionResult Index()
|
|
|
+ {
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ GroupeIndexViewModel model = new GroupeIndexViewModel(fact.getAll());
|
|
|
+ return View(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ // GET: Groupe/Create
|
|
|
+ public ActionResult Create()
|
|
|
+ {
|
|
|
+ Groupe groupe = new Groupe();
|
|
|
+
|
|
|
+ GroupeViewModel model = new GroupeViewModel(groupe, ModeAcces.Creation);
|
|
|
+ return View("Edit", model);
|
|
|
+ }
|
|
|
+
|
|
|
+ // POST: Groupe/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(Groupe groupe)
|
|
|
+ {
|
|
|
+ if (ModelState.IsValid)
|
|
|
+ {
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ fact.add(ref groupe);
|
|
|
+ return RedirectToAction("Index");
|
|
|
+ }
|
|
|
+
|
|
|
+ GroupeViewModel model = new GroupeViewModel(groupe, ModeAcces.Creation);
|
|
|
+ return View("Edit", model);
|
|
|
+ }
|
|
|
+
|
|
|
+ // GET: ActionEduAxe/Edit/5
|
|
|
+ public ActionResult Edit(int? id)
|
|
|
+ {
|
|
|
+ if (id == null)
|
|
|
+ {
|
|
|
+ return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
|
+ }
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ Groupe groupe = fact.getById(id.Value);
|
|
|
+ if (groupe == null)
|
|
|
+ {
|
|
|
+ return HttpNotFound();
|
|
|
+ }
|
|
|
+ GroupeViewModel model = new GroupeViewModel(groupe, 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]
|
|
|
+ [ValidateAntiForgeryToken]
|
|
|
+ public ActionResult Edit(Groupe groupe)
|
|
|
+ {
|
|
|
+ if (ModelState.IsValid)
|
|
|
+ {
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ fact.update(ref groupe);
|
|
|
+ return RedirectToAction("Index");
|
|
|
+ }
|
|
|
+ GroupeViewModel model = new GroupeViewModel(groupe, ModeAcces.Modification);
|
|
|
+ return View(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ // GET: ActionEduAxe/Delete/5
|
|
|
+ public ActionResult Delete(int? id)
|
|
|
+ {
|
|
|
+ if (id == null)
|
|
|
+ {
|
|
|
+ return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
|
+ }
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ Groupe groupe = fact.getById(id.Value);
|
|
|
+ if (groupe == null)
|
|
|
+ {
|
|
|
+ return HttpNotFound();
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteViewModel model = new DeleteViewModel(groupe, "Groupe", groupe.Nom);
|
|
|
+ return View("~/Views/Shared/_AdminDeleteWarning.cshtml", model);
|
|
|
+ }
|
|
|
+
|
|
|
+ // POST: ActionEduAxe/Delete/5
|
|
|
+ [HttpPost, ActionName("Delete")]
|
|
|
+ [ValidateAntiForgeryToken]
|
|
|
+ public ActionResult DeleteConfirmed(int id)
|
|
|
+ {
|
|
|
+ GroupeFactory fact = new GroupeFactory(db);
|
|
|
+ Groupe groupe = fact.getById(id);
|
|
|
+ fact.delete(ref groupe);
|
|
|
+ return RedirectToAction("Index");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void Dispose(bool disposing)
|
|
|
+ {
|
|
|
+ if (disposing)
|
|
|
+ {
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+ base.Dispose(disposing);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|