コード例 #1
0
ファイル: Сart.cs プロジェクト: VadimTeslya/OnlineStore
        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
ファイル: Сart.cs プロジェクト: VadimTeslya/OnlineStore
 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);
 }