Example #1
0
        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);
        }
Example #2
0
        protected override async Task Handle(SharePrivateList command)
        {
            var privateList = await _privateListFetchHandler.Handle(new GetPrivateListByUserId(command.UserId));

            var sharedList = CreateSharedListFromPrivate(privateList, command);

            var user = await WriteService.GetAsync <User>(command.UserId);

            var listNameSpecification = new SharedListNameSpecification(user);

            if (!listNameSpecification.SatisfiedBy(sharedList.Name))
            {
                throw new ObjectAlreadyExistsException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Name"] = command.Name
                });
            }

            await WriteService.SaveAsync(sharedList);

            var privateItems = await _privateItemsFetchHandler.Handle(new GetItemsByListId(privateList.Id));

            var sharedItems = CreateSharedItemsFromPrivateItems(privateItems, sharedList.Id);

            await WriteService.SaveBatchAsync(sharedItems);
        }
Example #3
0
        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);
        }
Example #4
0
        protected sealed override async Task <TDto> Handle(TCommand command)
        {
            var listId = await GetBookListId(command);

            var book = await WriteService.GetAsync <Book>(command.BookId);

            if (await DoItemExist(command.BookId, listId))
            {
                throw new ObjectAlreadyExistsException <TItem>(new OnExceptionObjectDescriptor
                {
                    ["Author"] = book.Author,
                    ["Title"]  = book.Title
                });
            }

            var item = CreateItem(book, listId);

            await SaveAsync(item);

            return(Convert(item));
        }
Example #5
0
        protected override async Task <SharedBookListPreviewDto> Handle(CreateSharedList command)
        {
            var user = await WriteService.GetAsync <User>(command.UserId);

            if (user == null)
            {
                throw new ObjectNotExistException <User>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = command.UserId.ToString()
                });
            }

            var listNameSpecification = new SharedListNameSpecification(user);

            if (!listNameSpecification.SatisfiedBy(command.Name))
            {
                throw new ObjectAlreadyExistsException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Name"] = command.Name
                });
            }

            var list = new BookList
            {
                Name    = command.Name,
                OwnerId = user.Id,
                Type    = BookListType.Shared
            };

            var tags = await _bookListService.ProcessTags(command.Tags, list.Id);

            if (tags != null)
            {
                list.SharedBookListTags = tags;
            }

            await WriteService.SaveAsync(list);

            return(Mapper.Map <BookList, SharedBookListPreviewDto>(list));
        }
Example #6
0
 protected override async Task <PrivateBookListItem> GetEntity(UpdatePrivateListItem command)
 {
     return(await WriteService.GetAsync <PrivateBookListItem>(command.ItemId));
 }