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

            if (line == null)
            {
                lineCollection.Add(new CartLine
                {
                    Product = product,
                    Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }
Пример #2
0
        public ActionResult CreateProduct(Product product, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    product.PhotoMimeType = photo.ContentType;
                    product.ProductPhoto = new byte[photo.ContentLength];
                    photo.InputStream.Read(product.ProductPhoto, 0, photo.ContentLength);
                }

                _productService.Insert(product);
                TempData["message"] = string.Format("{0} has been created", product.Name);

                return Json( new { success = true });
            }

            ViewBag.Id = new SelectList(_categoryService.GetAll().ToList(), "Id", "Name");

            return PartialView("_CreateProduct", product);
        }
Пример #3
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.Id == product.Id);
 }
Пример #4
0
        public ActionResult EditProduct(Product product, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    product.PhotoMimeType = photo.ContentType;
                    product.ProductPhoto = new byte[photo.ContentLength];
                    photo.InputStream.Read(product.ProductPhoto, 0, photo.ContentLength);
                }

                _productService.Update(product);
                TempData["message"] = string.Format("{0} has been saved", product.Name);
                return RedirectToAction("Index");
            }

            return View(product);
        }
Пример #5
0
 public void Update(Product model)
 {
     if (model == null)
         throw new ArgumentNullException("product");
     productRepository.Update(model);
 }
Пример #6
0
 public void Insert(Product model)
 {
     if (model == null)
         throw new ArgumentNullException("product");
     productRepository.Insert(model);
 }