public IActionResult BillingAddress(BillingAddressViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ValidateBillingAddressModel(ref model); if (ModelState.IsValid) { Address billingAddress = new Address(model.BusinessName, model.AddressLine1, model.AddressLine2, model.AddressLine3, model.City, model.County, model.Postcode, model.Country); if (_accountProvider.SetBillingAddress(UserId(), billingAddress)) { GrowlAdd("Billing address successfully updated"); return(RedirectToAction("Index", "Account")); } ModelState.AddModelError(String.Empty, "Failed to update billing address"); } return(View(model)); }
public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { if (viewModelState == null) { return; } // Try to populate address and payment method controls with default data if available ShippingAddressViewModel.SetLoadDefault(true); BillingAddressViewModel.SetLoadDefault(true); PaymentMethodViewModel.SetLoadDefault(true); // This ViewModel is an example of composition. The CheckoutHubPageViewModel manages // three child view models (Shipping Address, Billing Address, and Payment Method). // Since the FrameNavigationService calls this OnNavigatedTo method, passing in // a viewModelState dictionary, it is the responsibility of the parent view model // to manage separate dictionaries for each of its children. If the parent view model // were to pass its viewModelState dictionary to each of its children, it would be very // easy for one child view model to write over a sibling view model's state. if (e.NavigationMode == NavigationMode.New) { viewModelState["ShippingViewModel"] = new Dictionary <string, object>(); viewModelState["BillingViewModel"] = new Dictionary <string, object>(); viewModelState["PaymentMethodViewModel"] = new Dictionary <string, object>(); } ShippingAddressViewModel.OnNavigatedTo(e, viewModelState["ShippingViewModel"] as Dictionary <string, object>); BillingAddressViewModel.OnNavigatedTo(e, viewModelState["BillingViewModel"] as Dictionary <string, object>); PaymentMethodViewModel.OnNavigatedTo(e, viewModelState["PaymentMethodViewModel"] as Dictionary <string, object>); base.OnNavigatedTo(e, viewModelState); }
private async void GoNext() { IsShippingAddressInvalid = ShippingAddressViewModel.ValidateForm() == false; IsBillingAddressInvalid = !UseSameAddressAsShipping && BillingAddressViewModel.ValidateForm() == false; IsPaymentMethodInvalid = PaymentMethodViewModel.ValidateForm() == false; if (IsShippingAddressInvalid || IsBillingAddressInvalid || IsPaymentMethodInvalid) { return; } string errorMessage = string.Empty; try { await _accountService.VerifyUserAuthenticationAsync(); await ProcessFormAsync(); } catch (Exception ex) { errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message); } if (!string.IsNullOrWhiteSpace(errorMessage)) { await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable")); } }
public IActionResult BillingAddress(BillingAddressViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ValidateBillingAddressModel(ref model); if (ModelState.IsValid) { Address billingAddress = new Address(model.AddressId, 0, model.BusinessName, model.AddressLine1, model.AddressLine2, model.AddressLine3, model.City, model.County, model.Postcode, model.Country); if (_accountProvider.SetBillingAddress(UserId(), billingAddress)) { GrowlAdd(Languages.LanguageStrings.BillingAddressUpdated); return(RedirectToAction(nameof(Index), "Account")); } ModelState.AddModelError(String.Empty, Languages.LanguageStrings.FailedToUpdateBillingAddress); } model = new BillingAddressViewModel(GetModelData()); PrepareBillingAddressModel(ref model, null); return(View(model)); }
private async Task SaveAsync() { if (BillingAddressViewModel.ValidateForm()) { string errorMessage = string.Empty; try { await BillingAddressViewModel.ProcessFormAsync(); _navigationService.GoBack(); } catch (ModelValidationException mvex) { DisplayValidationErrors(mvex.ValidationResult); } catch (Exception ex) { errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message); } if (!string.IsNullOrWhiteSpace(errorMessage)) { await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable")); } } }
public ClsSalesChallan() { DAL = new ActiveDataAccess.ActiveDataAccess(Database.DBConnection); Model = new SalesChallanMasterViewModel(); ModelDetails = new List <SalesChallanDetailsViewModel>(); ModelTerms = new List <TermViewModel>(); ModelBillAddress = new BillingAddressViewModel(); ModelOtherDetails = new OtherDetailsViewModel(); }
public ClsPurchaseOrder() { DAL = new ActiveDataAccess.ActiveDataAccess(Database.DBConnection); Model = new PurchaseOrderMasterViewModel(); ModelDetails = new List <PurchaseOrderDetailsViewModel>(); ModelTerms = new List <TermViewModel>(); ModelBillAddress = new BillingAddressViewModel(); ModelOtherDetails = new OtherDetailsViewModel(); }
public ClsPurchaseChallanReturn() { DAL = new ActiveDataAccess.ActiveDataAccess(Database.DBConnection); Model = new PurchaseChallanReturnMasterViewModel(); ModelDetails = new List <PurchaseChallanReturnDetailsViewModel>(); ModelTerms = new List <TermViewModel>(); ModelPartyInfo = new PartyInfoViewModel(); ModelBillAddress = new BillingAddressViewModel(); ModelOtherDetails = new OtherDetailsViewModel(); }
public override void OnNavigatingFrom(NavigatingFromEventArgs e, Dictionary <string, object> viewModelState, bool suspending) { if (viewModelState == null || viewModelState.Count == 0) { return; } ShippingAddressViewModel.OnNavigatingFrom(e, viewModelState["ShippingViewModel"] as Dictionary <string, object>, suspending); BillingAddressViewModel.OnNavigatingFrom(e, viewModelState["BillingViewModel"] as Dictionary <string, object>, suspending); PaymentMethodViewModel.OnNavigatingFrom(e, viewModelState["PaymentMethodViewModel"] as Dictionary <string, object>, suspending); base.OnNavigatingFrom(e, viewModelState, suspending); }
public async Task <IActionResult> MyBillingAddress(BillingAddressViewModel model) { var user = await _userManager.GetUserAsync(User); user.BillingPropertyName = model.PropertyName; user.BillingStreetAdress = model.StreetAdress; user.BillingTownCity = model.TownCity; user.BillingZipPostcode = model.ZipPostcode; user.BillingCountry = model.Country; await _userManager.UpdateAsync(user); return(View(model)); }
public override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { if (await _accountService.VerifyUserAuthenticationAsync() == null) { return; } var addressId = e.Parameter as string; HeaderLabel = string.IsNullOrWhiteSpace(addressId) ? _resourceLoader.GetString("AddBillingAddressTitle") : _resourceLoader.GetString("EditBillingAddressTitle"); BillingAddressViewModel.OnNavigatedTo(e, viewModelState); }
public IActionResult BillingAddress() { Address billingAddress = _accountProvider.GetBillingAddress(UserId()); if (billingAddress == null) { throw new InvalidOperationException(nameof(billingAddress)); } BillingAddressViewModel model = new BillingAddressViewModel(); PrepareBillingAddressModel(ref model, billingAddress); return(View(model)); }
public async Task WHEN_Passing_Valid_Parameters_SHOULD_Update_BillingAddress_With_ShippingAddress() { //Arrange var shippingAddress = new Address { City = "Paris", FirstName = GetRandom.String(32), LastName = GetRandom.String(32), Line1 = GetRandom.String(32), Line2 = GetRandom.String(32), RegionCode = GetRandom.String(32), CountryCode = GetRandom.String(32), PhoneNumber = GetRandom.String(32) }; var cart = CreateBasicCart(); cart.Shipments.First().Address = shippingAddress; var service = CreateCheckoutService(cart); var updatedBillingAddress = new BillingAddressViewModel { UseShippingAddress = true, }; // Act var param = new UpdateCheckoutCartParam { GetCartParam = CreateGetCartParam(), UpdateValues = CreateUpdateOperation("BillingAddress", updatedBillingAddress), CurrentStep = GetRandom.Int(), IsGuest = GetRandom.Boolean() }; var processedCart = await service.UpdateCheckoutCartAsync(param); //Assert processedCart.Should().NotBeNull(); processedCart.Cart.Payment.BillingAddress.City.Should().Be("Paris"); processedCart.Cart.Payment.BillingAddress.FirstName.ShouldBeEquivalentTo(shippingAddress.FirstName); processedCart.Cart.Payment.BillingAddress.LastName.ShouldBeEquivalentTo(shippingAddress.LastName); processedCart.Cart.Payment.BillingAddress.Line1.ShouldBeEquivalentTo(shippingAddress.Line1); processedCart.Cart.Payment.BillingAddress.Line2.ShouldBeEquivalentTo(shippingAddress.Line2); processedCart.Cart.Payment.BillingAddress.RegionCode.ShouldBeEquivalentTo(shippingAddress.RegionCode); processedCart.Cart.Payment.BillingAddress.CountryCode.ShouldBeEquivalentTo(shippingAddress.CountryCode); processedCart.Cart.Payment.BillingAddress.PhoneNumber.ShouldBeEquivalentTo(shippingAddress.PhoneNumber); }
protected virtual Address CreateAddressFromViewModel(BillingAddressViewModel addressViewModel) { var address = new Address { AddressName = addressViewModel.AddressName, City = addressViewModel.City, CountryCode = addressViewModel.CountryCode, FirstName = addressViewModel.FirstName, LastName = addressViewModel.LastName, Line1 = addressViewModel.Line1, Line2 = addressViewModel.Line2, PhoneNumber = addressViewModel.PhoneNumber, PostalCode = addressViewModel.PostalCode, RegionCode = addressViewModel.RegionCode }; return(address); }
private void ValidateBillingAddressModel(ref BillingAddressViewModel model) { AddressOptions addressOptions = _accountProvider.GetAddressOptions(AddressOption.Delivery); if (addressOptions.HasFlag(AddressOptions.AddressLine1Mandatory) && String.IsNullOrEmpty(model.AddressLine1)) { ModelState.AddModelError(nameof(model.AddressLine1), Languages.LanguageStrings.AddressLine1Required); } if (addressOptions.HasFlag(AddressOptions.AddressLine2Mandatory) && String.IsNullOrEmpty(model.AddressLine2)) { ModelState.AddModelError(nameof(model.AddressLine2), Languages.LanguageStrings.AddressLine2Required); } if (addressOptions.HasFlag(AddressOptions.AddressLine3Mandatory) && String.IsNullOrEmpty(model.AddressLine3)) { ModelState.AddModelError(nameof(model.AddressLine3), Languages.LanguageStrings.AddressLine3Required); } if (addressOptions.HasFlag(AddressOptions.CityMandatory) && String.IsNullOrEmpty(model.City)) { ModelState.AddModelError(nameof(model.City), Languages.LanguageStrings.CityRequired); } if (addressOptions.HasFlag(AddressOptions.CountyMandatory) && String.IsNullOrEmpty(model.County)) { ModelState.AddModelError(nameof(model.County), Languages.LanguageStrings.CountyRequired); } if (addressOptions.HasFlag(AddressOptions.PostCodeMandatory) && String.IsNullOrEmpty(model.Postcode)) { ModelState.AddModelError(nameof(model.Postcode), Languages.LanguageStrings.PostcodeRequired); } if (addressOptions.HasFlag(AddressOptions.BusinessNameMandatory) && String.IsNullOrEmpty(model.BusinessName)) { ModelState.AddModelError(nameof(model.BusinessName), Languages.LanguageStrings.BusinessNameRequired); } }
private void ValidateBillingAddressModel(ref BillingAddressViewModel model) { AddressOptions addressOptions = _accountProvider.GetAddressOptions(); if (addressOptions.HasFlag(AddressOptions.AddressLine1Mandatory) && String.IsNullOrEmpty(model.AddressLine1)) { ModelState.AddModelError(nameof(model.AddressLine1), "Address line 1 is required"); } if (addressOptions.HasFlag(AddressOptions.AddressLine2Mandatory) && String.IsNullOrEmpty(model.AddressLine2)) { ModelState.AddModelError(nameof(model.AddressLine2), "Address line 2 is required"); } if (addressOptions.HasFlag(AddressOptions.AddressLine3Mandatory) && String.IsNullOrEmpty(model.AddressLine3)) { ModelState.AddModelError(nameof(model.AddressLine3), "Address line 3 is required"); } if (addressOptions.HasFlag(AddressOptions.CityMandatory) && String.IsNullOrEmpty(model.City)) { ModelState.AddModelError(nameof(model.City), "City is required"); } if (addressOptions.HasFlag(AddressOptions.CountyMandatory) && String.IsNullOrEmpty(model.County)) { ModelState.AddModelError(nameof(model.County), "County is required"); } if (addressOptions.HasFlag(AddressOptions.PostCodeMandatory) && String.IsNullOrEmpty(model.Postcode)) { ModelState.AddModelError(nameof(model.Postcode), "Postcode is required"); } if (addressOptions.HasFlag(AddressOptions.BusinessNameMandatory) && String.IsNullOrEmpty(model.BusinessName)) { ModelState.AddModelError(nameof(model.BusinessName), "Business Name is required"); } }
public override void OnNavigatingFrom(NavigatingFromEventArgs e, Dictionary <string, object> viewModelState, bool suspending) { BillingAddressViewModel.OnNavigatingFrom(e, viewModelState, suspending); }
/// <summary> /// Creates view model for checkout delivery step. /// </summary> /// <param name="customer">Filled customer details</param> /// <param name="billingAddress">Filled billing address</param> /// <param name="shippingOption">Selected shipping option</param> public DeliveryDetailsViewModel PrepareDeliveryDetailsViewModel(CustomerViewModel customer = null, BillingAddressViewModel billingAddress = null, ShippingOptionViewModel shippingOption = null) { var cart = mShoppingService.GetCurrentShoppingCart(); var countries = CreateCountryList(); var shippingOptions = CreateShippingOptionList(); customer = customer ?? new CustomerViewModel(cart.Customer); var addresses = (cart.Customer != null) ? mAddressRepository.GetByCustomerId(cart.Customer.CustomerID) : Enumerable.Empty <AddressInfo>(); var billingAddresses = new SelectList(addresses, nameof(AddressInfo.AddressID), nameof(AddressInfo.AddressName)); billingAddress = billingAddress ?? new BillingAddressViewModel(mShoppingService.GetBillingAddress(), countries, mCountryRepository, billingAddresses); shippingOption = shippingOption ?? new ShippingOptionViewModel(cart.ShippingOption, shippingOptions, cart.IsShippingNeeded); billingAddress.BillingAddressCountryStateSelector.Countries = billingAddress.BillingAddressCountryStateSelector.Countries ?? countries; billingAddress.BillingAddressSelector = billingAddress.BillingAddressSelector ?? new AddressSelectorViewModel { Addresses = billingAddresses }; shippingOption.ShippingOptions = shippingOptions; var viewModel = new DeliveryDetailsViewModel { Customer = customer, BillingAddress = billingAddress, ShippingOption = shippingOption }; return(viewModel); }
public override void OnNavigatedFrom(Dictionary <string, object> viewModelState, bool suspending) { BillingAddressViewModel.OnNavigatedFrom(viewModelState, suspending); }
private async Task ProcessFormAsync() { if (UseSameAddressAsShipping) { BillingAddressViewModel.Address = new Address { Id = Guid.NewGuid().ToString(), AddressType = AddressType.Billing, FirstName = ShippingAddressViewModel.Address.FirstName, MiddleInitial = ShippingAddressViewModel.Address.MiddleInitial, LastName = ShippingAddressViewModel.Address.LastName, StreetAddress = ShippingAddressViewModel.Address.StreetAddress, OptionalAddress = ShippingAddressViewModel.Address.OptionalAddress, City = ShippingAddressViewModel.Address.City, State = ShippingAddressViewModel.Address.State, ZipCode = ShippingAddressViewModel.Address.ZipCode, Phone = ShippingAddressViewModel.Address.Phone }; } try { await ShippingAddressViewModel.ProcessFormAsync(); await BillingAddressViewModel.ProcessFormAsync(); await PaymentMethodViewModel.ProcessFormAsync(); } catch (ModelValidationException) { // Handle validation exceptions when the order is created. } var user = _accountService.SignedInUser; var shoppingCart = await _shoppingCartRepository.GetShoppingCartAsync(); try { // Create an order with the values entered in the form await _orderRepository.CreateBasicOrderAsync(user.UserName, shoppingCart, ShippingAddressViewModel.Address, BillingAddressViewModel.Address, PaymentMethodViewModel.PaymentMethod); _navigationService.Navigate("CheckoutSummary", null); } catch (ModelValidationException mvex) { DisplayOrderErrorMessages(mvex.ValidationResult); if (_shippingAddressViewModel.Address.Errors.Errors.Count > 0) { IsShippingAddressInvalid = true; } if (_billingAddressViewModel.Address.Errors.Errors.Count > 0 && !UseSameAddressAsShipping) { IsBillingAddressInvalid = true; } if (_paymentMethodViewModel.PaymentMethod.Errors.Errors.Count > 0) { IsPaymentMethodInvalid = true; } } }
private void PrepareBillingAddressModel(ref BillingAddressViewModel model, in Address billingAddress)
protected virtual Task UpdateBillingAddress(Overture.ServiceModel.Orders.Cart cart, BillingAddressViewModel billingAddressViewModel) { if (billingAddressViewModel == null) { return(Task.FromResult(0)); } var payment = GetPayment(cart); if (payment == null) { return(Task.FromResult(0)); } if (billingAddressViewModel.UseShippingAddress) { var shipment = cart.Shipments.FirstOrDefault(); if (shipment?.Address == null) { return(Task.FromResult(0)); } payment.BillingAddress = shipment.Address.Clone(); } else { payment.BillingAddress = CreateAddressFromViewModel(billingAddressViewModel); } if (cart.Customer.Type == CustomerType.Guest) { cart.Customer.FirstName = payment.BillingAddress.FirstName; cart.Customer.LastName = payment.BillingAddress.LastName; cart.Customer.Phone = payment.BillingAddress.PhoneNumber; } return(Task.FromResult(0)); }