public ActionResult ChangeAddress(ChangeAddressViewModel model) { if (Validator.IsCanadianPostal(model.NewPostal, out string invalid)) { Customer curr = GetCurrentCustomer(); // make sure we found customer if (curr == null) { ModelState.AddModelError(String.Empty, "Sorry an error occured while trying to find you. Please try log in again."); return(View()); } curr.CustAddress = model.NewAddress; curr.CustCity = model.NewCity; curr.CustProv = model.NewProv; curr.CustCity = model.NewCity; curr.CustPostal = model.NewPostal; curr.CustCountry = model.NewCountry; if (model.Update(curr)) { return(RedirectToAction("Index", new { Message = ManageMessageId.EditAddressSuccess })); } // something went wrong return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } // made it here, something went wrong with data if (!string.IsNullOrEmpty(invalid)) { ModelState.AddModelError(String.Empty, "Invalid postal code."); } return(View()); }
public async Task<ActionResult> ChangeAddress([Bind("Email, NewAddress")] ChangeAddressViewModel avm) { if (User.Identity.Name != avm.Email) { return View("Error", new String[] { "There was a problem editing this customer. Try again!" }); } AppUser userLoggedIn = await _userManager.FindByNameAsync(User.Identity.Name); if (ModelState.IsValid == false) { return View(avm); } try { //find the record in the database AppUser dbUsers = _context.Users.Where(u => u.Email == avm.Email).FirstOrDefault(); //update the notes dbUsers.Address = avm.NewAddress; _context.Update(dbUsers); await _context.SaveChangesAsync(); } catch (Exception ex) { return View("Error", new String[] { "There was an error updating this order!", ex.Message }); } //send the user to the Account Index page. return RedirectToAction(nameof(Index)); }
public ActionResult ChangeAddress() { ChangeAddressViewModel model = new ChangeAddressViewModel(); model.states = new SelectList(db.State, "_ID", "_State"); return(View(model)); }
public ChangeAddressViewModel GetChangeAddressViewModel(ChangeAddressViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var person = Repository.GetById <Person>(model.PersonId); var rehydratedModel = new ChangeAddressViewModel() { PersonId = person.Id, PersonFirstName = person.FirstName, PersonLastName = person.LastName, EffectiveDate = model.EffectiveDate, Address = new Models.PostalAddress { Address = model.Address.Address, City = model.Address.City, PostalCode = model.Address.PostalCode, Province = model.Address.Province, Country = model.Address.Country } }; return(rehydratedModel); }
private void ValidateAgainstPersistence(ChangeAddressViewModel model) { var personDto = WorkerServices.GetChangeAddressViewModelPersonDto(model.PersonId); var persistenceValidationModelState = model.Validate(personDto); ModelState.Merge(persistenceValidationModelState); }
public async Task <IActionResult> ChangeAddress() { var epaoid = _contextAccessor.HttpContext.User.FindFirst("http://schemas.portal.com/epaoid")?.Value; try { var organisation = await _organisationsApiClient.GetEpaOrganisation(epaoid); var viewModel = new ChangeAddressViewModel { AddressLine1 = ModelState.IsValid ? organisation.OrganisationData?.Address1 : ModelState[nameof(ChangeAddressViewModel.AddressLine1)]?.AttemptedValue, AddressLine2 = ModelState.IsValid ? organisation.OrganisationData?.Address2 : ModelState[nameof(ChangeAddressViewModel.AddressLine2)]?.AttemptedValue, AddressLine3 = ModelState.IsValid ? organisation.OrganisationData?.Address3 : ModelState[nameof(ChangeAddressViewModel.AddressLine3)]?.AttemptedValue, AddressLine4 = ModelState.IsValid ? organisation.OrganisationData?.Address4 : ModelState[nameof(ChangeAddressViewModel.AddressLine4)]?.AttemptedValue, Postcode = ModelState.IsValid ? organisation.OrganisationData?.Postcode : ModelState[nameof(ChangeAddressViewModel.Postcode)]?.AttemptedValue }; return(View(viewModel)); } catch (EntityNotFoundException e) { _logger.LogWarning(e, "Failed to find organisation"); return(RedirectToAction(nameof(HomeController.NotRegistered), nameof(HomeController).RemoveController())); } }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { if (!ModelState.IsValid) { return(View(model)); } WorkerServices.ChangeAddress(model); return(Redirect("/Registry/")); }
public ActionResult ChangeAddress(string email) { ChangeAddressViewModel newavm = new ChangeAddressViewModel(); { newavm.Email = email; }; return View(newavm); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { ValidateAgainstPersistence(model); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } WorkerServices.ChangeAddress(model); return(Ok()); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { ValidateAgainstPersistence(model); if (!ModelState.IsValid) { var rehydratedModel = WorkerServices.GetChangeAddressViewModel(model); return(View(model)); } WorkerServices.ChangeAddress(model); return(RedirectToRoute("registry", new { })); }
public ActionResult ChangeAddress(string id) { if (User.Identity.IsAuthenticated && ((User.IsInRole("Administrator") && (id == User.Identity.GetUserId())) || User.IsInRole("Admin"))) { ChangeAddressViewModel model = new ChangeAddressViewModel { Address = KindergartenManager.GetKindergartenById(id).Address, AltAddress = KindergartenManager.GetKindergartenClaimValue(id, "AltAddress") }; return(View(model)); } return(RedirectToAction("Index", "Home")); }
public IActionResult ChangeAddress(ChangeAddressViewModel addressViewModel) { if (ModelState.IsValid) { if (UserService.ChangeAddress(User, addressViewModel, _db)) { return(Redirect("/Profile")); } return(Unauthorized()); } return(BadRequest("Something went wrong , please return to the homepage")); }
public async Task <IActionResult> ChangeAddress(ChangeAddressViewModel Address) { var user = await GetCurrentUserAsync(); if (user == null) { return(View("Error")); } user.Address1 = Address.Address1; await _userManager.UpdateAsync(user); //return View("Index"); return(RedirectToAction("Index", "Manage")); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { if (!ModelState.IsValid) { return(View(model)); } String user; user = HttpContext.User.Identity.GetUserName(); AppUser f = db.Users.FirstOrDefault(x => x.UserName == user); f.Address = model.NewAddress; db.SaveChanges(); return(RedirectToAction("Index", "Accounts")); }
public async Task <ActionResult> ChangeAddress(ChangeAddressViewModel model) { if (!ModelState.IsValid) { return(View(model)); } // Generate the token and send it var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); user.Address = model.Address; await UserManager.UpdateAsync(user); return(RedirectToAction("Index", "Manage")); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { if (ModelState.IsValid) { var address = this.Data.Addresses.GetById(model.Id); address.Town = model.Town; address.State = model.State; address.Country = model.Country; this.Data.Addresses.Update(address); this.Data.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public static bool ChangeAddress(ClaimsPrincipal user, ChangeAddressViewModel addressViewModel, WebshopDbContext db) { string guidString = user.Claims.Where(claim => claim.Type == ClaimTypes.Sid).Select(s => s.Value).SingleOrDefault(); if (!Guid.TryParse(guidString, out Guid userId)) { return(false); } User u = UserService.GetUser(userId, db); u.Street = addressViewModel.Street; u.PostalCode = addressViewModel.PostalCode; db.Update(u); db.SaveChanges(); return(true); }
public void ChangeAddress(ChangeAddressViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var cmd = new ChangePersonAddressCommand(model.PersonId, model.Address.Address, model.Address.PostalCode, model.Address.City, model.Address.Province, model.Address.Country); Bus.Send(cmd); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { if (User.Identity.IsAuthenticated && ((User.IsInRole("Administrator") && (model.Id == User.Identity.GetUserId())) || User.IsInRole("Admin"))) { if (ModelState.IsValid) { KindergartenManager.AddKindergartenClaimWithDel(model.Id, "AltAddress", model.AltAddress); KindergartenManager.EditKindergartenAddress(model.Id, model.Address); return(RedirectToAction("KindergartenProfile", "Kindergarten", new { id = model.Id })); } else { return(View(model)); } } return(RedirectToAction("Index", "Home")); }
public ActionResult ChangeAddress(ChangeAddressViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } Account a = new Account(User.Identity.GetUserId()); a.Buyer.Address = model.NewAddress; a.Buyer.City = new City(model.CityId); return(RedirectToAction("Index")); } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Manage", "ChangeAddress"); return(RedirectToAction("Index", "Error", new { model = error })); } }
public void ChangeAddress(ChangeAddressViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var effectiveDateTime = model.EffectiveDate; var effectiveDate = new DateTime(effectiveDateTime.Year, effectiveDateTime.Month, effectiveDateTime.Day); var cmd = new ChangePersonAddressCommand(model.PersonId, model.Address.Address, model.Address.PostalCode, model.Address.City, model.Address.Province, model.Address.Country, effectiveDate); Bus.Send(cmd); }
public ChangeAddressViewModel GetChangeAddressViewModel(Guid personId) { var person = Repository.GetById <Person>(personId); var model = new ChangeAddressViewModel() { PersonId = person.Id }; if (person.LegalAddress != null) { model.Address = new Models.PostalAddress { Address = person.LegalAddress.Address, City = person.LegalAddress.City, PostalCode = person.LegalAddress.PostalCode, Province = person.LegalAddress.Province, Country = person.LegalAddress.Country }; } return(model); }
public async Task <ActionResult> ChangeAddress(ChangeAddressViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userId = User.Identity.GetUserId(); var user = UserManager.FindById(userId); Identifiers id = user.Identifier; id.Address = model.Address; user.Identifier = id; var result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeAddressSuccess })); } AddErrors(result); return(View(model)); }
public async Task <IActionResult> ChangeAddress(ChangeAddressViewModel vm) { var epaoid = _contextAccessor.HttpContext.User.FindFirst("http://schemas.portal.com/epaoid")?.Value; try { var organisation = await GetEpaOrganisation(epaoid); if (organisation == null) { return(RedirectToAction(nameof(HomeController.NotRegistered), nameof(HomeController).RemoveController())); } if (vm.ActionChoice == "Save") { // regardless of whether the model is invalid, when the values have not been changed do not update if (string.Equals(vm.AddressLine1, organisation.OrganisationData?.Address1) && string.Equals(vm.AddressLine2, organisation.OrganisationData?.Address2) && string.Equals(vm.AddressLine3, organisation.OrganisationData?.Address3) && string.Equals(vm.AddressLine4, organisation.OrganisationData?.Address4) && string.Equals(vm.Postcode, organisation.OrganisationData?.Postcode)) { ModelState.Clear(); return(RedirectToAction(nameof(OrganisationDetails))); } if (!ModelState.IsValid) { return(RedirectToAction(nameof(ChangeAddress))); } vm = new ChangeAddressViewModel { AddressLine1 = vm.AddressLine1, AddressLine2 = vm.AddressLine2, AddressLine3 = vm.AddressLine3, AddressLine4 = vm.AddressLine4, Postcode = vm.Postcode }; return(View("ChangeAddressConfirm", vm)); } else if (vm.ActionChoice == "Confirm") { var userId = _contextAccessor.HttpContext.User.FindFirst("UserId").Value; var request = new UpdateEpaOrganisationAddressRequest { AddressLine1 = vm.AddressLine1, AddressLine2 = vm.AddressLine2, AddressLine3 = vm.AddressLine3, AddressLine4 = vm.AddressLine4, Postcode = vm.Postcode, OrganisationId = organisation.OrganisationId, UpdatedBy = Guid.Parse(userId) }; var notifiedContacts = await _organisationsApiClient.UpdateEpaOrganisationAddress(request); if (notifiedContacts == null) { throw new Exception("Unable to update the address"); } vm = new ChangeAddressViewModel { AddressLine1 = vm.AddressLine1, AddressLine2 = vm.AddressLine2, AddressLine3 = vm.AddressLine3, AddressLine4 = vm.AddressLine4, Postcode = vm.Postcode, Contacts = notifiedContacts }; return(View("ChangeAddressUpdated", vm)); } } catch (Exception e) { _logger.LogError(e, "Failed to change address"); ModelState.AddModelError(nameof(ChangeAddressViewModel.AddressLine1), "Unable to update the address at this time."); return(RedirectToAction(nameof(ChangeAddress))); } return(RedirectToAction(nameof(OrganisationDetails))); }