public async Task <ChangedInformationResultModel> RegisterAsync(string email, string firstName, string lastName, string middleName, string password, string role, string position) { var existingUser = await _userManager.FindByEmailAsync(email); if (existingUser != null) { return(new ChangedInformationResultModel { Success = false, ErrorsMessages = new[] { "User with this email addres already exist" } }); } var userName = email.Substring(0, email.LastIndexOf('@')); var newUser = new UserModel { Email = email, UserName = userName, Role = role, FirstName = firstName, LastName = lastName, Position = await _positionManager.AddNewPositionAsync(position), MiddleName = middleName }; var createdUser = await _userManager.CreateAsync(newUser, password); if (!createdUser.Succeeded) { return(new ChangedInformationResultModel { Success = false, ErrorsMessages = createdUser.Errors.Select(x => x.Description) }); } await _emailSendMessageManager.SendEmailAsync( email, "Оповещение", EmailMessageWrapper.RegClientMessageWrapp(firstName, lastName, email, password)); return(new ChangedInformationResultModel { Success = true }); }
public async Task <ChangedInformationResultModel> ChangePositionAsync(string username, string newPosition) { var foundUser = await _userManager.FindByNameAsync(username); if (foundUser != null) { foundUser.Position = await _positionManager.AddNewPositionAsync(newPosition); IdentityResult identityResult = await _userManager.UpdateAsync(foundUser); return(new ChangedInformationResultModel { Success = identityResult.Succeeded, ErrorsMessages = identityResult.Errors.Select(x => x.Description) }); } else { return(new ChangedInformationResultModel { Success = false, ErrorsMessages = new[] { "User not found" } }); } }