TopModel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 string Annee_Lib { get; }
  25. // (Facultatif) Mode d'accès à la page
  26. // Defaut: Lecture
  27. public ModeAcces Acces { get; set; }
  28. // (Facultatif) Permet d'emporter d'éventuelles données complémentaires
  29. // comme les listes qui serviront entre autre à peupler les listes déroulantes.
  30. public Dictionary<string, object> Bag { get; set; } = new Dictionary<string, object>();
  31. // Utilisateur courant
  32. public UtilisateurConnecte User = CD67.FicheCollege.MVC.Internal.UtilisateurConnecteFactory.getUtilisateurConnecte();
  33. // ***************************
  34. // Constructeur de base
  35. public TopModel(object model,
  36. ModeAcces acces = ModeAcces.Lecture,
  37. Dictionary<string, object> bag = null)
  38. {
  39. _Obj = model;
  40. Acces = acces;
  41. if (bag != null)
  42. Bag = bag;
  43. }
  44. }
  45. public class AnneeViewModel : TopModel
  46. {
  47. public AnneeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  48. {
  49. }
  50. public Annee Obj
  51. {
  52. get
  53. {
  54. return (_Obj as Annee);
  55. }
  56. }
  57. public override string Annee_Lib
  58. {
  59. get
  60. {
  61. return Obj.Libelle;
  62. }
  63. }
  64. }
  65. public class CollegeViewModel : TopModel
  66. {
  67. public SelectList Sel_TypesCollege;
  68. public SelectList Sel_CodesPostaux;
  69. public CollegeViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  70. {
  71. if (acces == ModeAcces.Creation | acces == ModeAcces.Modification)
  72. {
  73. Entities db = new Entities();
  74. TypeCollegeFactory fact = new TypeCollegeFactory(db);
  75. Sel_TypesCollege = new SelectList(fact.getAll(), "Id", "Libelle", Obj.TypeCollege_Id);
  76. Sel_CodesPostaux = new SelectList(Referentiel.GetCodesPostaux(Obj.Commune_Insee), Obj.Code_Postal);
  77. }
  78. }
  79. public College Obj {
  80. get {
  81. return (_Obj as College);
  82. }
  83. }
  84. public override string Annee_Lib
  85. {
  86. get {
  87. return Obj.Annee.Libelle;
  88. }
  89. }
  90. }
  91. public class IdentiteViewModel : TopModel
  92. {
  93. public List<ContactViewModel> Contacts;
  94. public IdentiteViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  95. {
  96. Contacts = new List<ContactViewModel>();
  97. if (Obj.Principal_SID != null)
  98. 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));
  99. if (Obj.Adjoint_SID != null)
  100. 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));
  101. if (Obj.Gestionnaire_SID != null)
  102. 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));
  103. if (Obj.Gestionnaire2_SID != null)
  104. 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));
  105. }
  106. public Identite Obj
  107. {
  108. get
  109. {
  110. return (_Obj as Identite);
  111. }
  112. }
  113. public override string Annee_Lib
  114. {
  115. get
  116. {
  117. return Obj.College.Annee.Libelle;
  118. }
  119. }
  120. }
  121. }