Selaa lähdekoodia

ViewModels: utilisation du typage variable <T>

olivier.massot 7 vuotta sitten
vanhempi
commit
a77b803e73

+ 2 - 10
CD67.FicheCollege.MVC/Models/ActionClasViewModel.cs

@@ -3,21 +3,13 @@ using System.Collections.Generic;
 
 namespace CD67.FicheCollege.MVC.Models
 {
-    public class ActionClasViewModel : BaseViewModel
+    public class ActionClasViewModel : BaseViewModel<ActionCLAS>
     {
 
-        public ActionClasViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        public ActionClasViewModel(ActionCLAS 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

+ 4 - 20
CD67.FicheCollege.MVC/Models/AnneeViewModel.cs

@@ -3,20 +3,12 @@ using System.Collections.Generic;
 
 namespace CD67.FicheCollege.MVC.Models
 {
-    public class AnneeViewModel : BaseViewModel
+    public class AnneeViewModel : BaseViewModel<Annee>
     {
-        public AnneeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        public AnneeViewModel(Annee 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
@@ -34,20 +26,12 @@ namespace CD67.FicheCollege.MVC.Models
         }
     }
 
-    public class AnneeIndexViewModel : BaseViewModel
+    public class AnneeIndexViewModel : BaseViewModel<IEnumerable<Annee>>
     {
-        public AnneeIndexViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        public AnneeIndexViewModel(IEnumerable<Annee> 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

+ 4 - 4
CD67.FicheCollege.MVC/Models/BaseViewModel.cs

@@ -16,9 +16,9 @@ namespace CD67.FicheCollege.MVC.Models
     }
 
     // Wrapper du modele qui permet d'emmener des informations supplementaires avec celui-ci.
-    public abstract class BaseViewModel
+    public abstract class BaseViewModel<T>
     {
-        internal object _Obj;
+        internal T Obj;
 
         public abstract int Id { get; }
         public abstract string Annee_Lib { get; }
@@ -36,11 +36,11 @@ namespace CD67.FicheCollege.MVC.Models
 
         // ***************************
         // Constructeur de base
-        public BaseViewModel(object model,
+        public BaseViewModel(T model,
             ModeAcces acces = ModeAcces.Lecture,
             Dictionary<string, object> bag = null)
         {
-            _Obj = model;
+            Obj = model;
             Acces = acces;
             if (bag != null)
                 Bag = bag;

+ 2 - 10
CD67.FicheCollege.MVC/Models/CollegeViewModel.cs

@@ -6,12 +6,12 @@ using System.Web.Mvc;
 
 namespace CD67.FicheCollege.MVC.Models
 {
-    public class CollegeViewModel : BaseViewModel
+    public class CollegeViewModel : BaseViewModel<College>
     {
         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)
+        public CollegeViewModel(College model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
         {
             if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
             {
@@ -22,14 +22,6 @@ namespace CD67.FicheCollege.MVC.Models
             }
         }
 
-        public College Obj
-        {
-            get
-            {
-                return (_Obj as College);
-            }
-        }
-
         public override int Id
         {
             get

+ 2 - 10
CD67.FicheCollege.MVC/Models/IdentiteViewModel.cs

@@ -3,11 +3,11 @@ using System.Collections.Generic;
 
 namespace CD67.FicheCollege.MVC.Models
 {
-    public class IdentiteViewModel : BaseViewModel
+    public class IdentiteViewModel : BaseViewModel<Identite>
     {
         public List<ContactViewModel> Contacts;
 
-        public IdentiteViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        public IdentiteViewModel(Identite model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
         {
             Contacts = new List<ContactViewModel>();
             if (Obj.Principal_SID != null)
@@ -20,14 +20,6 @@ namespace CD67.FicheCollege.MVC.Models
                 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