Beispiel #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);
        }
Beispiel #2
0
        protected sealed override async Task <TDto> Handle(TCommand command)
        {
            var entity = await GetEntity(command);

            await Validate(entity, command);

            Update(entity, command);

            await WriteService.SaveAsync(entity);

            return(Convert(entity, command));
        }
Beispiel #3
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));
        }
Beispiel #4
0
        protected override async Task <AuthenticationDataDto> Handle(RegisterUser command)
        {
            var user = await _userFetchHandler.Handle(new GetUserByLogin(command.Email));

            if (user != null)
            {
                throw new ObjectAlreadyExistsException <User>(new OnExceptionObjectDescriptor
                {
                    ["Email"] = command.Email
                });
            }

            user = new User
            {
                Login    = command.Email,
                Password = _encryptionService.Encrypt(command.Password),
                RoleId   = (int)UserRole.User,
                Profile  = new Profile {
                    Email = command.Email
                }
            };

            await WriteService.SaveAsync(user);

            await WriteService.SaveAsync(new BookList
            {
                Name    = "Default",
                OwnerId = user.Id,
                Type    = BookListType.Private
            });

            if (_encryptionService.Encrypt(command.Password) != user.Password)
            {
                throw new WrongPasswordException();
            }

            return(_authenticationService.Authenticate(user));
        }
Beispiel #5
0
 protected override async Task SaveAsync(PrivateBookListItem item)
 {
     await WriteService.SaveAsync(item);
 }