public ActionResult Edit(int recurringOrderId) { var customer = HttpContext.GetCustomer(); var billingAddress = TypeConversions.ConvertToAddressViewModel( customer.PrimaryBillingAddress, customer); var countries = AddressSelectListBuilder.BuildCountrySelectList(billingAddress.Country); var states = AddressSelectListBuilder.BuildStateSelectList(countries.SelectedValue.ToString(), billingAddress.State); var address = new AddressDetailViewModel( address: billingAddress, residenceTypeOptions: AddressSelectListBuilder.BuildResidenceTypeSelectList(billingAddress.ResidenceType.ToString()), stateOptions: states, countryOptions: countries, showCompanyField: AddressSettings.ShowCompanyField, showNickName: AddressSettings.ShowNickName, showSuite: AddressSettings.ShowSuite, showResidenceTypeField: true, showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(billingAddress.Country), returnUrl: string.Empty, header: AddressHeaderProvider.GetHeaderText(billingAddress.Id, AddressTypes.Billing)); return(View(ControllerHelper.BuildRecurringOrderEditViewModel( recurringOrderId: recurringOrderId, address: address, creditCard: new CreditCardViewModel(), customer: customer))); }
public IEnumerable <AddressViewModel> GetCustomerAddresses(Customer customer) { var addressCollection = new Addresses(); addressCollection.LoadCustomer(customer.CustomerID); return(addressCollection .Cast <Address>() .Select(address => TypeConversions.ConvertToAddressViewModel(address, customer))); }
public AddressViewModel GetCustomerAddress(int?addressId, Customer customer) { var address = new Address(); if (addressId.HasValue) { address.LoadFromDB(addressId.Value); if (address.CustomerID != customer.CustomerID) { throw new HttpException(403, "Forbidden"); } } return(TypeConversions.ConvertToAddressViewModel(address, customer)); }
public ActionResult Index() { var customer = HttpContext.GetCustomer(); var shippingAddress = TypeConversions.ConvertToAddressViewModel( customer.PrimaryShippingAddress, customer); var countries = AddressSelectListBuilder.BuildCountrySelectList(shippingAddress.Country); var states = AddressSelectListBuilder.BuildStateSelectList(countries.SelectedValue.ToString(), shippingAddress.State); return(View(new AddressDetailViewModel( address: shippingAddress, residenceTypeOptions: AddressSelectListBuilder.BuildResidenceTypeSelectList(shippingAddress.ResidenceType.ToString()), stateOptions: states, countryOptions: countries, showCompanyField: AddressSettings.ShowCompanyField, showNickName: AddressSettings.ShowNickName, showSuite: AddressSettings.ShowSuite, showResidenceTypeField: true, showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(shippingAddress.Country), returnUrl: string.Empty, header: AddressHeaderProvider.GetHeaderText(shippingAddress.Id, AddressTypes.Shipping)))); }
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)); }
ActionResult RenderIndexView(CheckoutStageContext checkoutStageContext, PersistedCheckoutContext persistedCheckoutContext, PaymentMethodInfo selectedPaymentMethod, Customer customer, bool termsAndConditionsAccepted, string returnUrl, bool showCheckoutStageErrors) { var cart = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID()); // Build a model and render it var billingAddressViewModel = customer.PrimaryBillingAddress != null ? TypeConversions.ConvertToAddressViewModel(customer.PrimaryBillingAddress, customer) : null; var shippingAddressViewModel = customer.PrimaryShippingAddress != null ? TypeConversions.ConvertToAddressViewModel(customer.PrimaryShippingAddress, customer) : null; var cartPageAd = new PayPalAd(PayPalAd.TargetPage.Cart); var gatewayIsTwoCheckout = AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWTWOCHECKOUT && selectedPaymentMethod != null && selectedPaymentMethod.Name == AppLogic.ro_PMCreditCard; var shippingEnabled = checkoutStageContext.ShippingAddress.Disabled != true || checkoutStageContext.ShippingMethod.Disabled != true; var shippingInfoRequired = checkoutStageContext.ShippingAddress.Required == true || checkoutStageContext.ShippingMethod.Required == true; var billingInfoRequired = checkoutStageContext.BillingAddress.Required == true; var displayBillingSection = checkoutStageContext.BillingAddress.Disabled != true; var allowShipToDifferentThanBillTo = AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo"); // Display the shipping sections (both the Shipping Address section and the Shipping Method section) // only if shipping is enabled on the site. If so, than if shipping can be different // than billing, we need to show the Shipping Address form. // If shipping and billing can be different or the current payment // option doesn't care about billing, then show just the shipping section and that address will be used for // both shipping and billing. var displayShippingSections = shippingEnabled; var checkoutIsOffsiteOnly = PaymentOptionProvider.CheckoutIsOffsiteOnly(HttpContext, customer, cart); var paymentMethodStageState = ConvertStageStatusToDisplayState(checkoutStageContext.PaymentMethod, showCheckoutStageErrors); var model = new CheckoutIndexViewModel( selectedPaymentMethod: selectedPaymentMethod, selectedBillingAddress: billingAddressViewModel, selectedShippingAddress: shippingAddressViewModel, checkoutButtonDisabled: checkoutStageContext.PlaceOrderButton.Fulfilled != true, showOver13Required: Over13Required(customer), showOkToEmail: AppLogic.AppConfigBool("Checkout.ShowOkToEmailOnCheckout"), showTermsAndConditions: AppLogic.AppConfigBool("RequireTermsAndConditionsAtCheckout"), displayGiftCardSetup: checkoutStageContext.GiftCardSetup.Required == true, showOrderOptions: cart.AllOrderOptions.Any(), showOrderNotes: !AppLogic.AppConfigBool("DisallowOrderNotes"), showRealTimeShippingInfo: AppLogic.AppConfigBool("RTShipping.DumpDebugXmlOnCheckout") && (customer.IsAdminUser || customer.IsAdminSuperUser), allowShipToDifferentThanBillTo: allowShipToDifferentThanBillTo, displayShippingSections: displayShippingSections, displayBillingSection: displayBillingSection, shippingInfoIsRequired: shippingInfoRequired, billingInfoIsRequired: billingInfoRequired, displayTwoCheckoutText: gatewayIsTwoCheckout, displayContinueOffsite: selectedPaymentMethod != null && selectedPaymentMethod.Location == PaymentMethodLocation.Offsite, showPromotions: AppLogic.AppConfigBool("Promotions.Enabled"), showGiftCards: AppLogic.AppConfigBool("GiftCards.Enabled"), giftCardCoversTotal: cart.GiftCardCoversTotal(), checkoutIsOffsiteOnly: checkoutIsOffsiteOnly, pageTitle: AppLogic.GetString("checkout.indexpagetitle", customer.LocaleSetting), payPalBanner: cartPageAd.ImageMarkup, accountStageState: ConvertStageStatusToDisplayState(checkoutStageContext.Account, showCheckoutStageErrors), continueShoppingUrl: AppLogic.AppConfigBool("ContinueShopping.Enabled") ? Url.Content(returnUrl) : string.Empty, offsiteCheckoutError: checkoutIsOffsiteOnly && paymentMethodStageState == CheckoutStageDisplayState.Failing ? AppLogic.GetString("checkout.OffsiteCheckoutError") : string.Empty, paymentMethodStageState: paymentMethodStageState, billingAddressStageState: ConvertStageStatusToDisplayState(checkoutStageContext.BillingAddress, showCheckoutStageErrors), shippingAddressStageState: ConvertStageStatusToDisplayState(checkoutStageContext.ShippingAddress, showCheckoutStageErrors), shippingMethodStageState: ConvertStageStatusToDisplayState(checkoutStageContext.ShippingMethod, showCheckoutStageErrors), giftCardSetupStageState: ConvertStageStatusToDisplayState(checkoutStageContext.GiftCardSetup, showCheckoutStageErrors)) { OrderNotes = cart.OrderNotes, Over13Selected = persistedCheckoutContext.Over13Checked, OkToEmailSelected = customer.OKToEMail, TermsAndConditionsAccepted = termsAndConditionsAccepted }; return(View(model)); }