浏览代码

Refactorise les ViewModels

olivier.massot 7 年之前
父节点
当前提交
8441e84b49

+ 5 - 1
CD67.FicheCollege.MVC/Controllers/HomeController.cs

@@ -1,4 +1,5 @@
 using CD67.FicheCollege.Entity;
+using CD67.FicheCollege.Factory;
 using System;
 using System.Linq;
 using System.Net;
@@ -8,10 +9,13 @@ namespace CD67.FicheCollege.MVC.Controllers
 {
     public class HomeController : Controller
     {
+        private Entities db = new Entities();
+
         // GET: Home
         public ActionResult Index()
         {
-            return RedirectToAction("Details", "Annees", new { id = Annee.get_current_year_id() });
+            AnneeFactory fact = new AnneeFactory(db);
+            return RedirectToAction("Details", "Annees", new { id = fact.get_current_year_id() });
         }
     }
 }

+ 37 - 0
CD67.FicheCollege.MVC/Models/ActionClasViewModel.cs

@@ -0,0 +1,37 @@
+using CD67.FicheCollege.Entity;
+using System.Collections.Generic;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+    public class ActionClasViewModel : BaseViewModel
+    {
+
+        public ActionClasViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public ActionCLAS Obj
+        {
+            get
+            {
+                return (_Obj as ActionCLAS);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return Obj.College_Id;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.College.Annee.Libelle;
+            }
+        }
+    }
+}

+ 67 - 0
CD67.FicheCollege.MVC/Models/AnneeViewModel.cs

@@ -0,0 +1,67 @@
+using CD67.FicheCollege.Entity;
+using System.Collections.Generic;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+    public class AnneeViewModel : BaseViewModel
+    {
+        public AnneeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public Annee Obj
+        {
+            get
+            {
+                return (_Obj as Annee);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return Obj.Id;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.Libelle;
+            }
+        }
+    }
+
+    public class AnneeIndexViewModel : BaseViewModel
+    {
+        public AnneeIndexViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public IEnumerable<Annee> Obj
+        {
+            get
+            {
+                return (_Obj as IEnumerable<Annee>);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return 0;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return "";
+            }
+        }
+    }
+}

+ 50 - 0
CD67.FicheCollege.MVC/Models/BaseViewModel.cs

@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+    public enum ModeAcces
+    {
+        [Display(Prompt = "Ajouter")]
+        Creation,
+        [Display(Prompt = "Lire")]
+        Lecture,
+        [Display(Prompt = "Modifier")]
+        Modification,
+        [Display(Prompt = "Supprimer")]
+        Suppression
+    }
+
+    // Wrapper du modele qui permet d'emmener des informations supplementaires avec celui-ci.
+    public abstract class BaseViewModel
+    {
+        internal object _Obj;
+
+        public abstract int Id { get; }
+        public abstract string Annee_Lib { get; }
+
+        // (Facultatif) Mode d'accès à la page
+        // Defaut: Lecture
+        public ModeAcces Acces { get; set; }
+
+        // (Facultatif) Permet d'emporter d'éventuelles données complémentaires
+        // comme les listes qui serviront entre autre à peupler les listes déroulantes.
+        public Dictionary<string, object> Bag { get; set; } = new Dictionary<string, object>();
+
+        // Utilisateur courant
+        public UtilisateurConnecte User = CD67.FicheCollege.MVC.Internal.UtilisateurConnecteFactory.getUtilisateurConnecte();
+
+        // ***************************
+        // Constructeur de base
+        public BaseViewModel(object model,
+            ModeAcces acces = ModeAcces.Lecture,
+            Dictionary<string, object> bag = null)
+        {
+            _Obj = model;
+            Acces = acces;
+            if (bag != null)
+                Bag = bag;
+        }
+
+    }
+}

+ 49 - 0
CD67.FicheCollege.MVC/Models/CollegeViewModel.cs

@@ -0,0 +1,49 @@
+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 CollegeViewModel : BaseViewModel
+    {
+        public SelectList Sel_TypesCollege;
+        public SelectList Sel_CodesPostaux;
+
+        public CollegeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+            if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
+            {
+                Entities db = new Entities();
+                TypeCollegeFactory fact = new TypeCollegeFactory(db);
+                Sel_TypesCollege = new SelectList(fact.getAll(), "Id", "Libelle", Obj.TypeCollege_Id);
+                Sel_CodesPostaux = new SelectList(Referentiel.GetCodesPostaux(Obj.Commune_Insee), Obj.Code_Postal);
+            }
+        }
+
+        public College Obj
+        {
+            get
+            {
+                return (_Obj as College);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return Obj.Id;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.Annee.Libelle;
+            }
+        }
+    }
+}

+ 47 - 0
CD67.FicheCollege.MVC/Models/IdentiteViewModel.cs

@@ -0,0 +1,47 @@
+using CD67.FicheCollege.Entity;
+using System.Collections.Generic;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+    public class IdentiteViewModel : BaseViewModel
+    {
+        public List<ContactViewModel> Contacts;
+
+        public IdentiteViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+            Contacts = new List<ContactViewModel>();
+            if (Obj.Principal_SID != null)
+                Contacts.Add(new ContactViewModel("Principal", Obj.Principal_SID, Obj.Principal_Login, Obj.Principal_Nom, Obj.Principal_Prenom, Obj.Principal_Email, Obj.Principal_Tel, Obj.Principal_Structure));
+            if (Obj.Adjoint_SID != null)
+                Contacts.Add(new ContactViewModel("Principal adjoint", Obj.Adjoint_SID, Obj.Adjoint_Login, Obj.Adjoint_Nom, Obj.Adjoint_Prenom, Obj.Adjoint_Email, Obj.Adjoint_Tel, Obj.Adjoint_Structure));
+            if (Obj.Gestionnaire_SID != null)
+                Contacts.Add(new ContactViewModel("Gestionnaire", Obj.Gestionnaire_SID, Obj.Gestionnaire_Login, Obj.Gestionnaire_Nom, Obj.Gestionnaire_Prenom, Obj.Gestionnaire_Email, Obj.Gestionnaire_Tel, Obj.Gestionnaire_Structure));
+            if (Obj.Gestionnaire2_SID != null)
+                Contacts.Add(new ContactViewModel("Gestionnaire n°2", Obj.Gestionnaire2_SID, Obj.Gestionnaire2_Login, Obj.Gestionnaire2_Nom, Obj.Gestionnaire2_Prenom, Obj.Gestionnaire2_Email, Obj.Gestionnaire2_Tel, Obj.Gestionnaire2_Structure));
+        }
+
+        public Identite Obj
+        {
+            get
+            {
+                return (_Obj as Identite);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return Obj.College_Id;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.College.Annee.Libelle;
+            }
+        }
+    }
+}

+ 0 - 229
CD67.FicheCollege.MVC/Models/TopModel.cs

@@ -1,229 +0,0 @@
-using CD67.FicheCollege.Entity;
-using CD67.FicheCollege.Factory;
-using CD67.FicheCollege.MVC.Internal;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Web.Mvc;
-
-namespace CD67.FicheCollege.MVC.Models
-{
-    public enum ModeAcces
-    {
-        [Display(Prompt = "Ajouter")]
-        Creation,
-        [Display(Prompt = "Lire")]
-        Lecture,
-        [Display(Prompt = "Modifier")]
-        Modification,
-        [Display(Prompt = "Supprimer")]
-        Suppression
-    }
-
-    // Wrapper du modele qui permet d'emmener des informations supplementaires avec celui-ci.
-    public abstract class TopModel
-    {
-        internal object _Obj;
-
-        public abstract int Id { get; }
-        public abstract string Annee_Lib { get; }
-
-        // (Facultatif) Mode d'accès à la page
-        // Defaut: Lecture
-        public ModeAcces Acces { get; set; }
-
-        // (Facultatif) Permet d'emporter d'éventuelles données complémentaires
-        // comme les listes qui serviront entre autre à peupler les listes déroulantes.
-        public Dictionary<string, object> Bag { get; set; } = new Dictionary<string, object>();
-
-        // Utilisateur courant
-        public UtilisateurConnecte User = CD67.FicheCollege.MVC.Internal.UtilisateurConnecteFactory.getUtilisateurConnecte();
-
-        // ***************************
-        // Constructeur de base
-        public TopModel(object model,
-            ModeAcces acces = ModeAcces.Lecture,
-            Dictionary<string, object> bag = null)
-        {
-            _Obj = model;
-            Acces = acces;
-            if (bag != null)
-                Bag = bag;
-        }
-
-    }
-
-    public class AnneeViewModel : TopModel
-    {
-        public AnneeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
-        {
-        }
-
-        public Annee Obj
-        {
-            get
-            {
-                return (_Obj as Annee);
-            }
-        }
-
-        public override int Id
-        {
-            get
-            {
-                return Obj.Id;
-            }
-        }
-
-        public override string Annee_Lib
-        {
-            get
-            {
-                return Obj.Libelle;
-            }
-        }
-    }
-
-    public class AnneeIndexViewModel : TopModel
-    {
-        public AnneeIndexViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
-        {
-        }
-
-        public IEnumerable<Annee> Obj
-        {
-            get
-            {
-                return (_Obj as IEnumerable<Annee>);
-            }
-        }
-
-        public override int Id
-        {
-            get
-            {
-                return 0;
-            }
-        }
-
-        public override string Annee_Lib
-        {
-            get
-            {
-                return "";
-            }
-        }
-    }
-
-    public class CollegeViewModel : TopModel
-    {
-        public SelectList Sel_TypesCollege;
-        public SelectList Sel_CodesPostaux;
-
-        public CollegeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
-        {
-            if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
-            {
-                Entities db = new Entities();
-                TypeCollegeFactory fact = new TypeCollegeFactory(db);
-                Sel_TypesCollege = new SelectList(fact.getAll(), "Id", "Libelle", Obj.TypeCollege_Id);
-                Sel_CodesPostaux = new SelectList(Referentiel.GetCodesPostaux(Obj.Commune_Insee), Obj.Code_Postal);
-            }
-        }
-
-        public College Obj {
-            get {
-                return (_Obj as College);
-            }
-        }
-
-        public override int Id
-        {
-            get
-            {
-                return Obj.Id;
-            }
-        }
-
-        public override string Annee_Lib
-        {
-            get {
-                return Obj.Annee.Libelle;
-            }
-        }
-    }
-
-    public class IdentiteViewModel : TopModel
-    {
-        public List<ContactViewModel> Contacts;
-
-        public IdentiteViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
-        {
-            Contacts = new List<ContactViewModel>();
-            if (Obj.Principal_SID != null)
-                Contacts.Add(new ContactViewModel("Principal", Obj.Principal_SID, Obj.Principal_Login, Obj.Principal_Nom, Obj.Principal_Prenom, Obj.Principal_Email, Obj.Principal_Tel, Obj.Principal_Structure));
-            if (Obj.Adjoint_SID != null)
-                Contacts.Add(new ContactViewModel("Principal adjoint", Obj.Adjoint_SID, Obj.Adjoint_Login, Obj.Adjoint_Nom, Obj.Adjoint_Prenom, Obj.Adjoint_Email, Obj.Adjoint_Tel, Obj.Adjoint_Structure));
-            if (Obj.Gestionnaire_SID != null)
-                Contacts.Add(new ContactViewModel("Gestionnaire", Obj.Gestionnaire_SID, Obj.Gestionnaire_Login, Obj.Gestionnaire_Nom, Obj.Gestionnaire_Prenom, Obj.Gestionnaire_Email, Obj.Gestionnaire_Tel, Obj.Gestionnaire_Structure));
-            if (Obj.Gestionnaire2_SID != null)
-                Contacts.Add(new ContactViewModel("Gestionnaire n°2", Obj.Gestionnaire2_SID, Obj.Gestionnaire2_Login, Obj.Gestionnaire2_Nom, Obj.Gestionnaire2_Prenom, Obj.Gestionnaire2_Email, Obj.Gestionnaire2_Tel, Obj.Gestionnaire2_Structure));
-        }
-
-        public Identite Obj
-        {
-            get
-            {
-                return (_Obj as Identite);
-            }
-        }
-
-        public override int Id
-        {
-            get
-            {
-                return Obj.College_Id;
-            }
-        }
-
-        public override string Annee_Lib
-        {
-            get
-            {
-                return Obj.College.Annee.Libelle;
-            }
-        }
-    }
-
-    public class ActionClasViewModel : TopModel
-    {
-
-        public ActionClasViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
-        {
-        }
-
-        public ActionCLAS Obj
-        {
-            get
-            {
-                return (_Obj as ActionCLAS);
-            }
-        }
-
-        public override int Id
-        {
-            get
-            {
-                return Obj.College_Id;
-            }
-        }
-
-        public override string Annee_Lib
-        {
-            get
-            {
-                return Obj.College.Annee.Libelle;
-            }
-        }
-    }
-
-}