示例#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;
            }
        }
        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);
 }
        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);
 }