TopModel.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 ContactViewModel : TopModel
  92. {
  93. public ContactViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
  94. {
  95. }
  96. public Identite Obj
  97. {
  98. get
  99. {
  100. return (_Obj as Identite);
  101. }
  102. }
  103. public override string Annee_Lib
  104. {
  105. get
  106. {
  107. return Obj.College.Annee.Libelle;
  108. }
  109. }
  110. }
  111. }