Ejemplo n.º 1
0
 public void AddItem(Product product, int quantity)
 {
     CartLine line = lineCollection
         .FirstOrDefault(p => p.Product.ProductID == product.ProductID);
     if (line == null)
     {
         var cartLine = new CartLine();
         cartLine.Product = product;
         cartLine.Quantity = quantity;
         lineCollection.Add(cartLine);
     }
     else
     {
         line.Quantity += quantity;
     }
 }
Ejemplo n.º 2
0
 public void AddItem(Product product, int quantity)
 {
     CartLine line = _lineCollection.Where(a => a.Product.ProductID == product.ProductID).FirstOrDefault();
     if (line == null)
     {
         var cartline = new CartLine()
         {
             Product = product,
             Quantity = quantity
         };
         _lineCollection.Add(cartline);
     }
     else
     {
         line.Quantity += quantity;
     }
 }
Ejemplo n.º 3
0
        public void AddItem(Product product, int quantity)
        {
            //check for record
            CartLine line = lineCollection.Where
                                (p => p.Product.ProductID == product.ProductID)
                            .FirstOrDefault();

            //if record is null proceed to adding new record otherwise add quantity only
            if (line == null)
            {
                //linq query
                lineCollection.Add(
                    new CartLine
                {
                    Product = product, Quantity = quantity
                }
                    );
            }
            else
            {
                line.Quantity += quantity;
            }
        }
Ejemplo n.º 4
0
        public void MinusItem(Product product)
        {
            CartLine line = lineCollection
                            .Where(p => p.Product.ProductID == product.ProductID)
                            .FirstOrDefault();

            if (line != null)
            {
                var quant = line.Quantity;

                if (quant == 1)
                {
                    RemoveLine(line.Product);
                }
                else
                {
                    line.Quantity -= 1;
                }
            }
            else
            {
                throw new ArgumentException("incorrect product for MinusItem");
            }
        }