public ActionResult Edit(RecurringOrderPostViewModel model) { var customer = HttpContext.GetCustomer(); if (!ModelState.IsValid) { return(View(ActionNames.Edit, ControllerHelper.BuildRecurringOrderEditViewModel( recurringOrderId: model.RecurringOrderId, address: new AddressDetailViewModel( address: model.Address, residenceTypeOptions: AddressSelectListBuilder.BuildResidenceTypeSelectList(model.Address.ResidenceType.ToString()), stateOptions: AddressSelectListBuilder.BuildStateSelectList(model.Address.Country, model.Address.State), countryOptions: AddressSelectListBuilder.BuildCountrySelectList(model.Address.Country), showCompanyField: AddressSettings.ShowCompanyField, showNickName: AddressSettings.ShowNickName, showSuite: AddressSettings.ShowSuite, showResidenceTypeField: true, showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(model.Address.Country), returnUrl: string.Empty, header: AddressHeaderProvider.GetHeaderText(model.Address.Id, AddressTypes.Billing)), creditCard: model.CreditCard, customer: customer))); } if (!customer.Owns.RecurringOrder(model.RecurringOrderId)) { throw new HttpException(403, "Forbidden"); } var result = ControllerHelper.UpdateRecurringOrder( recurringOrderId: model.RecurringOrderId, address: TypeConversions.ConvertToAddress(model.Address, customer), creditCard: model.CreditCard, customer: customer); switch (result.Status) { case RecurringOrderActionStatus.Failure: NoticeProvider.PushNotice(result.Message, NoticeType.Failure); break; default: case RecurringOrderActionStatus.Success: break; } return(RedirectToAction(ActionNames.Index)); }
public int UpdateAddress(AddressViewModel address, Customer customer) { var adnsfAddress = TypeConversions.ConvertToAddress(address, customer); if (address.Id.HasValue) { if (!Customer.OwnsThisAddress(customer.CustomerID, (int)address.Id)) { throw new HttpException(403, "Forbidden"); } adnsfAddress.UpdateDB(); } else { adnsfAddress.InsertDB(); } return(adnsfAddress.AddressID); }
public ActionResult Detail(AddressPostViewModel model, string addressType, string returnUrl, bool makePrimary = false) { var customer = HttpContext.GetCustomer(); var safeReturnUrl = Url.MakeSafeReturnUrl(returnUrl, Url.Action(ActionNames.Index)); if (model.Address.Id.HasValue) { var verificationAddress = new Address(); verificationAddress.LoadFromDB(model.Address.Id.Value); if (verificationAddress.CustomerID != customer.CustomerID) { throw new HttpException(404, null); } } var addressTypeValue = GetAddressType(addressType); var countries = SelectListBuilder.BuildCountrySelectList(model.Address.Country); var states = SelectListBuilder.BuildStateSelectList(countries.SelectedValue.ToString(), model.Address.State); if (!ModelState.IsValid) { return(View(ActionNames.Detail, new AddressDetailViewModel( address: model.Address, residenceTypeOptions: SelectListBuilder.BuildResidenceTypeSelectList(model.Address.ResidenceType), stateOptions: states, countryOptions: countries, showCompanyField: AddressSettings.ShowCompanyField, showNickName: AddressSettings.ShowNickName, showSuite: AddressSettings.ShowSuite, showResidenceTypeField: ShowResidenceTypeField(addressTypeValue), showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(countries.SelectedValue.ToString()), returnUrl: safeReturnUrl, header: AddressHeaderProvider.GetHeaderText(model.Address.Id, addressTypeValue), makePrimary: makePrimary, enablePhoneInputMask: AddressSettings.UsePhoneNumberMask))); } var addressValidationResults = AddressValidationProviderFactory .Create() .Select(v => v .Validate( address: TypeConversions.ConvertToAddress(model.Address, customer), addressType: addressTypeValue) ) .ToArray(); if (addressValidationResults .Where(v => v.Status == AddressValidationStatus.Failure) .Any()) { foreach (var addressValidationResult in addressValidationResults .Where(v => v.Status == AddressValidationStatus.Failure)) { NoticeProvider.PushNotice( message: string.Concat(AppLogic.GetString("address.validation.errormsg", customer.LocaleSetting), addressValidationResult.Message), type: NoticeType.Failure); } var correctedAddress = addressValidationResults .Where(v => v.CorrectedAddresses != null) .SelectMany(v => v .CorrectedAddresses .Select(a => TypeConversions.ConvertToAddressViewModel(a, customer))) .FirstOrDefault() ?? model.Address; //remove fields USPS could have modified so corrected values will display on front end ModelState.Remove("Address.Address1"); ModelState.Remove("Address.Address2"); ModelState.Remove("Address.City"); ModelState.Remove("Address.State"); ModelState.Remove("Address.Zip"); return(View(ActionNames.Detail, new AddressDetailViewModel( address: correctedAddress, residenceTypeOptions: SelectListBuilder.BuildResidenceTypeSelectList(model.Address.ResidenceType), stateOptions: states, countryOptions: countries, showCompanyField: AddressSettings.ShowCompanyField, showNickName: AddressSettings.ShowNickName, showSuite: AddressSettings.ShowSuite, showResidenceTypeField: ShowResidenceTypeField(addressTypeValue), showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(correctedAddress.Country), returnUrl: safeReturnUrl, header: AddressHeaderProvider.GetHeaderText(correctedAddress.Id, addressTypeValue), makePrimary: makePrimary, enablePhoneInputMask: AddressSettings.UsePhoneNumberMask))); } var updatedAddressId = ControllerHelper.UpdateAddress(model.Address, customer); if (makePrimary) { // Read the address back out of the database so that we can guarantee an address id before we try to make it a primary address var address = ControllerHelper.GetCustomerAddress(updatedAddressId, customer); MakePrimary(customer, addressTypeValue, address); } return(Redirect(safeReturnUrl)); }