| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 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 RestaurationTypeRepasController : Controller
- {
- private Entities db = new Entities();
- // GET: RestaurationTypeRepas
- public ActionResult Index()
- {
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepaIndexViewModel model = new RestaurationTypeRepaIndexViewModel(fact.getAll());
- return View(model);
- }
- // GET: RestaurationTypeRepas/Create
- public ActionResult Create()
- {
- RestaurationTypeRepa repas = new RestaurationTypeRepa();
- RestaurationTypeRepaViewModel model = new RestaurationTypeRepaViewModel(repas, ModeAcces.Creation);
- return View(model);
- }
- // POST: RestaurationTypeRepas/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(RestaurationTypeRepa repas)
- {
- if (ModelState.IsValid)
- {
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- fact.add(ref repas);
- return RedirectToAction("Index");
- }
- RestaurationTypeRepaViewModel model = new RestaurationTypeRepaViewModel(repas, ModeAcces.Creation);
- return View(model);
- }
- // GET: RestaurationTypeRepas/Edit/5
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepa repas = fact.getById(id.Value);
- if (repas == null)
- {
- return HttpNotFound();
- }
- RestaurationTypeRepaViewModel model = new RestaurationTypeRepaViewModel(repas, ModeAcces.Modification);
- return View(model);
- }
- // POST: RestaurationTypeRepas/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(RestaurationTypeRepa repas)
- {
- if (ModelState.IsValid)
- {
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- fact.update(ref repas);
- return RedirectToAction("Index");
- }
- RestaurationTypeRepaViewModel model = new RestaurationTypeRepaViewModel(repas, ModeAcces.Modification);
- return View(model);
- }
- // GET: RestaurationTypeRepas/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepa repas = fact.getById(id.Value);
- if (repas == null)
- {
- return HttpNotFound();
- }
- RestaurationTypeRepaViewModel model = new RestaurationTypeRepaViewModel(repas);
- return View(model);
- }
- // POST: RestaurationTypeRepas/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepa repas = fact.getById(id);
- fact.delete(ref repas);
- return RedirectToAction("Index");
- }
- public ActionResult Up(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepa repas = fact.getById(id.Value);
- fact.Up(ref repas);
- return RedirectToAction("Index");
- }
- public ActionResult Down(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- RestaurationTypeRepaFactory fact = new RestaurationTypeRepaFactory(db);
- RestaurationTypeRepa repas = fact.getById(id.Value);
- fact.Down(ref repas);
- return RedirectToAction("Index");
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|