예제 #1
0
 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");
 }
예제 #2
0
 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;
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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;
        }
예제 #5
0
 public Product UpdateProduct(Product product)
 {
     return _productRepository.AddOrUpdate(product);
 }
예제 #6
0
 public void RemoveItem(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductId == product.ProductId);
 }
예제 #7
-4
        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);
        }