예제 #1
0
        public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
        {
            //List<RegionShippingCost> listPerRegionCosts = PerRegionCosts.ToList();
            //bool containsCountryRegion = listPerRegionCosts.Exists(x=>x.DestinationRegion==lineItem.DeliveryRegion);
            ////bool checkListContains=(from c in PerRegionCosts where c.DestinationRegion.Contains(lineItem.DeliveryRegion));
            //if (containsCountryRegion)
            //    return
            //    (from c in PerRegionCosts
            //     where c.DestinationRegion == lineItem.DeliveryRegion
            //     select c.Amount).Single();

            //else
            //{
            //    lineItem.DeliveryRegion = RegionShippingCost.Regions.RestOfTheWorld;
            //    return
            //    (from c in PerRegionCosts
            //     where c.DestinationRegion == lineItem.DeliveryRegion
            //     select c.Amount).Single();
            //}

            return
                ((from c in PerRegionCosts
                  where c.DestinationRegion == lineItem.DeliveryRegion
                  select c.Amount).Single());
        }
예제 #2
0
        public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
        {
            decimal         result = 0m;
            List <LineItem> foundItemList;

            isMultipleShipping = false;

            #region Multiple rule: "if there is at least one other item in the basket with the same Shipping Option and the same Supplier and Region"

            foundItemList = basket.LineItems.FindAll(o => o.Shipping is PerRegionDiscountShipping &&
                                                     o.SupplierId == lineItem.SupplierId &&
                                                     o.DeliveryRegion == lineItem.DeliveryRegion);

            // "at least one other item" && it should start to get a discount at the second item.
            if (foundItemList.Count >= 2 && lineItem.Id != foundItemList[0].Id)
            {
                isMultipleShipping = true;
            }
            #endregion

            // Get Amount by mapping XML
            result = (from c in PerRegionCosts
                      where c.DestinationRegion == lineItem.DeliveryRegion
                      select c.Amount).Single();

            // Special rule: Get discount
            result = isMultipleShipping ? (result - SpecialRule_deducte) : result;

            return(result);
        }
 public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
 {
     return
         ((from c in PerRegionCosts
           where c.DestinationRegion == lineItem.DeliveryRegion
           select c.Amount).Single());
 }
        public void Given()
        {
            _basket = new Basket.Basket();

            _product = new Product(new ProductTitle("Product A", 15m, new Brand(), new Category(), new ProductColour(), null), new ProductSize());

            _basket.Add(_product);
        }
예제 #5
0
 /// <summary>
 /// Prints the Contents and totals of a given basket
 /// </summary>
 /// <param name="basket">The basket to be printed</param>
 public static void PrintBasket(Basket.Basket basket)
 {
     foreach (var item in basket.Items)
     {
         Console.WriteLine("{0} {1}: {2}", item.Value.Count, item.Value.Item.ProductName, Math.Round(item.Value.Count * (item.Value.Item.ImportTaxes + item.Value.Item.VatTaxes + item.Value.Item.PriceSalesExclusive), 2));
     }
     Console.WriteLine("Sales Taxes: {0}", basket.Taxes);
     Console.WriteLine("Total: {0}", basket.Taxes + basket.Subtotal);
     Console.WriteLine();
     Console.WriteLine();
 }
        /// <summary>
        /// Get amount for the same region shipping
        /// If there is at least one other item in the basket with the same Shipping Option and the same Supplier and Region, 'ReduceRate' should be deducted from the shipping.
        /// </summary>
        /// <param name="lineItem">current line item to get amount</param>
        /// <param name="basket">store all line items</param>
        /// <returns>the amount of current line item</returns>
        public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
        {
            //At least one other item in the basket with the same Shipping Option and the same Supplier and Region
            var anySameShipping = basket.LineItems
                                  .Any(item => item.Id != lineItem.Id &&
                                       item.Shipping is SameRegionShipping &&
                                       item.SupplierId == lineItem.SupplierId &&
                                       item.DeliveryRegion == lineItem.DeliveryRegion);

            return
                ((from c in PerRegionCosts
                  where c.DestinationRegion == lineItem.DeliveryRegion
                  select c.Amount).Single() - (anySameShipping ? ReduceRate : 0));
        }
예제 #7
0
        public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
        {
            var moreItemsWithSameConds = basket.LineItems
                                         .Any(
                element => element.Id != lineItem.Id && element.Shipping is NewRegionShipping &&
                element.SupplierId == lineItem.SupplierId &&
                element.DeliveryRegion == lineItem.DeliveryRegion);
            var amount =
                (from c in PerRegionCosts
                 where c.DestinationRegion == lineItem.DeliveryRegion
                 select c.Amount).Single();
            var discount = (moreItemsWithSameConds ? Discount : 0);

            return(amount - discount);
        }
        public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
        {
            int counter = 0;

            foreach (LineItem l in basket.LineItems)
            {
                if (l.Shipping is DiscountShipping &&
                    l.SupplierId == lineItem.SupplierId &&
                    l.DeliveryRegion.Equals(lineItem.DeliveryRegion))
                {
                    counter++;
                }
            }

            return(base.GetAmount(lineItem, basket) - (counter > 1 ? .5m : 0));
        }
        public void Given()
        {
            _basket = new Basket.Basket();

            var productTitle = new ProductTitle();

            productTitle.Name     = "Product A";
            productTitle.Price    = 15.00m;
            productTitle.Brand    = new Brand();
            productTitle.Category = new Category();
            productTitle.Color    = new ProductColor();
            productTitle.Products = null;

            _product       = new Product();
            _product.Title = productTitle;
            _product.Size  = new ProductSize();

            _basket.Add(_product);
        }
예제 #10
0
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return(string.Format("Shipping to {0}", lineItem.DeliveryRegion));
 }
예제 #11
0
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return("Flat rate shipping");
 }
예제 #12
0
 public override decimal GetAmount(LineItem lineItem, Basket.Basket basket)
 {
     return(FlatRate);
 }
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return($"Shipping to {lineItem.DeliveryRegion}");
 }
예제 #14
0
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return(string.Format("Shipping to {0} {1}"
                          , lineItem.DeliveryRegion
                          , isMultipleShipping ? "with discount" : ""));
 }
예제 #15
0
 public abstract string GetDescription(LineItem lineItem, Basket.Basket basket);
예제 #16
0
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return(string.Format("New choice for Shipping "));
 }
 public override string GetDescription(LineItem lineItem, Basket.Basket basket)
 {
     return(String.Format("DiscountShipping {0} - {1} - {2}", lineItem.SupplierId, lineItem.DeliveryRegion, lineItem.ShippingDescription));
 }
        public void Given()
        {
            _basket = new Basket.Basket();

            _basket.SetDeliveryOption(null);            
        }
예제 #19
0
        public void AddBasket(Basket.Basket basket)
        {
            basket.ThrowExceptionIfInvalid();

            _basket = basket;
        }
예제 #20
0
 internal CheckoutCommand(Basket.Basket basket, Warehouse.Warehouse warehouse)
 {
     this.basket    = basket;
     this.warehouse = warehouse;
 }
예제 #21
0
 public void Given()
 {
     _basket = new Basket.Basket();
 }
예제 #22
0
 public void Given()
 {
     _basket = new Basket.Basket();
     _basket.SetDeliveryOption(null);
 }
예제 #23
0
 public abstract decimal GetAmount(LineItem lineItem, Basket.Basket basket);
 public void Given()
 {
     _basket = new Basket.Basket();            
 }