Ejemplo n.º 1
0
 public PersonDomainModelImportService(
     PersonDomainService domainService,
     DataService dataService,
     IIntegerIdentityFactory <F1ChiefCommercialEntity> f1ChiefCommercialEntityFactory,
     IIntegerIdentityFactory <F1ChiefDesignerEntity> f1ChiefDesignerEntityFactory,
     IIntegerIdentityFactory <F1ChiefEngineerEntity> f1ChiefEngineerEntityFactory,
     IIntegerIdentityFactory <F1ChiefMechanicEntity> f1ChiefMechanicEntityFactory,
     IIntegerIdentityFactory <F1DriverEntity> f1DriverEntityFactory,
     IIntegerIdentityFactory <NonF1ChiefCommercialEntity> nonF1ChiefCommercialEntityFactory,
     IIntegerIdentityFactory <NonF1ChiefDesignerEntity> nonF1ChiefDesignerEntityFactory,
     IIntegerIdentityFactory <NonF1ChiefEngineerEntity> nonF1ChiefEngineerEntityFactory,
     IIntegerIdentityFactory <NonF1ChiefMechanicEntity> nonF1ChiefMechanicEntityFactory,
     IIntegerIdentityFactory <NonF1DriverEntity> nonF1DriverEntityFactory,
     IMapperService mapperService)
 {
     _domainService = domainService ?? throw new ArgumentNullException(nameof(domainService));
     _dataService   = dataService ?? throw new ArgumentNullException(nameof(dataService));
     _f1ChiefCommercialEntityFactory    = f1ChiefCommercialEntityFactory ?? throw new ArgumentNullException(nameof(f1ChiefCommercialEntityFactory));
     _f1ChiefDesignerEntityFactory      = f1ChiefDesignerEntityFactory ?? throw new ArgumentNullException(nameof(f1ChiefDesignerEntityFactory));
     _f1ChiefEngineerEntityFactory      = f1ChiefEngineerEntityFactory ?? throw new ArgumentNullException(nameof(f1ChiefEngineerEntityFactory));
     _f1ChiefMechanicEntityFactory      = f1ChiefMechanicEntityFactory ?? throw new ArgumentNullException(nameof(f1ChiefMechanicEntityFactory));
     _f1DriverEntityFactory             = f1DriverEntityFactory ?? throw new ArgumentNullException(nameof(f1DriverEntityFactory));
     _nonF1ChiefCommercialEntityFactory = nonF1ChiefCommercialEntityFactory ?? throw new ArgumentNullException(nameof(nonF1ChiefCommercialEntityFactory));
     _nonF1ChiefDesignerEntityFactory   = nonF1ChiefDesignerEntityFactory ?? throw new ArgumentNullException(nameof(nonF1ChiefDesignerEntityFactory));
     _nonF1ChiefEngineerEntityFactory   = nonF1ChiefEngineerEntityFactory ?? throw new ArgumentNullException(nameof(nonF1ChiefEngineerEntityFactory));
     _nonF1ChiefMechanicEntityFactory   = nonF1ChiefMechanicEntityFactory ?? throw new ArgumentNullException(nameof(nonF1ChiefMechanicEntityFactory));
     _nonF1DriverEntityFactory          = nonF1DriverEntityFactory ?? throw new ArgumentNullException(nameof(nonF1DriverEntityFactory));
     _mapperService = mapperService ?? throw new ArgumentNullException(nameof(mapperService));
 }
Ejemplo n.º 2
0
        public async Task <StatementExtension> MakeDecisionAsync(StatementExtension perceptionStatement, IPersonRepository personRepository,
                                                                 PersonDomainService personDomainService)
        {
            if (perceptionStatement == null)
            {
                return(null);
            }

            if (personRepository == null)
            {
                throw new ArgumentException("Person application service asked to make a decision without a person repository");
            }
            if (personDomainService == null)
            {
                throw new ArgumentException("Person application service asked to make a decision without a person domain service");
            }

            var personVerbs = new List <string>()
            {
                Verb.PersonCreationRequested, Verb.PersonRequested, Verb.PersonUpdateRequested
            };

            if (!personVerbs.Contains(perceptionStatement.verbString()))
            {
                return(null);
            }

            StatementExtension decisionStatement = null;

            await personRepository.SavePerceptionAsync(perceptionStatement);

            switch (perceptionStatement?.verbString())
            {
            case Verb.PersonCreationRequested:
                var personToCreate = perceptionStatement.targetData <Person>();
                decisionStatement = personDomainService.CreatePersonDecider(perceptionStatement, personToCreate);
                break;

            case Verb.PersonRequested:
                var idOfPersonRequested = perceptionStatement.targetId();
                var personRequested     = personRepository.RetrievePerson(idOfPersonRequested);
                decisionStatement = personDomainService.RetrievePersonDecider(perceptionStatement, personRequested);
                break;

            case Verb.PersonUpdateRequested:
                var idOfPerson     = perceptionStatement.targetId();
                var personToUpdate = personRepository.RetrievePerson(idOfPerson);
                decisionStatement = personDomainService.UpdatePersonDecider(perceptionStatement, personToUpdate);
                break;
            }

            await personRepository.SaveDecisionAsync(decisionStatement);

            return(decisionStatement);
        }