public async Task <ActionResult> SaveFullEditChanges(EditLocalAdminViewModel model) { if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindByEmailAsync(model.Email); bool error = false; if (!string.IsNullOrEmpty(model.NewPassword)) { var result = UserManager.ChangePassword(user.Id, model.Password, model.NewPassword); if (!result.Succeeded) { ModelState["Password"].Errors.Add("Senha incorreta"); error = true; } } if (!error) { user = await UserManager.FindByEmailAsync(model.Email); LocalManager localAdmin = model.ToLocalAdmin(user.PasswordHash); BusinessManager.Instance.LocalManagers.Update(localAdmin); return(RedirectToAction("Index", "GlobalAdmin")); } } return(View("FullEdit", model)); }
private static void SetAddress(Address address, EditLocalAdminViewModel localAdminViewModel) { localAdminViewModel.Street = address.Street; localAdminViewModel.Square = address.Square; localAdminViewModel.PostalCode = address.PostalCode; localAdminViewModel.State = address.State; localAdminViewModel.City = address.City; }
private static Address GetAddress(EditLocalAdminViewModel registerModel) { return(new Address { City = registerModel.City, PostalCode = registerModel.PostalCode, Square = registerModel.Square, State = registerModel.State, Street = registerModel.Street }); }
public static ApplicationUser ToApplicationUser(this EditLocalAdminViewModel model) { return(new ApplicationUser { FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email, PhoneNumber = model.PhoneNumber, UserType = UserType.LocalAdmin }); }
public static LocalManager ToLocalAdmin(this EditLocalAdminViewModel model, string passwordHash) { return(new LocalManager { Address = GetAddress(model), StreetNumber = int.Parse(model.Number), CPF = model.CPF, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Password = passwordHash, RG = model.RG, Telephone = model.PhoneNumber, Complement = model.Complement }); }
public static EditLocalAdminViewModel ToEditLocalAdminViewModel(this LocalManager localAdmin) { var localAdminViewModel = new EditLocalAdminViewModel { CPF = localAdmin.CPF, Email = localAdmin.Email, FirstName = localAdmin.FirstName, LastName = localAdmin.LastName, Number = localAdmin.StreetNumber.ToString(), PhoneNumber = localAdmin.Telephone, RG = localAdmin.RG, Complement = localAdmin.Complement }; SetAddress(localAdmin.Address, localAdminViewModel); return(localAdminViewModel); }