Esempio n. 1
0
        public async Task <SignUpResult> Execute(SignUpCommand command)
        {
            bool emailAlreadyExists = await _userReadOnlyRepository.Any(command.Email);

            if (emailAlreadyExists)
            {
                throw new UserEmailAlreadyExistsException("An account already exists with this email");
            }

            Account account = new Account();

            User user = new User(
                account.Id,
                command.Email,
                Password.Create(command.Password),
                command.Name,
                command.Picture);


            await _accountWriteOnlyRepository.Create(account);

            await _userWriteOnlyRepository.Create(user);

            string token = Token.Generate(user, jwtSettings);

            SignUpResult result = new SignUpResult
            {
                Token     = token,
                UserId    = user.Id,
                AccountId = account.Id
            };

            return(result);
        }