protected override async Task Handle(DeleteSharedListItem command) { var item = await WriteService.GetAsync <SharedBookListItem>(command.ItemId); if (item == null) { throw new ObjectNotExistException <SharedBookListItem>( new OnExceptionObjectDescriptor { ["Id"] = command.ItemId.ToString() }); } var accessSpecification = new BookListAccessSpecification(item.BookList); if (!accessSpecification.SatisfiedBy(command.UserId)) { throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor { ["Id"] = item.BookListId.ToString() }); } await WriteService.DeleteAsync <SharedBookListItem>(item.Id); }
protected override async Task <int> GetBookListId(AddSharedListItem command) { var list = await WriteService.GetAsync <BookList>(command.ListId); if (list == null) { throw new ObjectNotExistException <BookList>( new OnExceptionObjectDescriptor { ["Id"] = command.ListId.ToString() }); } var accessSpecification = new BookListAccessSpecification(list); if (!accessSpecification.SatisfiedBy(command.UserId)) { throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor { ["Id"] = command.ListId.ToString() }); } return(command.ListId); }
private static void Validate(BookList list, int userId, IEnumerable <BookListItem> items, int bookId) { var accessSpecification = new BookListAccessSpecification(list); if (!accessSpecification.SatisfiedBy(userId)) { throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor { ["Id"] = list.Id.ToString() }); } if (items.Any(i => i.BookId == bookId && i.BookListId == list.Id)) { throw new ObjectAlreadyExistsException <BookListItem>(new OnExceptionObjectDescriptor { ["Id"] = bookId.ToString() }); } }