Пример #1
0
        public void AddItem(Product product, int quantity) {
            CartLine line = lineCollection
                .Where(p => p.Product.ProductID == product.ProductID)
                .FirstOrDefault();

            if (line == null) {
                lineCollection.Add(new CartLine { Product = product, Quantity = quantity });
            } else {
                line.Quantity += quantity;
            }
        }
Пример #2
0
 public void DeleteProduct(Product product) {
     //Удаляем связанные с Product Pictures
     if(product.Pictures.Count != 0)
     { 
         //Удаляем картинки
         var delpic = from d in product.Pictures
                      select d;
         for (int i = 0; i < product.Pictures.Count; i++ )
         {
             var currentpic = delpic.First();
             _context.Pictures.Remove(currentpic);//DeletePicture(currentpic);
         }
     }
     _context.Products.Remove(product);
     _context.SaveChanges();
 }
Пример #3
0
        public void SaveProduct(Product product)
        {
            Product prod;
            //Внесем дату занесения/изменения
            product.EnrollmentDate = DateTime.Now;

            if (product.ProductID == 0) {
                _context.Products.Add(product);
            }
            else //Извлекаем и модифицируем
            {
                prod = _context.Products.Single(x => x.ProductID == product.ProductID);
                prod.Name = product.Name;
                prod.Description = product.Description;
                prod.Price = product.Price;
                prod.EnrollmentDate = product.EnrollmentDate;
                prod.SubcategoryId = product.SubcategoryId;
                prod.CategoryId = product.CategoryId;
            }
            _context.SaveChanges();
        }
Пример #4
0
 public void RemoveLine(Product product) {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }