Ejemplo n.º 1
0
        public async Task <AuthenticationResult> RegisterAsync(
            string userName,
            string password,
            string firstName,
            string lastName,
            string email,
            string phoneNumber)
        {
            var existsUserControlByUserName = await _applicationUserService.FindByNameAsync(userName);

            if (existsUserControlByUserName != null)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "User with this name already exist" },
                });
            }

            var newUser = new ApplicationUser()
            {
                UserName    = userName,
                FirstName   = firstName,
                LastName    = lastName,
                Email       = email,
                PhoneNumber = phoneNumber
            };

            var userCreated = await _userManager.CreateAsync(newUser, password);

            if (!userCreated.Succeeded)
            {
                return(new AuthenticationResult
                {
                    Errors = userCreated.Errors.Select(x => x.Description)
                });
            }

            return(await GenerateAuthenticationResultForUserAsync(newUser));
        }