|
|
@@ -1,10 +1,4 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Data;
|
|
|
-using System.Data.Entity;
|
|
|
-using System.Linq;
|
|
|
-using System.Net;
|
|
|
-using System.Web;
|
|
|
+using System.Net;
|
|
|
using System.Web.Mvc;
|
|
|
using CD67.FicheCollege.Entity;
|
|
|
using CD67.FicheCollege.Factory;
|
|
|
@@ -17,18 +11,20 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
{
|
|
|
private Entities db = new Entities();
|
|
|
|
|
|
- // GET: College
|
|
|
+ // GET: Colleges
|
|
|
public ActionResult Index(int? annee_id)
|
|
|
{
|
|
|
if (annee_id == null)
|
|
|
{
|
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
|
}
|
|
|
- TopModel model = new TopModel(db.Colleges.Where(c=>c.Annee_Id == annee_id), ModeAcces.Lecture);
|
|
|
+ AnneeFactory fact = new AnneeFactory(db);
|
|
|
+ Annee annee = fact.getById(annee_id);
|
|
|
+ AnneeViewModel model = new AnneeViewModel(annee, ModeAcces.Lecture);
|
|
|
return View(model);
|
|
|
}
|
|
|
|
|
|
- // GET: College/Details/5
|
|
|
+ // GET: Colleges/Details/5
|
|
|
public ActionResult Details(int? id)
|
|
|
{
|
|
|
if (id == null)
|
|
|
@@ -42,45 +38,46 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
return HttpNotFound();
|
|
|
}
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Lecture);
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Lecture);
|
|
|
|
|
|
return View(model);
|
|
|
}
|
|
|
|
|
|
- // GET: College/Create
|
|
|
- public ActionResult Create()
|
|
|
+ // 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;
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Creation);
|
|
|
- model.Bag["Select_TypeCollege"] = new SelectList(db.TypesCollege.OrderBy(t=>t.Ordre).ToList());
|
|
|
- model.Bag["Select_CodePostaux"] = new SelectList(Referentiel.GetCodesPostaux(college.Commune_Insee));
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Creation);
|
|
|
|
|
|
return View("Edit", model);
|
|
|
}
|
|
|
|
|
|
- // POST: College/Create
|
|
|
+ // 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, string commentaire)
|
|
|
+ public ActionResult Create(Entity.College college)
|
|
|
{
|
|
|
if (ModelState.IsValid)
|
|
|
{
|
|
|
CollegeFactory collegeFactory = new CollegeFactory(db);
|
|
|
collegeFactory.add(ref college);
|
|
|
- return RedirectToAction("Index");
|
|
|
+ return RedirectToAction("Details", new { id = college.Id });
|
|
|
}
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Creation);
|
|
|
- model.Bag["Select_TypeCollege"] = new SelectList(db.TypesCollege.ToList(), college.TypeCollege_Id);
|
|
|
- model.Bag["Select_CodePostaux"] = new SelectList(Referentiel.GetCodesPostaux(college.Commune_Insee), college.Commune_Insee);
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Creation);
|
|
|
|
|
|
return View("Edit", model);
|
|
|
}
|
|
|
|
|
|
- // GET: College/Edit/5
|
|
|
+ // GET: Colleges/Edit/5
|
|
|
public ActionResult Edit(int? id)
|
|
|
{
|
|
|
CollegeFactory collegeFactory = new CollegeFactory(db);
|
|
|
@@ -90,14 +87,12 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
return HttpNotFound();
|
|
|
}
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Modification);
|
|
|
- model.Bag["Select_TypeCollege"] = new SelectList(db.TypesCollege.ToList(), college.TypeCollege_Id);
|
|
|
- model.Bag["Select_CodePostaux"] = new SelectList(Referentiel.GetCodesPostaux(college.Commune_Insee), college.Commune_Insee);
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Modification);
|
|
|
|
|
|
return View(model);
|
|
|
}
|
|
|
|
|
|
- // POST: College/Edit/5
|
|
|
+ // 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]
|
|
|
@@ -111,9 +106,7 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
return RedirectToAction("Details", new { Id = college.Id });
|
|
|
}
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Modification);
|
|
|
- model.Bag["Select_TypeCollege"] = new SelectList(db.TypesCollege.ToList(), college.TypeCollege_Id);
|
|
|
- model.Bag["Select_CodePostaux"] = new SelectList(Referentiel.GetCodesPostaux(college.Commune_Insee), college.Commune_Insee);
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Modification);
|
|
|
|
|
|
return View(model);
|
|
|
}
|
|
|
@@ -132,9 +125,7 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
return HttpNotFound();
|
|
|
}
|
|
|
|
|
|
- TopModel model = new TopModel(college, ModeAcces.Suppression);
|
|
|
- model.Bag["Select_TypeCollege"] = new SelectList(db.TypesCollege.ToList(), college.TypeCollege_Id);
|
|
|
- model.Bag["Select_CodePostaux"] = new SelectList(Referentiel.GetCodesPostaux(college.Commune_Insee), college.Commune_Insee);
|
|
|
+ CollegeViewModel model = new CollegeViewModel(college, ModeAcces.Suppression);
|
|
|
|
|
|
return View("Details", model);
|
|
|
}
|
|
|
@@ -142,12 +133,17 @@ namespace CD67.FicheCollege.MVC.Controllers
|
|
|
// POST: College/Delete/5
|
|
|
[HttpPost, ActionName("Delete")]
|
|
|
[ValidateAntiForgeryToken]
|
|
|
- public ActionResult DeleteConfirmed(string id)
|
|
|
+ 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");
|
|
|
+ return RedirectToAction("Index", new { annee_id = annee_id });
|
|
|
}
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|