示例#1
0
        protected override Task Validate(BookList entity, UpdatePrivateList command)
        {
            if (entity == null)
            {
                throw new ObjectNotExistForException <BookList, User>(null, new OnExceptionObjectDescriptor
                {
                    ["Id"] = command.UserId.ToString()
                });
            }

            var accessSpecification = new BookListOwnerAccessSpecification(entity);

            if (!accessSpecification.SatisfiedBy(command.UserId))
            {
                throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = entity.Id.ToString()
                });
            }

            return(Task.CompletedTask);
        }
示例#2
0
        protected override async Task Handle(DeleteSharedList 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 BookListOwnerAccessSpecification(list);

            if (!accessSpecification.SatisfiedBy(command.UserId))
            {
                throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = list.Id.ToString()
                });
            }

            await WriteService.DeleteAsync <BookList>(list.Id);
        }
示例#3
0
        protected override Task Validate(PrivateBookListItem entity, UpdatePrivateListItem command)
        {
            if (entity == null)
            {
                throw new ObjectNotExistException <PrivateBookListItem>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = command.ItemId.ToString()
                });
            }

            var accessSpecification = new BookListOwnerAccessSpecification(entity.BookList);

            if (!accessSpecification.SatisfiedBy(command.UserId))
            {
                throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = entity.BookListId.ToString()
                });
            }

            PrivateBookListItemStatusValidator.Validate(entity.Status, (BookItemStatus)command.Status);

            return(Task.CompletedTask);
        }
示例#4
0
        protected override async Task Handle(DeletePrivateItem command)
        {
            var item = await WriteService.GetAsync <PrivateBookListItem>(command.ItemId);

            if (item == null)
            {
                throw new ObjectNotExistException <PrivateBookListItem>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = command.ItemId.ToString()
                });
            }

            var accessSpecification = new BookListOwnerAccessSpecification(item.BookList);

            if (!accessSpecification.SatisfiedBy(command.UserId))
            {
                throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = item.BookListId.ToString()
                });
            }

            await WriteService.DeleteAsync <PrivateBookListItem>(item.Id);
        }