Beispiel #1
0
        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));
        }