Esempio n. 1
0
        private void Initialize(PersonInputDto person, EntityDependency[] dependencies)
        {
            RegisterCommandRepositoryFactory <Person>(() => new PersonCommandRepository());

            var spouseDependency = (Person)dependencies?.SingleOrDefault()?.Entity;

            RootEntity = new Person
            {
                Id       = person.PersonId,
                Name     = person.Name,
                Gender   = person.Gender,
                SpouseId = (spouseDependency != null) ? spouseDependency.Id : person.SpouseId
            };

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

            Enqueue(new DeleteLinksCommandOperation <Person>(RootEntity, "UnlinkMarriedToFromPerson"));

            if (person.MarriedTo != null)
            {
                ILinkedAggregateCommandOperation operation;

                var marriedTo = person.MarriedTo;

                if (marriedTo is PersonInputDto)
                {
                    operation = new AddLinkedAggregateCommandOperation <Person, SavePersonCommandAggregate, PersonInputDto>(
                        RootEntity,
                        (PersonInputDto)marriedTo,
                        new EntityDependency[]
                    {
                        new EntityDependency
                        {
                            Entity   = RootEntity,
                            Selector = "MarriedTo"
                        }
                    }
                        );

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

                Enqueue(new UpdateEntityCommandOperation <Person>(RootEntity, new EntityDependency[]
                {
                    new EntityDependency
                    {
                        Entity   = operation.CommandAggregate.RootEntity,
                        Selector = "MarriedTo"
                    }
                }));
            }
        }
Esempio n. 2
0
 public SavePersonCommandAggregate(PersonInputDto person, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(PersonWithSpouseConnectionClass.GetConnectionName()))
 {
     Initialize(person, dependencies);
 }