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 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; }
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); }