public override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { // Get latest shopping cart var shoppingCart = await _shoppingCartRepository.GetShoppingCartAsync(); _order = _orderRepository.CurrentOrder; _order.ShoppingCart = shoppingCart; // Populate the ShoppingCart items var shoppingCartItemVMs = _order.ShoppingCart.ShoppingCartItems.Select(item => new ShoppingCartItemViewModel(item, _resourceLoader)); ShoppingCartItemViewModels = new ReadOnlyCollection <ShoppingCartItemViewModel>(shoppingCartItemVMs.ToList()); // Populate the ShippingMethods and set the selected one var shippingMethods = await _shippingMethodService.GetShippingMethodsAsync(); ShippingMethods = new ReadOnlyCollection <ShippingMethod>(shippingMethods.ToList()); SelectedShippingMethod = _order.ShippingMethod != null?ShippingMethods.FirstOrDefault(c => c.Id == _order.ShippingMethod.Id) : null; // Update order's address and payment information _order.ShippingAddress = await _checkoutDataRepository.GetShippingAddressAsync(_order.ShippingAddress.Id); _order.BillingAddress = await _checkoutDataRepository.GetBillingAddressAsync(_order.BillingAddress.Id); _order.PaymentMethod = await _checkoutDataRepository.GetPaymentMethodAsync(_order.PaymentMethod.Id); // Populate the CheckoutData items (Addresses & payment information) CheckoutDataViewModels = new ObservableCollection <CheckoutDataViewModel> { CreateCheckoutData(_order.ShippingAddress, Constants.ShippingAddress), CreateCheckoutData(_order.BillingAddress, Constants.BillingAddress), CreateCheckoutData(_order.PaymentMethod) }; base.OnNavigatedTo(e, viewModelState); if (e.NavigationMode == NavigationMode.Refresh) { // Restore the selected CheckoutData manually string selectedCheckoutData = RetrieveEntityStateValue <string>("selectedCheckoutData", viewModelState); if (!string.IsNullOrWhiteSpace(selectedCheckoutData)) { SelectedCheckoutData = CheckoutDataViewModels.FirstOrDefault(c => c.EntityId == selectedCheckoutData); } } }
public override async void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, System.Collections.Generic.Dictionary <string, object> viewModelState) { if (await _accountService.VerifyUserAuthenticationAsync() == null) { return; } var paymentMethodId = navigationParameter as string; HeaderLabel = string.IsNullOrWhiteSpace(paymentMethodId) ? _resourceLoader.GetString("AddPaymentMethodTitle") : _resourceLoader.GetString("EditPaymentMethodTitle"); if (!string.IsNullOrWhiteSpace(paymentMethodId)) { // Update PaymentMethod information PaymentMethodViewModel.PaymentMethod = await _checkoutDataRepository.GetPaymentMethodAsync(paymentMethodId); } PaymentMethodViewModel.OnNavigatedTo(navigationParameter, navigationMode, viewModelState); }