Quellcode durchsuchen

Integration ViewModels à TopModel

olivier.massot vor 7 Jahren
Ursprung
Commit
e2e8113799

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

@@ -174,9 +174,6 @@
     <Compile Include="Internal\Navigation.cs" />
     <Compile Include="Internal\UtilisateurConnecteFactory.cs" />
     <Compile Include="Models\TopModel.cs" />
-    <Compile Include="Models\CollegeViewModel_old.cs" />
-    <Compile Include="Models\ContactViewModel.cs" />
-    <Compile Include="Models\ModeAcces.cs" />
     <Compile Include="Models\UtilisateurConnecte.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\Settings.Designer.cs">

+ 0 - 19
CD67.FicheCollege.MVC/Models/CollegeViewModel_old.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
-
-namespace CD67.FicheCollege.MVC.Models
-{
-    public class CollegeViewModel_old
-    {
-        public int College_Id { get; set; }
-        public string College_Libelle { get; set; }
-        public int Annee_Id { get; set; }
-        public string Annee_Lib { get; set; }
-        public object Contenu { get; set; }
-        public ModeAcces Acces { get; set; }
-        public Dictionary<String, SelectList> Listes { get; set; }
-    }
-}

+ 0 - 31
CD67.FicheCollege.MVC/Models/ContactViewModel.cs

@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace CD67.FicheCollege.MVC.Models
-{
-    public class ContactViewModel
-    {
-        public string Role { get; set; }
-        public string SID { get; set; }
-        public string Login { get; set; }
-        public string Nom { get; set; }
-        public string Prenom { get; set; }
-        public string Email { get; set; }
-        public string Tel { get; set; }
-        public string Structure { get; set; }
-
-        public ContactViewModel(string Role, string SID, string Login, string Nom, string Prenom, string Email, string Tel, string Structure)
-        {
-            this.Role = Role;
-            this.SID = SID;
-            this.Login = Login;
-            this.Nom = Nom;
-            this.Prenom = Prenom;
-            this.Email = Email;
-            this.Tel = Tel;
-            this.Structure = Structure;
-        }
-    }
-}

+ 0 - 20
CD67.FicheCollege.MVC/Models/ModeAcces.cs

@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Web;
-
-namespace CD67.FicheCollege.MVC.Models
-{
-    public enum ModeAcces
-    {
-        [Display(Prompt = "Ajouter")]
-        Creation,
-        [Display(Prompt = "Lire")]
-        Lecture,
-        [Display(Prompt = "Modifier")]
-        Modification,
-        [Display(Prompt = "Supprimer")]
-        Suppression
-    }
-}

+ 34 - 2
CD67.FicheCollege.MVC/Models/TopModel.cs

@@ -2,10 +2,23 @@
 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
     {
@@ -64,8 +77,6 @@ namespace CD67.FicheCollege.MVC.Models
 
     public class CollegeViewModel : TopModel
     {
-        private Entities db = new Entities();
-
         public SelectList Sel_TypesCollege;
         public SelectList Sel_CodesPostaux;
 
@@ -73,6 +84,7 @@ namespace CD67.FicheCollege.MVC.Models
         {
             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);
@@ -91,9 +103,29 @@ namespace CD67.FicheCollege.MVC.Models
                 return Obj.Annee.Libelle;
             }
         }
+    }
 
+    public class ContactViewModel : TopModel
+    {
+        public ContactViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
 
+        public Identite Obj
+        {
+            get
+            {
+                return (_Obj as Identite);
+            }
+        }
 
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.College.Annee.Libelle;
+            }
+        }
     }
 
 }