public ActionResult Async_Save(IEnumerable <HttpPostedFileBase> files) { long ParamPlayerID = 4; string FinalFileName = ""; // The Name of the Upload component is "files" if (files != null) { PlayerImagesRepository modelRepo = new PlayerImagesRepository(); string PlayerImagesFolder = Path.Combine(Server.MapPath("~" + SecurityUtils.Players_ImagePath + ""), ParamPlayerID.ToString()); foreach (var file in files) { if (!(System.IO.Directory.Exists(PlayerImagesFolder))) { System.IO.Directory.CreateDirectory(PlayerImagesFolder); } // Some browsers send file names with full path. This needs to be stripped. string IEFileName = "", FileNameWithExtension = ""; if (Request.Browser.Browser.ToLower().Equals("ie") || Request.Browser.Browser.ToLower().Equals("internetexplorer")) { IEFileName = Path.GetFileName(file.FileName); } if (IEFileName != "") { FileNameWithExtension = IEFileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } else { FileNameWithExtension = file.FileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } var fileExtension = Path.GetExtension(FileNameWithExtension); //Following Code will rename the file if it is already Exists int count = 1; string fileNameOnly = Guid.NewGuid().ToString(); //Path.GetFileNameWithoutExtension(FileNameWithExtension); string extension = Path.GetExtension(FileNameWithExtension); string newFullPath = FileNameWithExtension; newFullPath = Path.Combine(PlayerImagesFolder, fileNameOnly + extension); while (System.IO.File.Exists(newFullPath)) { string tempFileName = string.Format("{0}({1})", fileNameOnly, count++); newFullPath = Path.Combine(PlayerImagesFolder, tempFileName + extension); } fileNameOnly = Path.GetFileNameWithoutExtension(newFullPath); //Update Filename from Repository string Msg = ""; bool status = true; FinalFileName = fileNameOnly + extension; //Save the file to the Disk file.SaveAs(newFullPath); string PlayerImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); string WaterMarkImagePath = Server.MapPath("~/Images/verticle_mvff.png"); Image_Combine imgCombine = new Image_Combine(); string FinalFileName_WaterMarked = imgCombine.CombineBitmap_WatermarkImage(PlayerImagesFolder, FinalFileName, WaterMarkImagePath); //Clear the Object imgCombine = null; PlayerImagesExt PlayerImg = new PlayerImagesExt() { PlayerID = ParamPlayerID, FileName = FinalFileName_WaterMarked, IsAnimated = false, Display = true, DefaultImage = false, UploadDateTime = DateTime.Now }; modelRepo.CreateOrUpdate(ref PlayerImg, ref Msg, ref status, this); string NonWaterMarkImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); if (System.IO.File.Exists(NonWaterMarkImagePath)) { System.IO.File.Delete(NonWaterMarkImagePath); } if (status && SecurityUtils.Enable_PremiumDashboard) { AchievementsRepository achRepo = new AchievementsRepository(); Guid guid = Guid.NewGuid(); AchievementThread = new Thread(() => achRepo.ImageGallery_AchievementPoints(ParamPlayerID, AchievementThread)); AchievementThread.Name = "ImageGallery_BeforeAfterImageCreated_AchievementPoints_" + guid.ToString(); AchievementThread.Start(); } } } // Return an empty string to signify success return(Content("")); }
/// <summary> /// Save Player Progress Image /// </summary> /// <param name="PlayerProgressImages">List of Uploaded Images</param> /// <param name="PlayerEmailAddress">Player Email Address to match and save against Player record in DB</param> /// <param name="LeagueID">League ID from current League Home Page</param> /// <param name="IsFront">IsFront</param> /// <param name="IsSide">IsSide</param> /// <returns></returns> public ActionResult SavePlayerProgressImages(IEnumerable <HttpPostedFileBase> PlayerProgressImages_Front, IEnumerable <HttpPostedFileBase> PlayerProgressImages_Side, string PlayerEmailAddress, long LeagueID, bool IsFront, bool IsSide) { IEnumerable <HttpPostedFileBase> PlayerProgressImages = null; List <PlayerImagesExt> ListOfPlayerImages = new List <PlayerImagesExt>(); if (PlayerProgressImages_Front != null) { PlayerProgressImages = PlayerProgressImages_Front; } else if (PlayerProgressImages_Side != null) { PlayerProgressImages = PlayerProgressImages_Side; } PlayersRepository playerRepo = new PlayersRepository(); var player = playerRepo.ReadOne_ByEmailAddress(PlayerEmailAddress); PlayerImagesRepository modelRepo = new PlayerImagesRepository(); if (player != null) { ListOfPlayerImages = modelRepo.ReadAll(player.PlayerID, false, false); } var ErrorMsg = ValidatePlayer_ForProgressImage(player, ListOfPlayerImages, LeagueID, IsFront, IsSide); if (!string.IsNullOrEmpty(ErrorMsg)) { return(Content(ErrorMsg)); } else { var ParamPlayerID = player.PlayerID; string FinalFileName = ""; // The Name of the Upload component is "files" if (PlayerProgressImages != null) { string PlayerImagesFolder = Path.Combine(Server.MapPath("~" + SecurityUtils.Players_ImagePath + ""), ParamPlayerID.ToString()); foreach (var file in PlayerProgressImages) { if (!(System.IO.Directory.Exists(PlayerImagesFolder))) { System.IO.Directory.CreateDirectory(PlayerImagesFolder); } // Some browsers send file names with full path. This needs to be stripped. string IEFileName = "", FileNameWithExtension = ""; if (Request.Browser.Browser.ToLower().Equals("ie") || Request.Browser.Browser.ToLower().Equals("internetexplorer")) { IEFileName = Path.GetFileName(file.FileName); } if (IEFileName != "") { FileNameWithExtension = IEFileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } else { FileNameWithExtension = file.FileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } var fileExtension = Path.GetExtension(FileNameWithExtension); //Following Code will rename the file if it is already Exists int count = 1; string fileNameOnly = Guid.NewGuid().ToString(); //Path.GetFileNameWithoutExtension(FileNameWithExtension); string extension = Path.GetExtension(FileNameWithExtension); string newFullPath = FileNameWithExtension; newFullPath = Path.Combine(PlayerImagesFolder, fileNameOnly + extension); while (System.IO.File.Exists(newFullPath)) { string tempFileName = string.Format("{0}({1})", fileNameOnly, count++); newFullPath = Path.Combine(PlayerImagesFolder, tempFileName + extension); } fileNameOnly = Path.GetFileNameWithoutExtension(newFullPath); //Update Filename from Repository string Msg = ""; bool status = true; FinalFileName = fileNameOnly + extension; //Save the file to the Disk file.SaveAs(newFullPath); // ImageWaterMark imgWaterMark = new ImageWaterMark(); string PlayerImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); string WaterMarkImagePath = Server.MapPath("~/Images/verticle_mvff.png"); Image_Combine imgCombine = new Image_Combine(); string FinalFileName_WaterMarked = imgCombine.CombineBitmap_WatermarkImage(PlayerImagesFolder, FinalFileName, WaterMarkImagePath); //imgWaterMark.GenerateWaterMarkOnImage(PlayerImagesFolder, FinalFileName, false, true, WaterMarkImagePath, null, false, false, true, false, false); //Clear the Object imgCombine = null; PlayerImagesExt PlayerImg = new PlayerImagesExt() { PlayerID = ParamPlayerID, FileName = FinalFileName_WaterMarked, IsAnimated = false, Display = true, DefaultImage = false, IsFront = IsFront, IsSide = IsSide, UploadDateTime = DateTime.Now }; modelRepo.CreateOrUpdate(ref PlayerImg, ref Msg, ref status, this); string NonWaterMarkImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); if (System.IO.File.Exists(NonWaterMarkImagePath)) { System.IO.File.Delete(NonWaterMarkImagePath); } } } // Return an empty string to signify success return(Content("")); } }