public Product Remove(Product obj) { if (obj != null) { var retrivedBook = _efDbContext.Products.Find(obj.ProductId); return Remove(retrivedBook.ProductId); } throw new ArgumentNullException("obj","The obj can't be null"); }
public void AddItem(Product product, int quantity) { CartLine cartline = lineCollection.FirstOrDefault(x => x.Product.ProductId == product.ProductId); if (cartline == null) { lineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } else { cartline.Quantity += quantity; } }
public ActionResult Edit(Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { product.ImageMimeType = image.ContentType; product.ImageData = new byte[image.ContentLength]; image.InputStream.Read(product.ImageData, 0, image.ContentLength); } _productRepository.AddOrUpdate(product); TempData["message"] = string.Format("{0} has been saved successfully", product.Title); return RedirectToAction("Index"); } return View(product); }
public Product AddOrUpdate(Product entity) { Product product; if (entity.ProductId == 0) { product = _efDbContext.Products.Add(entity); } else { product = _efDbContext.Products.Find(entity.ProductId); product.Code = entity.Code; product.Title = entity.Title; product.Description = entity.Description; product.Category = entity.Category; product.Brand = entity.Brand; product.Brand = entity.Brand; product.RewardPoints = entity.RewardPoints; product.Price = entity.Price; } Save(); return product; }
public Product UpdateProduct(Product product) { return _productRepository.AddOrUpdate(product); }
public void RemoveItem(Product product) { lineCollection.RemoveAll(l => l.Product.ProductId == product.ProductId); }
public ActionResult Edit(Product product, IFormFile image) { if (ModelState.IsValid) { if (image != null) { FileDetails fileDetails; using (var reader = new StreamReader(image.OpenReadStream())) { var fileContent = reader.ReadToEnd(); var parsedContentDisposition = ContentDispositionHeaderValue.Parse(image.ContentDisposition); fileDetails = new FileDetails { Filename = parsedContentDisposition.FileName, Content = fileContent, ContentType=image.ContentType }; } //product.ImageMimeType = image.ContentType; product.ImageData = fileDetails.Content; } _productRepository.AddOrUpdate(product); TempData["message"] = string.Format("{0} has been saved successfully", product.Title); return RedirectToAction("Index"); } return View(product); }