Esempio n. 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"));
        }
 public void Delete(int productId, int imageId)
 {
     _productImageRepository.Delete(new ProductImage
     {
         ProductId = productId,
         ImageId   = imageId
     });
 }
Esempio n. 3
0
 public bool DeleteImages(List <ProductImage> productImages)
 {
     foreach (var item in productImages)
     {
         _productImageRepository.Delete(item);
     }
     return(true);
 }
Esempio n. 4
0
        public void DeleteImageAndFolder(string imageId, string folderName)
        {
            ProductImage productImage = _productImageRepository.Get(imageId);

            _productImageRepository.Delete(productImage);
            _productImageRepository.Save(requestContext);
            string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "imageUpload");

            Directory.Delete(Path.Combine(uploadsFolder, folderName), true);
        }
        public JsonResult RemoveProductImage(string image, int id)
        {
            try
            {
                var path = AppDomain.CurrentDomain.BaseDirectory + image;
                _productImageRepository.Delete(id, image);
                System.IO.File.Delete(path);
            }
            catch
            {
                return(Json(new { status = "fail" }, "text/html"));
            }

            return(Json(new { status = "success" }, "text/html"));
        }
Esempio n. 6
0
        public async Task <IActionResult> DeleteImage(long Id)
        {
            var _image = await _imageRepository.GetSingleAsync(x => x.Id == Id);

            if (_image == null)
            {
                return(new NotFoundResult());
            }
            var url = _image.ImageUrl;

            _imageRepository.Delete(_image);
            await _imageRepository.Commit();

            Uri u         = new Uri(url);
            var path      = u.LocalPath.Replace("/", "\\");
            var localPath = string.Format("{0}{1}", _environment.WebRootPath, path);

            FileInfo file = new FileInfo(localPath);
            await Task.Factory.StartNew(() => file.Delete());

            return(new NoContentResult());
        }
Esempio n. 7
0
 public void Delete(int id)
 {
     _productImageRepository.Delete(id);
 }
Esempio n. 8
0
 public void Delete(ProductImage entity)
 {
     repo.Delete(entity);
 }
Esempio n. 9
0
 public ProductImage Delete(int Id)
 {
     return(ProductImageRepo.Delete(Id));
 }
 public void Delete(ProductImage ProductImage)
 {
     ProductImageRepository.Delete(ProductImage);
 }
Esempio n. 11
0
 public void Delete(int id)
 {
     _repository.Delete(id);
 }