public ActionResult Index(FormsAndValidationViewModel model) { if (ModelState.IsValid) { Feedback.AddMessage(FeedbackMessageType.Success, "All fields validated correctly.", "Contratulations!"); } else { Feedback.AddMessage(FeedbackMessageType.Error, "Some fields are not valid.", "Oops!"); } model = BuildFormsAndValidationViewModel(model); return(View(model)); }
public ActionResult Edit(int id, UserViewModel model) { var entity = _managementUsersRepository.GetById(id); if (ModelState.IsValid) { entity.Realms = model.Realms.Select(r => r.ChangeType <Realm>()).ToList(); entity.Roles = model.Roles.Select(r => r.ChangeType <Role>()).ToList(); _managementUsersRepository.Update(entity); Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString("DefaultSuccessMessage")); return(RedirectToAction(nameof(Index))); } model = BuildUserViewModel(userEntity: entity, postedModel: model); return(View("Manager", model)); }
public async Task <ActionResult> PasswordChange(AccountPasswordChangeViewModel model) { if (ModelState.IsValid) { var result = await _appUserManager.ChangePasswordAsync( User.Id, model.Password, model.NewPassword ); if (result.Succeeded) { Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString <AreaResources>("DefaultSuccessMessage")); return(RedirectToAction("Index", "Home", new { area = AppAreas.GetAreaName(Area.Root) })); } ModelState.AddModelError("Password", GetLocalizedString <AreaResources>("InvalidPasswordMessage")); } return(View(model)); }
public async Task <ActionResult> Edit(ProfileEditViewModel model) { if (ModelState.IsValid) { model.Id = User.Id; var adminUser = BuildAdminUserEntity(model); await _userManager.UpdateProfileAsync(adminUser); await _signInManager.RefreshIdentity(User, reloadClaims : true); Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString("DefaultSuccessMessage")); return(RedirectToAction(nameof(Edit))); } var entity = await _userManager.FindByIdAsync(User.Id); model = BuildEditProfileViewModel(adminUser: entity, postedModel: model); return(View(model)); }
public ActionResult Add(UserViewModel model) { if (ModelState.IsValid) { var user = new UserEntity { FullName = model.FullName, Email = model.Email, Realms = model.Realms.Select(realm => realm.ChangeType <Realm>()).ToList(), Roles = model.Roles.Select(role => role.ChangeType <Role>()).ToList() }; // user.SetDefaultUserName(); user.LockoutEnabled = _Constants.UsersLockoutEnabledByDefault; user.EmailConfirmed = true; // var initialPassword = user.GetInitialPassword(); user.PasswordHash = _passwordHasher.HashPassword(initialPassword); // user = _managementUsersRepository.Create(user); if (user.Id > 0) { // var mail = new UserCreatedMessageViewModel() { Email = user.Email, FullName = user.FullName, InitialPassword = initialPassword, PageTitle = GetLocalizedString("Management_Users_UserCreatedMessageSubject"), }; // Provide the user information on how to access allowed realms. foreach (var realm in user.Realms) { switch (realm) { case Realm.AdminWebsite: { var link = Url.Action( "Index", "Home", new { area = AppAreas.GetAreaName(Area.Root) }, protocol: Request.Url.Scheme); mail.AllowedRealms.Add(new UserCreatedMessageViewModel.AllowedRealmInfo() { Realm = realm, RealmUri = new Uri(link, UriKind.Absolute) }); } break; } } // var subject = $"[{GetLocalizedString("_App_Name")}] {mail.PageTitle}"; var message = RenderViewToString("UserCreatedMessage", model: mail); // _emailDispatcherService.Dispatch(message, subject, new MailAddress(user.Email, user.FullName)); // Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString("DefaultSuccessMessage")); // return(RedirectToAction(nameof(Index))); } ModelState.AddModelError(string.Empty, GetLocalizedString("DefaultErrorMessage")); } model = BuildUserViewModel(postedModel: model); return(View("Manager", model)); }