public AddPageAggregate(RepositoryContext context, BookEntity bookEntity, PageInputDto pageInputDto) : base(context) { RootEntity = bookEntity; var addPage = new AddLinkedEntityCommandOperation <BookEntity, PageEntity>( RootEntity, getLinkedEntity: () => new PageEntity { Index = pageInputDto.Index } ); Enqueue(addPage); }
public UserCommandAggregate(IRepositoryContext context, UserInputDto userInputDto) : base(context) { RootEntity = new UserEntity { Name = userInputDto.Name }; Enqueue( new SaveEntityCommandOperation <UserEntity>(RootEntity) ); foreach (var photoDto in userInputDto.Photos) { var photoEntity = new PhotoEntity { Description = photoDto.Description }; var addPhoto = new AddLinkedEntityCommandOperation <UserEntity, PhotoEntity>( RootEntity, getLinkedEntity: () => photoEntity ); Enqueue(addPhoto); if (photoDto.IsDefault) { var updateUserWithDefaultPhoto = new UpdateEntityCommandOperation <UserEntity>( RootEntity, new EntityDependency[] { new EntityDependency { Entity = RootEntity }, new EntityDependency { Entity = photoEntity } } ); Enqueue(updateUserWithDefaultPhoto); } } }
public ReplacePagesAggregate(RepositoryContext context, BookEntity bookEntity, PageInputDto[] pageInputDtos) : base(context) { RootEntity = bookEntity; var removeLinkedEntities = new DeleteLinksCommandOperation <BookEntity>(bookEntity, selector: null); Enqueue(removeLinkedEntities); foreach (var pageInputDto in pageInputDtos) { var addPage = new AddLinkedEntityCommandOperation <BookEntity, PageEntity>( bookEntity, () => new PageEntity { Index = pageInputDto.Index }); Enqueue(addPage); } }