Ejemplo n.º 1
0
        private void Initialize(SaveOrganizationInputDto organization, EntityDependency[] dependencies)
        {
            RegisterCommandRepositoryFactory <Organization>(() => new OrganizationCommandRepository());

            RootEntity = new Organization
            {
                Id   = organization.OrganizationId,
                Name = organization.Name
            };

            Enqueue(new SaveEntityCommandOperation <Organization>(RootEntity, dependencies));

            Enqueue(new DeleteLinksCommandOperation <Organization>(RootEntity, "UnlinkPhonesFromOrganization"));

            if (organization.Phones?.Any() == true)
            {
                foreach (var dto in organization.Phones)
                {
                    ILinkedAggregateCommandOperation operation;

                    if (dto is SavePhoneInputDto)
                    {
                        operation = new AddLinkedAggregateCommandOperation <Organization, SavePhoneCommandAggregate, SavePhoneInputDto>(
                            RootEntity,
                            (SavePhoneInputDto)dto,
                            new EntityDependency[]
                        {
                            new EntityDependency
                            {
                                Entity   = RootEntity,
                                Selector = "Phones"
                            }
                        }
                            );

                        Enqueue(operation);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            Enqueue(new DeleteLinksCommandOperation <Organization>(RootEntity, "UnlinkAddressFromOrganization"));

            if (organization.Address != null)
            {
                ILinkedAggregateCommandOperation operation;

                var address = organization.Address;

                if (address is SaveAddressInputDto)
                {
                    operation = new AddLinkedAggregateCommandOperation <Organization, SaveAddressCommandAggregate, SaveAddressInputDto>(
                        RootEntity,
                        (SaveAddressInputDto)address,
                        new EntityDependency[]
                    {
                        new EntityDependency
                        {
                            Entity   = RootEntity,
                            Selector = "Address"
                        }
                    }
                        );

                    Enqueue(operation);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Ejemplo n.º 2
0
 public SaveOrganizationCommandAggregate(SaveOrganizationInputDto organization, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(OrganizationPersonWithCommonEntitiesConnectionClass.GetConnectionName()))
 {
     Initialize(organization, dependencies);
 }