private void CalculatePrice() { var totalPrice = 0.0; foreach (var parcel in _parcels.Values) { parcel.SetShippingPrice(ShippingRatesByCode); PriceDetails.AppendFormat($"{parcel.Name} parcel price : {parcel.TotalPrice}.\n"); TotalPrice += parcel.TotalPrice; } ICalculateDiscounts orderDiscount = new object() as ICalculateDiscounts; Discounts = CalculateDiscounts(orderDiscount); TotalDiscount = Discounts.Sum(discount => discount.Value); TotalPrice -= TotalDiscount; if (Speedy) { SpeedyShippingPrice = totalPrice; TotalPrice += SpeedyShippingPrice; } }
public ShippingOrder(List <Parcel> parcels, Dictionary <ParcelCode, ShippingRate> shippingRatesByCode, bool speedy = false) { Parcels = parcels; foreach (var parcel in parcels) { parcel.SetShippingPrice(shippingRatesByCode); TotalPrice += parcel.TotalPrice; } Discounts = CalculateDiscounts(); TotalDiscount = Discounts.Sum(discount => discount.Value); TotalPrice -= TotalDiscount; if (speedy) { SpeedyShippingPrice = TotalPrice; TotalPrice += SpeedyShippingPrice; } }