Exemple #1
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);
        }
Exemple #2
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));
        }