Beispiel #1
0
        public async Task <UserCreationUpdateResult> CreateAsync(User user, string password)
        {
            var errorResults = new AccountValidationError();
            var result       = new UserCreationUpdateResult
            {
                Errors = await AccountValidator.IsValidAccountAsync(user, this)
            };

            if (result.Errors != null && result.Errors.Any())
            {
                return(result);
            }

            _repo.Add(user);
            var createUser = await _userManager.CreateAsync(user, password);

            if (createUser.Succeeded)
            {
                result.Success = true;
                result.User    = user;
            }
            else
            {
                errorResults.ErrorCode = Model.Enums.AccountValidationError.USERNAME_ALREADY_EXISTS;
                errorResults.Message   = createUser.Errors.FirstOrDefault().Description;
            }

            return(result);
        }