Forráskód Böngészése

Thematiques: Crud ok

olivier.massot 7 éve
szülő
commit
75862805b5

+ 8 - 4
CD67.FicheCollege.Entity/Extend/ActionEduThematique.cs

@@ -20,15 +20,19 @@ namespace CD67.FicheCollege.Entity
     /// </summary>
     public class ActionEduThematique_Metadata
     {
-        [Required(ErrorMessage = "Obligatoire")]
+        [Required]
         public int Id { get; set; }
 
-        [Required(ErrorMessage = "Obligatoire")]
-        [Display(Name = "Thématique")]
+        [Required]
+        [Display(Name = "Axe")]
+        public int ActionEduAxeId { get; set; }
+
+        [Required]
+        [Display(Name = "Nom de la Thématique")]
         public string Nom { get; set; }
 
         [Display(Name = "Neutralisé (oui/non)")]
-        public bool Neutralise { get; set; }
+        public bool? Neutralise { get; set; }
 
         public int Ordre { get; set; }
     }

+ 4 - 4
CD67.FicheCollege.MVC/Controllers/ActionEduAxesController.cs

@@ -23,7 +23,7 @@ namespace CD67.FicheCollege.MVC.Controllers
         {
             ActionEduAxe axe = new ActionEduAxe();
 
-            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe);
+            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe, ModeAcces.Creation);
             return View(model);
         }
 
@@ -41,7 +41,7 @@ namespace CD67.FicheCollege.MVC.Controllers
                 return RedirectToAction("Index");
             }
 
-            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe);
+            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe, ModeAcces.Creation);
             return View(model);
         }
 
@@ -58,7 +58,7 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return HttpNotFound();
             }
-            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe);
+            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe, ModeAcces.Modification);
             return View(model);
         }
 
@@ -75,7 +75,7 @@ namespace CD67.FicheCollege.MVC.Controllers
                 fact.update(ref axe);
                 return RedirectToAction("Index");
             }
-            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe);
+            ActionEduAxeViewModel model = new ActionEduAxeViewModel(axe, ModeAcces.Modification);
             return View(model);
         }
 

+ 27 - 44
CD67.FicheCollege.MVC/Controllers/ActionEduThematiquesController.cs

@@ -18,28 +18,11 @@ namespace CD67.FicheCollege.MVC.Controllers
             return View(model);
         }
 
-        // GET: ActionEduThematique/Details/5
-        public ActionResult Details(int? id)
-        {
-            if (id == null)
-            {
-                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
-            }
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id.Value);
-            if (ActionEduThematique == null)
-            {
-                return HttpNotFound();
-            }
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
-            return View(model);
-        }
-
         // GET: ActionEduThematique/Create
         public ActionResult Create()
         {
-            Entity.ActionEduThematique ActionEduThematique = new Entity.ActionEduThematique();
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
+            ActionEduThematique thematique = new ActionEduThematique();
+            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(thematique, db, ModeAcces.Creation);
             return View(model);
         }
 
@@ -48,16 +31,16 @@ namespace CD67.FicheCollege.MVC.Controllers
         // plus de détails, voir  http://go.microsoft.com/fwlink/?LinkId=317598.
         [HttpPost]
         [ValidateAntiForgeryToken]
-        public ActionResult Create(ActionEduThematique ActionEduThematique)
+        public ActionResult Create(ActionEduThematique thematique)
         {
             if (ModelState.IsValid)
             {
-                ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-                ActionEduThematiqueFactory.add(ref ActionEduThematique);
+                ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+                fact.add(ref thematique);
                 return RedirectToAction("Index");
             }
 
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
+            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(thematique, db, ModeAcces.Creation);
             return View(model);
         }
 
@@ -68,13 +51,13 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             }
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id.Value);
-            if (ActionEduThematique == null)
+            ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+            Entity.ActionEduThematique thematique = fact.getById(id.Value);
+            if (thematique == null)
             {
                 return HttpNotFound();
             }
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
+            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(thematique, db, ModeAcces.Modification);
             return View(model);
         }
 
@@ -83,15 +66,15 @@ namespace CD67.FicheCollege.MVC.Controllers
         // plus de détails, voir  http://go.microsoft.com/fwlink/?LinkId=317598.
         [HttpPost]
         [ValidateAntiForgeryToken]
-        public ActionResult Edit(ActionEduThematique ActionEduThematique)
+        public ActionResult Edit(ActionEduThematique thematique)
         {
             if (ModelState.IsValid)
             {
-                ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-                ActionEduThematiqueFactory.update(ref ActionEduThematique);
+                ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+                fact.update(ref thematique);
                 return RedirectToAction("Index");
             }
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
+            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(thematique, db, ModeAcces.Modification);
             return View(model);
         }
 
@@ -102,13 +85,13 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             }
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id.Value);
-            if (ActionEduThematique == null)
+            ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+            Entity.ActionEduThematique thematique = fact.getById(id.Value);
+            if (thematique == null)
             {
                 return HttpNotFound();
             }
-            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(ActionEduThematique);
+            ActionEduThematiqueViewModel model = new ActionEduThematiqueViewModel(thematique, db);
             return View(model);
         }
 
@@ -117,9 +100,9 @@ namespace CD67.FicheCollege.MVC.Controllers
         [ValidateAntiForgeryToken]
         public ActionResult DeleteConfirmed(int id)
         {
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id);
-            ActionEduThematiqueFactory.delete(ref ActionEduThematique);
+            ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+            Entity.ActionEduThematique thematique = fact.getById(id);
+            fact.delete(ref thematique);
             return RedirectToAction("Index");
         }
 
@@ -129,9 +112,9 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             }
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id.Value);
-            ActionEduThematiqueFactory.Up(ref ActionEduThematique);
+            ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+            Entity.ActionEduThematique thematique = fact.getById(id.Value);
+            fact.Up(ref thematique);
             return RedirectToAction("Index");
         }
 
@@ -141,9 +124,9 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             }
-            ActionEduThematiqueFactory ActionEduThematiqueFactory = new ActionEduThematiqueFactory(db);
-            Entity.ActionEduThematique ActionEduThematique = ActionEduThematiqueFactory.getById(id.Value);
-            ActionEduThematiqueFactory.Down(ref ActionEduThematique);
+            ActionEduThematiqueFactory fact = new ActionEduThematiqueFactory(db);
+            Entity.ActionEduThematique thematique = fact.getById(id.Value);
+            fact.Down(ref thematique);
             return RedirectToAction("Index");
         }
 

+ 8 - 1
CD67.FicheCollege.MVC/Models/ActionEduThematiqueViewModel.cs

@@ -8,8 +8,15 @@ namespace CD67.FicheCollege.MVC.Models
 {
     public class ActionEduThematiqueViewModel : BaseViewModel<ActionEduThematique>
     {
-        public ActionEduThematiqueViewModel(ActionEduThematique model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        public SelectList Sel_Axes;
+
+        public ActionEduThematiqueViewModel(ActionEduThematique model, Entities dbContext, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
         {
+            if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
+            {
+                ActionEduAxeFactory fact = new ActionEduAxeFactory(dbContext);
+                Sel_Axes = new SelectList(fact.getAll(), "Id", "Nom", Obj.ActionEduAxeId);
+            }
         }
 
         public override string Annee_Lib { get { return ""; } }

+ 16 - 0
CD67.FicheCollege.MVC/Views/ActionEduThematiques/Create.cshtml

@@ -27,6 +27,22 @@
             </div>
         </div>
 
+        <div class="form-group">
+            @Html.LabelFor(model => thematique.Neutralise, htmlAttributes: new { @class = "control-label col-md-2" })
+            <div class="col-md-10">
+                @Html.EditorFor(model => thematique.Neutralise, new { htmlAttributes = new { @class = "form-control" } })
+                @Html.ValidationMessageFor(model => thematique.Neutralise, "", new { @class = "text-danger" })
+            </div>
+        </div>
+
+        <div class="form-group">
+            @Html.LabelFor(model => thematique.ActionEduAxeId, htmlAttributes: new { @class = "control-label col-md-2" })
+            <div class="col-md-10">
+                @Html.DropDownListFor(model => thematique.ActionEduAxeId, Model.Sel_Axes, htmlAttributes: new { @class = "form-control" })
+                @Html.ValidationMessageFor(model => thematique.ActionEduAxeId, "", new { @class = "text-danger" })
+            </div>
+        </div>
+
         <div class="form-group">
             <div class="col-md-offset-2 col-md-10">
                 <input type="submit" value="Créer" class="btn btn-default" />

+ 1 - 1
CD67.FicheCollege.MVC/Views/ActionEduThematiques/Delete.cshtml

@@ -11,7 +11,7 @@
 
 <h3>Voulez-vous vraiment supprimer cet élément?</h3>
 <div>
-    <h4>Type collège</h4>
+    <h4>Thématiques</h4>
     <hr />
     <dl class="dl-horizontal">
         <dt>

+ 16 - 0
CD67.FicheCollege.MVC/Views/ActionEduThematiques/Edit.cshtml

@@ -29,6 +29,22 @@
             </div>
         </div>
 
+        <div class="form-group">
+            @Html.LabelFor(model => thematique.Neutralise, htmlAttributes: new { @class = "control-label col-md-2" })
+            <div class="col-md-10">
+                @Html.EditorFor(model => thematique.Neutralise, new { htmlAttributes = new { @class = "form-control" } })
+                @Html.ValidationMessageFor(model => thematique.Neutralise, "", new { @class = "text-danger" })
+            </div>
+        </div>
+
+        <div class="form-group">
+            @Html.LabelFor(model => thematique.ActionEduAxeId, htmlAttributes: new { @class = "control-label col-md-2" })
+            <div class="col-md-10">
+                @Html.DropDownListFor(model => thematique.ActionEduAxeId, Model.Sel_Axes, htmlAttributes: new { @class = "form-control" })
+                @Html.ValidationMessageFor(model => thematique.ActionEduAxeId, "", new { @class = "text-danger" })
+            </div>
+        </div>
+
         <div class="form-group">
             <div class="col-md-offset-2 col-md-10">
                 <input type="submit" value="Enregistrer" class="btn btn-default" />

+ 15 - 2
CD67.FicheCollege.MVC/Views/ActionEduThematiques/Index.cshtml

@@ -20,8 +20,15 @@
 <table class="table">
     <tr>
         <th>
-            @*@Html.DisplayNameFor(model => model.Obj.Libelle)*@
+            @Html.DisplayNameFor(model => model.Obj.First().Nom)
         </th>
+        <th>
+            @Html.DisplayNameFor(model => model.Obj.First().ActionEduAxeId)
+        </th>
+        <th>
+            @Html.DisplayNameFor(model => model.Obj.First().Neutralise)
+        </th>
+
         <th></th>
     </tr>
 
@@ -31,7 +38,13 @@
             <td>
                 @Html.DisplayFor(modelItem => item.Nom)
             </td>
-        
+            <td>
+                @Html.DisplayFor(modelItem => item.ActionEduAxe.Nom)
+            </td>
+            <td>
+                @Html.DisplayFor(modelItem => item.Neutralise)
+            </td>
+
             <td>
                 @if (row != 1)
                     {