Beispiel #1
0
        /// <summary>
        /// Adds view model of cartline to List
        /// </summary>
        /// <param name="productId">Id of product</param>
        /// <param name="quantity">Quantity of product</param>
        public void AddCartLineViewModel(int productId, int quantity)
        {
            Product           product           = businessLayer.Products.Where(p => p.ProductId == productId).First();
            CartLineViewModel cartLineViewModel = CartLineViewModels.Where(c => c.ProductId == productId).FirstOrDefault();

            //If there is no such cartline in List, creates new
            if (cartLineViewModel == null)
            {
                CartLineViewModel newCartLineViewModel = new CartLineViewModel()
                {
                    ProductId = productId, Product = product, Quantity = quantity
                };
                CartLineViewModels.Add(newCartLineViewModel);
            }
            //If there is such cartline in List, adds to its quantity
            else
            {
                cartLineViewModel.Quantity += quantity;
            }
        }
Beispiel #2
0
 public void Clear()
 {
     CartLineViewModels.Clear();
 }
Beispiel #3
0
 public void RemoveCartLineViewModel(int productId)
 {
     CartLineViewModels.RemoveAll(c => c.ProductId == productId);
 }