TopModel.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using CD67.FicheCollege.Entity;
  2. using CD67.FicheCollege.Factory;
  3. using CD67.FicheCollege.MVC.Internal;
  4. using System.Collections.Generic;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Web.Mvc;
  7. namespace CD67.FicheCollege.MVC.Models
  8. {
  9. public enum ModeAcces
  10. {
  11. [Display(Prompt = "Ajouter")]
  12. Creation,
  13. [Display(Prompt = "Lire")]
  14. Lecture,
  15. [Display(Prompt = "Modifier")]
  16. Modification,
  17. [Display(Prompt = "Supprimer")]
  18. Suppression
  19. }
  20. // Wrapper du modele qui permet d'emmener des informations supplementaires avec celui-ci.
  21. public abstract class TopModel
  22. {
  23. internal object _Obj;
  24. public abstract int Id { get; }
  25. public abstract string Annee_Lib { get; }
  26. // (Facultatif) Mode d'accès à la page
  27. // Defaut: Lecture
  28. public ModeAcces Acces { get; set; }
  29. // (Facultatif) Permet d'emporter d'éventuelles données complémentaires
  30. // comme les listes qui serviront entre autre à peupler les listes déroulantes.
  31. public Dictionary<string, object> Bag { get; set; } = new Dictionary<string, object>();
  32. // Utilisateur courant
  33. public UtilisateurConnecte User = CD67.FicheCollege.MVC.Internal.UtilisateurConnecteFactory.getUtilisateurConnecte();
  34. // ***************************
  35. // Constructeur de base
  36. public TopModel(object model,
  37. ModeAcces acces = ModeAcces.Lecture,
  38. Dictionary<string, object> bag = null)
  39. {
  40. _Obj = model;
  41. Acces = acces;
  42. if (bag != null)
  43. Bag = bag;
  44. }
  45. }
  46. public class AnneeViewModel : TopModel
  47. {
  48. public AnneeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  49. {
  50. }
  51. public Annee Obj
  52. {
  53. get
  54. {
  55. return (_Obj as Annee);
  56. }
  57. }
  58. public override int Id
  59. {
  60. get
  61. {
  62. return Obj.Id;
  63. }
  64. }
  65. public override string Annee_Lib
  66. {
  67. get
  68. {
  69. return Obj.Libelle;
  70. }
  71. }
  72. }
  73. public class AnneeIndexViewModel : TopModel
  74. {
  75. public AnneeIndexViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  76. {
  77. }
  78. public IEnumerable<Annee> Obj
  79. {
  80. get
  81. {
  82. return (_Obj as IEnumerable<Annee>);
  83. }
  84. }
  85. public override int Id
  86. {
  87. get
  88. {
  89. return 0;
  90. }
  91. }
  92. public override string Annee_Lib
  93. {
  94. get
  95. {
  96. return "";
  97. }
  98. }
  99. }
  100. public class CollegeViewModel : TopModel
  101. {
  102. public SelectList Sel_TypesCollege;
  103. public SelectList Sel_CodesPostaux;
  104. public CollegeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  105. {
  106. if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
  107. {
  108. Entities db = new Entities();
  109. TypeCollegeFactory fact = new TypeCollegeFactory(db);
  110. Sel_TypesCollege = new SelectList(fact.getAll(), "Id", "Libelle", Obj.TypeCollege_Id);
  111. Sel_CodesPostaux = new SelectList(Referentiel.GetCodesPostaux(Obj.Commune_Insee), Obj.Code_Postal);
  112. }
  113. }
  114. public College Obj {
  115. get {
  116. return (_Obj as College);
  117. }
  118. }
  119. public override int Id
  120. {
  121. get
  122. {
  123. return Obj.Id;
  124. }
  125. }
  126. public override string Annee_Lib
  127. {
  128. get {
  129. return Obj.Annee.Libelle;
  130. }
  131. }
  132. }
  133. public class IdentiteViewModel : TopModel
  134. {
  135. public List<ContactViewModel> Contacts;
  136. public IdentiteViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  137. {
  138. Contacts = new List<ContactViewModel>();
  139. if (Obj.Principal_SID != null)
  140. 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));
  141. if (Obj.Adjoint_SID != null)
  142. 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));
  143. if (Obj.Gestionnaire_SID != null)
  144. 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));
  145. if (Obj.Gestionnaire2_SID != null)
  146. 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));
  147. }
  148. public Identite Obj
  149. {
  150. get
  151. {
  152. return (_Obj as Identite);
  153. }
  154. }
  155. public override int Id
  156. {
  157. get
  158. {
  159. return Obj.College_Id;
  160. }
  161. }
  162. public override string Annee_Lib
  163. {
  164. get
  165. {
  166. return Obj.College.Annee.Libelle;
  167. }
  168. }
  169. }
  170. public class ActionClasViewModel : TopModel
  171. {
  172. public ActionClasViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  173. {
  174. }
  175. public ActionCLAS Obj
  176. {
  177. get
  178. {
  179. return (_Obj as ActionCLAS);
  180. }
  181. }
  182. public override int Id
  183. {
  184. get
  185. {
  186. return Obj.College_Id;
  187. }
  188. }
  189. public override string Annee_Lib
  190. {
  191. get
  192. {
  193. return Obj.College.Annee.Libelle;
  194. }
  195. }
  196. }
  197. }