コード例 #1
0
        private static IReadOnlyList <PaymentShippingOption> CreateShippingOptions(ShoppingCart shoppingCart)
        {
            List <PaymentShippingOption> paymentShippingOptions = new List <PaymentShippingOption>();

            ShippingType selectedShippingType = shoppingCart.ShippingType;
            IReadOnlyDictionary <ShippingType, ShoppingCartCostsSummary> cartShippingOptions = shoppingCart.CalculateShippingOptions();

            ShoppingCartCostsSummary costsOfSelectedShipping = cartShippingOptions[selectedShippingType];

            foreach (var kvp in cartShippingOptions)
            {
                ShippingType             shippingType = kvp.Key;
                ShoppingCartCostsSummary costs        = kvp.Value;

                PaymentShippingOption shippingOption = new PaymentShippingOption(
                    label: ShippingTypeStringUtilities.CreateShippingOptionTitle(shippingType, costs, costsOfSelectedShipping),
                    selected: (shippingType == selectedShippingType),
                    tag: shippingType.ToString(),
                    amount: CreateCurrencyAmount(costs.Shipping));

                paymentShippingOptions.Add(shippingOption);
            }

            return(paymentShippingOptions);
        }
        /// <summary>
        /// Updates the strings that display the cost summary (e.g. sub-total, tax, etc.) of the shopping cart.
        /// </summary>
        private void UpdateCostsSummaryStrings()
        {
            ShoppingCartCostsSummary costsSummary = this.ShoppingCart.CostsSummary;

            // Update values.
            this.SubtotalString          = PriceStringUtilities.CreatePriceString(costsSummary.ItemsSubtotal);
            this.EstimatedShippingString = PriceStringUtilities.CreatePriceString(costsSummary.Shipping);
            this.ShippingTypeString      = ShippingTypeStringUtilities.GetFriendlyNameOfShippingType(this.ShoppingCart.ShippingType);
            this.EstimatedTaxString      = PriceStringUtilities.CreatePriceString(costsSummary.TotalTax);
            this.TotalCostString         = PriceStringUtilities.CreatePriceString(costsSummary.Total);

            // Raise all the 'PropertyChanged' events.
            this.RaisePropertyChanged(nameof(this.SubtotalString));
            this.RaisePropertyChanged(nameof(this.EstimatedShippingString));
            this.RaisePropertyChanged(nameof(this.ShippingTypeString));
            this.RaisePropertyChanged(nameof(this.EstimatedTaxString));
            this.RaisePropertyChanged(nameof(this.TotalCostString));
        }