Beispiel #1
0
        public ActionResult Edit(Product product, HttpPostedFileBase ProductImage)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            _productRepository.Update(product);
            _productRepository.Save();

            if (ProductImage == null || ProductImage.ContentLength <= 0)
            {
                return(RedirectToAction("Index"));
            }
            var img = new ProductImage()
            {
                ImageName   = Path.GetFileName(ProductImage.FileName),
                ContentType = ProductImage.ContentType
            };

            using (var reader = new BinaryReader(ProductImage.InputStream))
            {
                img.Content   = reader.ReadBytes(ProductImage.ContentLength);
                img.ProductId = product.ProductId;
            }
            var existingImage = _productRepository.GetById(product.ProductId).ProductImages;

            if (existingImage != null && existingImage.Count > 0)
            {
                existingImage.ForEach(x => _productImagerepository.Delete(x.ProductImageId));
            }
            _productImagerepository.Insert(img);
            _productImagerepository.Save();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public void Insert(ProductImage item)
 {
     _repository.Insert(item);
 }