public IActionResult UpdateImage(string ImageName, string ModuleName, int RowId) { var response = new OperationResponse <ProductImages>(); try { string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; if (Request.Form.Files.Count > 0) { var file = Request.Form.Files[0]; var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), OriginalImagePath); var fullPath = Path.Combine(pathToSave, ImageName); if (System.IO.File.Exists(fullPath)) { ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, ImageName); } else { int MaxId = _productImageService.GetMaxProductImageId(); var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); // Update Image in Module as well _productImageService.UpdateImage(request.RowId, ModuleName, RowId); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in UpdateImage ==>" + exception.StackTrace); } return(new JsonResult(response)); }
public IActionResult UploadMultipleFiles(int ProductId) { var response = new OperationResponse <ProductImages>(); try { if (Request.Form.ContainsKey("ProductId")) { ProductId = Convert.ToInt32(Request.Form["ProductId"].ToString()); } if (Request.Form.Files.Count > 0) { foreach (var item in Request.Form.Files) { int MaxId = _productImageService.GetMaxProductImageId(); var file = item; string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); ProductImageProduct request2 = new ProductImageProduct(); request2.ProductId = Convert.ToInt32(ProductId); request2.ProductImageId = response.Data.RowId; _productImageService.AddProductImage_Product(request2); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); } return(new JsonResult(response)); }
public IActionResult UploadMultipleFiles(int ProductId) { var response = new OperationResponse <ProductImages>(); try { if (Request.Form.Files.Count > 0) { foreach (var item in Request.Form.Files) { int MaxId = _productImageService.GetMaxProductImageId(); var file = item; string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); //var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), "Resources"); //var fullPath = Path.Combine(pathToSave, fileName); //using (var stream = new FileStream(fullPath, FileMode.Create)) //{ // file.CopyTo(stream); //} ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in AddProductCategory ==>" + exception.StackTrace); } return(new JsonResult(response)); }
public IActionResult Upload() { var response = new OperationResponse <ProductImages>(); try { if (Request.Form.Files.Count > 0) { int MaxId = _productImageService.GetMaxProductImageId(); var file = Request.Form.Files[0]; string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); } else { response.Messages = new List <string>(); response.Messages.Insert(0, @"Please upload logo."); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in AddProductCategory ==>" + exception.StackTrace); } return(new JsonResult(response)); }