Browse Source

NEW Gestion des accès - Création d'une page d'administration des groupes

olivier.massot 7 years ago
parent
commit
20748f1b9c

+ 4 - 0
CD67.FicheCollege.MVC/CD67.FicheCollege.MVC.csproj

@@ -182,6 +182,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="App_Start\BundleConfig.cs" />
+    <Compile Include="Controllers\GroupesController.cs" />
     <Compile Include="Controllers\RestaurationFormulairesController.cs" />
     <Compile Include="Controllers\RestaurationParametresController.cs" />
     <Compile Include="Controllers\RestaurationTypesRepasController.cs" />
@@ -206,6 +207,7 @@
     <Compile Include="Internal\Navigation.cs" />
     <Compile Include="Internal\UtilisateurConnecteFactory.cs" />
     <Compile Include="Models\ActionEduActeurViewModel.cs" />
+    <Compile Include="Models\GroupeViewModel.cs" />
     <Compile Include="Models\ActionEduMissionViewModel.cs" />
     <Compile Include="Models\ActionEduCollegeViewModel.cs" />
     <Compile Include="Models\ActionEduAxeViewModel.cs" />
@@ -504,6 +506,8 @@
     <Content Include="Views\RestaurationFormulaires\Edit.cshtml" />
     <Content Include="Views\RestaurationFormulaires\Details.cshtml" />
     <Content Include="Views\Shared\DisplayTemplates\RestaurationStatut.cshtml" />
+    <Content Include="Views\Groupes\Edit.cshtml" />
+    <Content Include="Views\Groupes\Index.cshtml" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="App_Data\" />

+ 120 - 0
CD67.FicheCollege.MVC/Controllers/GroupesController.cs

@@ -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);
+        }
+    }
+}

+ 29 - 0
CD67.FicheCollege.MVC/Models/GroupeViewModel.cs

@@ -0,0 +1,29 @@
+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 GroupeViewModel : BaseViewModel<Groupe>
+    {
+        public GroupeViewModel(Groupe model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public override int Annee_Id { get { return 0; } }
+        public override string Annee_Lib { get { return ""; } }
+    }
+
+    public class GroupeIndexViewModel : BaseViewModel<IEnumerable<Groupe>>
+    {
+        public GroupeIndexViewModel(IEnumerable<Groupe> model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public override int Annee_Id { get { return 0; } }
+        public override string Annee_Lib { get { return ""; } }
+
+    }
+}

+ 27 - 0
CD67.FicheCollege.MVC/Views/Groupes/Index.cshtml

@@ -0,0 +1,27 @@
+@using CD67.FicheCollege.MVC.Models
+@model GroupeIndexViewModel
+
+@{
+    ViewBag.Title = "Administration - Utilisateurs";
+    Layout = "~/Views/Shared/_AdminLayout.cshtml";
+}
+
+<h2>Groupes d'utilisateurs</h2>
+
+<table class="table">
+    <tr>
+        <th>
+            @Html.DisplayNameFor(model => model.Obj.First().Nom)
+        </th>
+        <th>
+            @Html.DisplayNameFor(model => model.Obj.First().Description)
+        </th>
+    </tr>
+    @foreach (var item in Model.Obj.OrderBy(i => i.Nom))
+    {
+        <tr>
+            <td>@Html.DisplayFor(model => item.Nom)</td>
+            <td>@Html.DisplayFor(model => item.Description)</td>
+        </tr>
+    }
+</table>