浏览代码

FIX Integration des viewmodels au TypeCollege

olivier.massot 7 年之前
父节点
当前提交
1f5f21b9c4

+ 16 - 8
CD67.FicheCollege.MVC/Controllers/TypeCollegeController.cs

@@ -8,6 +8,7 @@ using System.Web;
 using System.Web.Mvc;
 using CD67.FicheCollege.Entity;
 using CD67.FicheCollege.Factory;
+using CD67.FicheCollege.MVC.Models;
 
 namespace CD67.FicheCollege.MVC.Controllers
 {
@@ -18,8 +19,9 @@ namespace CD67.FicheCollege.MVC.Controllers
         // GET: TypeCollege
         public ActionResult Index()
         {
-            TypeCollegeFactory typeCollegeFactory = new TypeCollegeFactory(db);
-            return View(typeCollegeFactory.getAll());
+            TypeCollegeFactory fact = new TypeCollegeFactory(db);
+            TypeCollegeIndexViewModel model = new TypeCollegeIndexViewModel(fact.getAll());
+            return View(model);
         }
 
         // GET: TypeCollege/Details/5
@@ -35,14 +37,16 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return HttpNotFound();
             }
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // GET: TypeCollege/Create
         public ActionResult Create()
         {
             Entity.TypeCollege typeCollege = new Entity.TypeCollege();
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // POST: TypeCollege/Create
@@ -59,7 +63,8 @@ namespace CD67.FicheCollege.MVC.Controllers
                 return RedirectToAction("Index");
             }
 
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // GET: TypeCollege/Edit/5
@@ -75,7 +80,8 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return HttpNotFound();
             }
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // POST: TypeCollege/Edit/5
@@ -91,7 +97,8 @@ namespace CD67.FicheCollege.MVC.Controllers
                 typeCollegeFactory.update(ref typeCollege);
                 return RedirectToAction("Index");
             }
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // GET: TypeCollege/Delete/5
@@ -107,7 +114,8 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return HttpNotFound();
             }
-            return View(typeCollege);
+            TypeCollegeViewModel model = new TypeCollegeViewModel(typeCollege);
+            return View(model);
         }
 
         // POST: TypeCollege/Delete/5

+ 27 - 0
CD67.FicheCollege.MVC/Models/TypeCollegeViewModel.cs

@@ -0,0 +1,27 @@
+using CD67.FicheCollege.Entity;
+using CD67.FicheCollege.Factory;
+using CD67.FicheCollege.MVC.Internal;
+using System.Collections.Generic;
+using System.Web.Mvc;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+    public class TypeCollegeViewModel : BaseViewModel<TypeCollege>
+    {
+        public TypeCollegeViewModel(TypeCollege model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public override string Annee_Lib { get { return ""; } }
+    }
+
+    public class TypeCollegeIndexViewModel : BaseViewModel<IEnumerable<TypeCollege>>
+    {
+        public TypeCollegeIndexViewModel(IEnumerable<TypeCollege> model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public override string Annee_Lib { get { return ""; } }
+
+    }
+}

+ 8 - 8
CD67.FicheCollege.MVC/Views/TypeCollege/Create.cshtml

@@ -1,12 +1,12 @@
-@model CD67.FicheCollege.Entity.TypeCollege
+@using CD67.FicheCollege.MVC.Models
+@model TypeCollegeViewModel
 
 @{
     ViewBag.Title = "Création";
     Layout = "~/Views/Shared/_Layout.cshtml";
+    TypeCollege typeCollege = Model.Obj;
 }
 
-<h2>Création</h2>
-
 
 @using (Html.BeginForm()) 
 {
@@ -16,14 +16,14 @@
         <h4>Type collège</h4>
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
-        @Html.HiddenFor(model => model.Id)
-        @Html.HiddenFor(model => model.Ordre)
+        @Html.HiddenFor(model => typeCollege.Id)
+        @Html.HiddenFor(model => typeCollege.Ordre)
 
         <div class="form-group">
-            @Html.LabelFor(model => model.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
+            @Html.LabelFor(model => typeCollege.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
             <div class="col-md-10">
-                @Html.EditorFor(model => model.Libelle, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.Libelle, "", new { @class = "text-danger" })
+                @Html.EditorFor(model => typeCollege.Libelle, new { htmlAttributes = new { @class = "form-control" } })
+                @Html.ValidationMessageFor(model => typeCollege.Libelle, "", new { @class = "text-danger" })
             </div>
         </div>
 

+ 5 - 3
CD67.FicheCollege.MVC/Views/TypeCollege/Delete.cshtml

@@ -1,8 +1,10 @@
-@model CD67.FicheCollege.Entity.TypeCollege
+@using CD67.FicheCollege.MVC.Models
+@model TypeCollegeViewModel
 
 @{
     ViewBag.Title = "Suppression";
     Layout = "~/Views/Shared/_Layout.cshtml";
+    TypeCollege typeCollege = Model.Obj;
 }
 
 <h2>Suppression</h2>
@@ -13,11 +15,11 @@
     <hr />
     <dl class="dl-horizontal">
         <dt>
-            @Html.DisplayNameFor(model => model.Libelle)
+            @Html.DisplayNameFor(model => typeCollege.Libelle)
         </dt>
 
         <dd>
-            @Html.DisplayFor(model => model.Libelle)
+            @Html.DisplayFor(model => typeCollege.Libelle)
         </dd>
 
     </dl>

+ 8 - 6
CD67.FicheCollege.MVC/Views/TypeCollege/Edit.cshtml

@@ -1,8 +1,10 @@
-@model CD67.FicheCollege.Entity.TypeCollege
+@using CD67.FicheCollege.MVC.Models
+@model TypeCollegeViewModel
 
 @{
     ViewBag.Title = "Modification";
     Layout = "~/Views/Shared/_Layout.cshtml";
+    TypeCollege typeCollege = Model.Obj;
 }
 
 <h2>Modification</h2>
@@ -16,14 +18,14 @@
         <h4>Type collège</h4>
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
-        @Html.HiddenFor(model => model.Id)
-        @Html.HiddenFor(model => model.Ordre)
+        @Html.HiddenFor(model => typeCollege.Id)
+        @Html.HiddenFor(model => typeCollege.Ordre)
 
         <div class="form-group">
-            @Html.LabelFor(model => model.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
+            @Html.LabelFor(model => typeCollege.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
             <div class="col-md-10">
-                @Html.EditorFor(model => model.Libelle, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.Libelle, "", new { @class = "text-danger" })
+                @Html.EditorFor(model => typeCollege.Libelle, new { htmlAttributes = new { @class = "form-control" } })
+                @Html.ValidationMessageFor(model => typeCollege.Libelle, "", new { @class = "text-danger" })
             </div>
         </div>
 

+ 38 - 37
CD67.FicheCollege.MVC/Views/TypeCollege/Index.cshtml

@@ -1,9 +1,10 @@
-@model IEnumerable<CD67.FicheCollege.Entity.TypeCollege>
+@using CD67.FicheCollege.MVC.Models
+@model TypeCollegeIndexViewModel
 
 @{
     ViewBag.Title = "Liste";
     Layout = "~/Views/Shared/_Layout.cshtml";
-    int maxOrdre = Model.Count() == 0 ? 0 : Model.Max(i => i.Ordre);
+    int maxOrdre = Model.Obj.Count() == 0 ? 0 : Model.Obj.Max(i => i.Ordre);
     int row = 1;
 }
 
@@ -19,48 +20,48 @@
 <table class="table">
     <tr>
         <th>
-            @Html.DisplayNameFor(model => model.Libelle)
+            @*@Html.DisplayNameFor(model => model.Obj.Libelle)*@
         </th>
         <th></th>
     </tr>
 
-@foreach (var item in Model)
-{
-    <tr>
-        <td>
-            @Html.DisplayFor(modelItem => item.Libelle)
-        </td>
+    @foreach (var item in Model.Obj)
+    {
+        <tr>
+            <td>
+                @Html.DisplayFor(modelItem => item.Libelle)
+            </td>
         
-        <td>
-            @if (row != 1)
+            <td>
+                @if (row != 1)
+                    {
+                    <a href="@Url.Action("Up", new { id = item.Id })">
+                        <span class="glyphicon glyphicon-circle-arrow-up fa-2x color1" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
+                    </a>
+                }
+                else
                 {
-                <a href="@Url.Action("Up", new { id = item.Id })">
-                    <span class="glyphicon glyphicon-circle-arrow-up fa-2x color1" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
-                </a>
-            }
-            else
-            {
-                <span class="glyphicon glyphicon-circle-arrow-up fa-2x color2" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
-            }
-            @if (item.Ordre != maxOrdre)
+                    <span class="glyphicon glyphicon-circle-arrow-up fa-2x color2" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
+                }
+                @if (item.Ordre != maxOrdre)
+                    {
+                    <a href="@Url.Action("Down", new { id = item.Id })">
+                        <span class="glyphicon glyphicon-circle-arrow-down fa-2x color1" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
+                    </a>
+                }
+                else
                 {
-                <a href="@Url.Action("Down", new { id = item.Id })">
-                    <span class="glyphicon glyphicon-circle-arrow-down fa-2x color1" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
+                    <span class="glyphicon glyphicon-circle-arrow-down fa-2x color2" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
+                }
+                <a href="@Url.Action("Edit", new { id = item.Id })">
+                    <span class="glyphicon glyphicon-edit fa-2x color1" title="Modifier" style="vertical-align: middle" aria-hidden="true"></span>
                 </a>
-            }
-            else
-            {
-                <span class="glyphicon glyphicon-circle-arrow-down fa-2x color2" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
-            }
-            <a href="@Url.Action("Edit", new { id = item.Id })">
-                <span class="glyphicon glyphicon-edit fa-2x color1" title="Modifier" style="vertical-align: middle" aria-hidden="true"></span>
-            </a>
-            <a href="@Url.Action("Delete", new { id = item.Id })">
-                <span class="glyphicon glyphicon-remove-sign fa-2x color1" title="Supprimer" style="vertical-align: middle" aria-hidden="true"></span>
-            </a>
-        </td>
-    </tr>
-    row += 1;
-}
+                <a href="@Url.Action("Delete", new { id = item.Id })">
+                    <span class="glyphicon glyphicon-remove-sign fa-2x color1" title="Supprimer" style="vertical-align: middle" aria-hidden="true"></span>
+                </a>
+            </td>
+        </tr>
+        row += 1;
+    }
 
 </table>