public string SaveCroppedImage([FromBody] ImageInfo objImageInfo)
        {
            string filePath = string.Empty;

            objImageInfo = ParseImagePath(objImageInfo);
            string basePath = MediaHelper.tempThumbPath + "/" + objImageInfo.ImagePath;

            MediaHelper.SaveBase64Image(basePath, objImageInfo.ImageName, objImageInfo.Image64Bit.Replace("data:image/jpeg;base64,", ""));
            string serverRootPath = MediaHelper.serverRootPath; //HttpContext.Current.Server.MapPath(@"~\").ToLower();

            filePath = objImageInfo.ImageFullPath;              //objImageInfo.ImagePath + "/" + objImageInfo.ImageName;
            basePath = serverRootPath + basePath + "/" + objImageInfo.ImageName;
            //PictureManager.CreateThmnail(basePath, 1920, serverRootPath + MediaHelper.originalThumbPath + filePath);
            //PictureManager.CreateThmnail(basePath, 1320, serverRootPath + MediaHelper.largeThumbPath + filePath);
            //PictureManager.CreateThmnail(basePath, 720, serverRootPath + MediaHelper.mediumThumbPath + filePath);
            //PictureManager.CreateThmnail(basePath, 320, serverRootPath + filePath);
            ImageOptimize objOptimizeImage = new ImageOptimize();

            objOptimizeImage.OptimizeImage(_hostingEnvironment.WebRootPath, basePath, "Media/", objImageInfo.ImageName, System.IO.Path.GetExtension(objImageInfo.ImageName).Replace(".", ""));

            return(filePath);
        }
        public JsonResult FileUpload(IFormFile files, string fileextension, string rootPath, string quality, string type)
        {
            string retMsg = "0###fail";

            try
            {
                bool   isValidFile     = false;
                string validExtension  = string.Empty;
                string retFilePath     = string.Empty;
                string dirBaseLocation = string.Empty;
                string originalPath    = string.Empty;
                string thumbLargePath  = string.Empty;
                string thumbMediumPath = string.Empty;
                string thumbSmallPath  = string.Empty;
                string strBaseLocation = rootPath;


                string filename    = string.Empty;
                string newFileName = string.Empty;
                //  HttpRequest Request = HttpContext.Current.Request;
                string   fileExt         = fileextension.ToString();
                string[] allowExtensions = fileExt.Split(',');
                long     encodeQuality   = 10L;
                if (quality != null && quality.ToString().Length > 0)
                {
                    long.TryParse(quality, out encodeQuality);
                }

                if (files != null)
                {
                    MediaSettingKeys       objsettingInfo = new MediaSettingKeys();
                    MediaSettingController objController  = new MediaSettingController();
                    objsettingInfo = objController.GetMediaSettingKeyValue().Result;

                    if (objsettingInfo != null)
                    {
                        string ext = string.Empty;
                        switch (type)
                        {
                        case "image":
                            ext = objsettingInfo.ImageExtension;
                            break;

                        case "video":
                            ext = objsettingInfo.VideoExtension;
                            break;

                        case "document":
                            ext = objsettingInfo.DocumentExtension;
                            break;

                        default:
                            ext = objsettingInfo.ImageExtension + "," + objsettingInfo.VideoExtension + "," + objsettingInfo.DocumentExtension;
                            break;
                        }
                        allowExtensions = ext.Split(',');
                        if (string.IsNullOrEmpty(fileExt))
                        {
                            fileExt = ext;
                        }
                    }
                    string extension = GetExtension(files.FileName.ToLower()).ToLower();
                    if (IsValidExtension(allowExtensions, extension))
                    {
                        string[] myExtensions = fileExt.Split(',');
                        if (IsValidExtension(myExtensions, extension))
                        {
                            isValidFile = true;
                            retMsg      = "0###Valid file Extension";
                        }
                        else
                        {
                            isValidFile = false;
                            retMsg      = "0###Not valid file Extension";
                        }
                    }
                    else
                    {
                        isValidFile = false;
                        retMsg      = "0###Not valid file Extension";
                    }
                    if (isValidFile)
                    {
                        filename = Path.GetFileName(files.FileName.Replace(" ", "_"));

                        originalPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.originalThumbPath, strBaseLocation);
                        string tempPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.tempThumbPath, strBaseLocation);
                        thumbLargePath  = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.largeThumbPath, strBaseLocation);
                        thumbMediumPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.mediumThumbPath, strBaseLocation);
                        string baseLocationPath = Path.Combine(_hostingEnvironment.WebRootPath, strBaseLocation);
                        newFileName = MediaHelper.NewFileName(filename.ToLower(), baseLocationPath);

                        string screenshotPath = string.Empty;
                        if (!Directory.Exists(originalPath))
                        {
                            Directory.CreateDirectory(originalPath);
                        }
                        if (!Directory.Exists(thumbLargePath))
                        {
                            Directory.CreateDirectory(thumbLargePath);
                        }
                        if (!Directory.Exists(thumbMediumPath))
                        {
                            Directory.CreateDirectory(thumbMediumPath);
                        }
                        if (!Directory.Exists(baseLocationPath))
                        {
                            Directory.CreateDirectory(baseLocationPath);
                        }
                        if (!Directory.Exists(tempPath))
                        {
                            Directory.CreateDirectory(tempPath);
                        }

                        thumbLargePath  = Path.Combine(thumbLargePath, newFileName);
                        thumbMediumPath = Path.Combine(thumbMediumPath, newFileName);
                        originalPath    = Path.Combine(originalPath, newFileName);
                        tempPath        = Path.Combine(tempPath, newFileName);
                        string filePath = Path.Combine(baseLocationPath, newFileName);
                        retFilePath = retFilePath + filename + ',';
                        bool isImage = CheckImage(extension, objsettingInfo.ImageExtension);
                        if (isImage)
                        {
                            ImageOptimize objOptimizeImage = new ImageOptimize();
                            using (FileStream tempPath1 = System.IO.File.Create(tempPath))
                                files.CopyTo(tempPath1);
                            // files.SaveAs(tempPath);
                            objOptimizeImage.OptimizeImage(_hostingEnvironment.WebRootPath, tempPath, strBaseLocation, newFileName, extension);
                        }
                        else
                        {
                            using (FileStream tempPath1 = System.IO.File.Create(this.GetPathAndFilename(filename)))
                                files.CopyTo(tempPath1);
                            //files.SaveAs(filePath);
                        }
                        retMsg = "1###" + retFilePath.TrimEnd(',').Replace("." + extension, "").Replace("_", " ") + "###" + newFileName;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString().WriteLOG();
                throw;
            }
            //string filename = ContentDispositionHeaderValue.Parse(files.ContentDisposition).FileName.Trim('"');

            //filename = this.EnsureCorrectFilename(filename);

            //using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename)))
            //    files.CopyTo(output);


            return(this.Json(retMsg));
        }