コード例 #1
0
        public async Task <string> Handle(RegisterUserCommand request, CancellationToken cancellationToken)
        {
            var password   = _securityService.HashPassword(request.Password);
            var userExists = await _readUserRepository.UserExistsByEmailAsync(request.Email);

            var users = await _userRepository.GetAllAsync();

            var id = await _userRepository.NextIdAsync();

            if (userExists)
            {
                throw new ApplicationException("Username or email already exists");
            }
            var user = new UserAggregate(id, password, new List <Right>(), request.Email,
                                         request.Username);

            user.SetMandatoryRoles(users);

            await _userRepository.SetAsync(user);

            return(id.ToString());
        }