Пример #1
0
        public CartViewModel GetCart(string id = "")
        {
            CartViewModel model = new CartViewModel();
            //Call the method GetCartFromDataStore
            List <ProductViewModel> data = GetCartFromDataStore();

            model.Cart = data;

            if (!string.IsNullOrEmpty(id))
            //Called the method GetSelectedProduct with parameter id and assign the return object to the AddedProduct
            {
                var pv = GetSelectedProduct(id);
                model.AddedProduct = pv;
            }
            return(model);
        }
Пример #2
0
        public CartViewModel GetCart(string id = "")
        {
            CartViewModel model = new CartViewModel();

            //Call the method GetCartFromDataStore
            model.Cart = GetCartFromDataStore();

            if (!string.IsNullOrEmpty(id))
            {
                //Called the method GetSelectedProduct with parameter id and assign the return object to the AddedProduct
                model.AddedProduct = this.GetSelectedProduct(id);
            }


            return(model);
        }
Пример #3
0
 public void AddToCart(CartViewModel model)
 {
     if (model.AddedProduct.ProductID != null)
     {
         //Get the product id of the added product
         string id = model.AddedProduct.ProductID;
         //Find the product in the car that matches the id using lambda expression.
         ProductViewModel inCart = model.Cart.Find(x => x.ProductID == id);
         if (inCart == null)
         {
             //Call the method AddItemToDataStore
             AddItemToDataStore(model);
         }
         else
         {
             //Increase the Quantity by the quantity of the added product
             inCart.Quantity += model.AddedProduct.Quantity;
         }
     }
 }
 public void AddToCart(CartViewModel model)
 {
     if (model.AddedProduct.ProductID != null)
     {
         //Get the product id of the added product
         var pID = model.AddedProduct.ProductID;
         //Find the product in the car that matches the id using lambda expression.
         var inCart = GetCartFromDataStore().Where(p => p.ProductID.Equals(pID)).FirstOrDefault();
         if (inCart == null)
         //Call the method AddItemToDataStore
         {
             AddItemToDataStore(model);
         }
         else
         {
             //Increase the Quantity by the quantity of the added product
             inCart.Quantity += model.AddedProduct.Quantity;
         }
     }
 }
Пример #5
0
 public void AddToCart(CartViewModel model)
 {
     if (model.AddedProduct.ProductID != null)
     {
         //Get the product id of the added product
         var pid = model.AddedProduct.ProductID;
         //Find the product in the cart that matches the id using lambda expression.
         var inCart = model.Cart.Where(s => s.ProductID == pid).SingleOrDefault();
         if (inCart == null)
         {
             //Call the method AddItemToDataStore
             AddItemToDataStore(model);
         }
         else
         {
             //Increase the Quantity by the quantity of the added product
             inCart.Quantity += model.AddedProduct.Quantity;
         }
     }
 }
Пример #6
0
 public void AddToCart(CartViewModel model)
 {
     if (model.AddedProduct.ProductID != null)
     {
         //Get the product id of the added product
         var id = model.AddedProduct.ProductID;
         //Find the product in the cart that matches the id using lambda expression.
         var inCart = model.Cart.FirstOrDefault(p => p.ProductID == id);
         if (inCart == null)
         {
             //Call the method AddItemToDataStore
             AddItemToDataStore(model);
         }
         else
         {
             //Increase the Quantity by the quantity of the added product
             model.AddedProduct.Quantity += inCart.Quantity;         // !! TO-CHECK
         }
     }
 }
Пример #7
0
 private void AddItemToDataStore(CartViewModel model)
 {   //Add the AddedProduct to the cart
     model.Cart.Add(model.AddedProduct);
 }
 private void AddItemToDataStore(CartViewModel model)
 {   //Add the AddedProduct to the cart
     model.Cart.Add(model.AddedProduct);
     HttpContext.Current.Session["cart"] = model.Cart;
 }
Пример #9
0
        private void AddItemToDataStore(CartViewModel model)
        {   //Add the AddedProduct to the cart
            List <ProductViewModel> data = GetCartFromDataStore();

            data.Add(model.AddedProduct);
        }