public async Task <IActionResult> ChangePhoneNumber(PhoneNumberFieldModel model) { string confirmText = null; var user = await _userManager.FindByNameAsync(User.Identity.Name); if (model.PhoneNumber != null) { if (new PhoneAttribute().IsValid(model.PhoneNumber) && model.PhoneNumber.Length == 19) { if (user is AppUser) { user.PhoneNumber = model.PhoneNumber; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { confirmText = "Phone number successfully changed!"; } else { for (int i = 0; i < result.Errors.Count(); i++) { ModelState.AddModelError("", result.Errors.ElementAt(i).Description); } } } else { ModelState.AddModelError("", "The user doesn't found. Please, reload page or refer to administrator."); } } else { ModelState.AddModelError("", "Input correct phone number"); } } else { ModelState.AddModelError("PhoneNumber", "The field is required"); } var returnModel = await getUserProps(User.Identity.Name); return(PartialView("Settings/PhoneNumberField", new PhoneNumberFieldModel() { PhoneNumber = returnModel.PhoneNumber, ContentOpened = true, ConfirmText = confirmText })); }
public void BeforeEach() { _classUnderTest = new PhoneNumberFieldModel(); }