Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. public interface IFactoryFiche
  2. {
  3.  
  4. }
  5.  
  6. public interface IFactoryForType
  7. {
  8. ContactInfoCommands GetContactInformation();
  9.  
  10. void InitFiche(Fiche fiche);
  11. }
  12.  
  13. public class FactoryFiche : IFactoryFiche
  14. {
  15. public void CreateFiche(IFactoryForType factoryForType)
  16. {
  17. var contact = factoryForType.GetContactInformation();
  18. Fiche fiche = new Fiche()
  19. {
  20. nom = contact.Nom,
  21. prenom = contact.Prenom,
  22. Adresse1 = contact.Adresse1,
  23. Adresse2 = contact.Adresse2,
  24. ville = contact.Ville,
  25. codePostal = contact.CodePostal,
  26. email = contact.Email,
  27. };
  28.  
  29. factoryForType.InitFiche(fiche);
  30. }
  31. }
  32.  
  33. public class FactoryFicheGav : IFactoryForType
  34. {
  35. public EnvoiGAVCommands EnvoieGAV { get; set; }
  36.  
  37.  
  38. public FactoryFicheGav(EnvoiGAVCommands envoieGAV)
  39. {
  40. EnvoieGAV = envoieGAV;
  41. }
  42.  
  43. public ContactInfoCommands GetContactInformation()
  44. {
  45. return EnvoieGAV.ContactInfoCommands;
  46. }
  47.  
  48. public void InitFiche(Fiche fiche)
  49. {
  50.  
  51. }
  52. }
  53.  
  54. public interface IFactoryFiche<COMMAND>
  55. {
  56. void CreateFiche(IFactoryForType<COMMAND> factoryForType, COMMAND command, string origine);
  57. }
  58.  
  59. public class FactoryFiche<COMMAND> : IFactoryFiche<COMMAND>
  60. {
  61. [Dependency]
  62. public IFicheRepository FicheRepository { get; set; }
  63.  
  64. public void CreateFiche(IFactoryForType<COMMAND> factoryForType, COMMAND command, string origine)
  65. {
  66. var contact = factoryForType.GetContactInformation(command);
  67. var composition = factoryForType.GetCompositionInformation(command);
  68.  
  69. if (string.IsNullOrEmpty(contact.Email))
  70. {
  71. throw new ReceptionException("L'email est obligatoire");
  72. }
  73.  
  74. Fiche fiche = new Fiche()
  75. {
  76. nom = contact.Nom,
  77. prenom = contact.Prenom,
  78. Adresse1 = contact.Adresse1,
  79. Adresse2 = contact.Adresse2,
  80. ville = contact.Ville,
  81. codePostal = contact.CodePostal,
  82. email = contact.Email,
  83. Type = (int)factoryForType.GetType()
  84. };
  85.  
  86. factoryForType.InitFiche(fiche, command);
  87.  
  88. FicheRepository.Add(fiche);
  89. FicheRepository.Save();
  90. }
  91. }
  92.  
  93. public interface IFactoryForType<COMMAND>
  94. {
  95. ContactInfoCommands GetContactInformation(COMMAND cmd);
  96.  
  97. CompositionCommands GetCompositionInformation(COMMAND command);
  98.  
  99. void InitFiche(Fiche fiche, COMMAND command);
  100.  
  101. Fiche.TypeFiche GetType();
  102. }
  103.  
  104. public class FactoryFicheGav : IFactoryForType<EnvoiGAVCommands>
  105. {
  106. public ContactInfoCommands GetContactInformation(EnvoiGAVCommands command)
  107. {
  108. return command.ContactInfoCommands;
  109. }
  110.  
  111. public void InitFiche(Fiche fiche, EnvoiGAVCommands command)
  112. {
  113. fiche.Complement = command.Commentaire;
  114. }
  115.  
  116. public CompositionCommands GetCompositionInformation(EnvoiGAVCommands command)
  117. {
  118. return command.CompositionCommands;
  119. }
  120.  
  121. public Fiche.TypeFiche GetType()
  122. {
  123. return Fiche.TypeFiche.GAV;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement