public async Task <ActionResult> ForgotPassword([Bind(Include = "UserIdentity")] ForgotPasswordViewModel model) { if (ModelState.IsValid) { try { var userService = ServiceFactory.GetUserService(); string userEmail = userService.GetEmailByUserIdentity(model.UserIdentity); int id = userService.GetIdOflogin(userEmail); string newPassword = PasswordEncryptor.RendomPassword(); if (userService.UpdatePassword(id, newPassword)) { string subject = "Ваш пароль был изменен"; string body = "Новый пароль: " + newPassword; if (await MailDispatch.SendingMailAsync(userEmail, subject, body).ConfigureAwait(false)) { return(this.RedirectToAction("ForgotPasswordSuccess")); } } } catch (UserValidationException ex) { ModelState.AddModelError(ex.UserProperty, ex.Message); return(View()); } } else { ModelState.AddModelError(string.Empty, "Ошибка восстановления пароля"); return(View()); } return(View()); }