Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IFactoryFiche
- {
- }
- public interface IFactoryForType
- {
- ContactInfoCommands GetContactInformation();
- void InitFiche(Fiche fiche);
- }
- public class FactoryFiche : IFactoryFiche
- {
- public void CreateFiche(IFactoryForType factoryForType)
- {
- var contact = factoryForType.GetContactInformation();
- Fiche fiche = new Fiche()
- {
- nom = contact.Nom,
- prenom = contact.Prenom,
- Adresse1 = contact.Adresse1,
- Adresse2 = contact.Adresse2,
- ville = contact.Ville,
- codePostal = contact.CodePostal,
- email = contact.Email,
- };
- factoryForType.InitFiche(fiche);
- }
- }
- public class FactoryFicheGav : IFactoryForType
- {
- public EnvoiGAVCommands EnvoieGAV { get; set; }
- public FactoryFicheGav(EnvoiGAVCommands envoieGAV)
- {
- EnvoieGAV = envoieGAV;
- }
- public ContactInfoCommands GetContactInformation()
- {
- return EnvoieGAV.ContactInfoCommands;
- }
- public void InitFiche(Fiche fiche)
- {
- }
- }
- public interface IFactoryFiche<COMMAND>
- {
- void CreateFiche(IFactoryForType<COMMAND> factoryForType, COMMAND command, string origine);
- }
- public class FactoryFiche<COMMAND> : IFactoryFiche<COMMAND>
- {
- [Dependency]
- public IFicheRepository FicheRepository { get; set; }
- public void CreateFiche(IFactoryForType<COMMAND> factoryForType, COMMAND command, string origine)
- {
- var contact = factoryForType.GetContactInformation(command);
- var composition = factoryForType.GetCompositionInformation(command);
- if (string.IsNullOrEmpty(contact.Email))
- {
- throw new ReceptionException("L'email est obligatoire");
- }
- Fiche fiche = new Fiche()
- {
- nom = contact.Nom,
- prenom = contact.Prenom,
- Adresse1 = contact.Adresse1,
- Adresse2 = contact.Adresse2,
- ville = contact.Ville,
- codePostal = contact.CodePostal,
- email = contact.Email,
- Type = (int)factoryForType.GetType()
- };
- factoryForType.InitFiche(fiche, command);
- FicheRepository.Add(fiche);
- FicheRepository.Save();
- }
- }
- public interface IFactoryForType<COMMAND>
- {
- ContactInfoCommands GetContactInformation(COMMAND cmd);
- CompositionCommands GetCompositionInformation(COMMAND command);
- void InitFiche(Fiche fiche, COMMAND command);
- Fiche.TypeFiche GetType();
- }
- public class FactoryFicheGav : IFactoryForType<EnvoiGAVCommands>
- {
- public ContactInfoCommands GetContactInformation(EnvoiGAVCommands command)
- {
- return command.ContactInfoCommands;
- }
- public void InitFiche(Fiche fiche, EnvoiGAVCommands command)
- {
- fiche.Complement = command.Commentaire;
- }
- public CompositionCommands GetCompositionInformation(EnvoiGAVCommands command)
- {
- return command.CompositionCommands;
- }
- public Fiche.TypeFiche GetType()
- {
- return Fiche.TypeFiche.GAV;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement