Esempio n. 1
0
        private void Initialize(SaveBookInputDto book, EntityDependency[] dependencies)
        {
            RegisterCommandRepositoryFactory <Book>(() => new BookCommandRepository());

            RootEntity = new Book
            {
                Id            = book.BookId,
                Title         = book.Title,
                Category      = book.Category,
                DatePublished = book.DatePublished,
                PublisherId   = book.PublisherId,
                IsHardCopy    = book.IsHardCopy
            };

            Enqueue(new UpdateEntityCommandOperation <Book>(RootEntity, dependencies));

            Enqueue(new DeleteLinksCommandOperation <Book>(RootEntity, "UnlinkPagesFromBook"));

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

                    if (dto is SavePageInputDto)
                    {
                        operation = new AddLinkedAggregateCommandOperation <Book, CreatePageCommandAggregate, SavePageInputDto>(
                            RootEntity,
                            (SavePageInputDto)dto,
                            new EntityDependency[]
                        {
                            new EntityDependency
                            {
                                Entity   = RootEntity,
                                Selector = "Pages"
                            }
                        }
                            );

                        Enqueue(operation);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }
Esempio n. 2
0
 public UpdateBookCommandAggregate(SaveBookInputDto book, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(BookWithPagesConnectionClass.GetConnectionName()))
 {
     Initialize(book, dependencies);
 }