Esempio n. 1
0
        public async Task <ActionResult <int> > Add(UserViewModel userViewModel)
        {
            var user = new ApplicationUser();

            UpdateUserDetails(userViewModel, user);

            IdentityResult result = await _userManager.CreateAsync(user);

            if (result.Succeeded)
            {
                var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                await UpdateUserRoles(userViewModel, user);

                await _emailService.SendActivationEmailAsync(user, TokenHelper.Encode(token));

                return(Ok());
            }
            else
            {
                string errorMessage = result.Errors?.FirstOrDefault()?.Description ?? "Error adding user";
                _errorLogger.LogError(new Exception(errorMessage));

                return(BadRequest(errorMessage));
            }
        }