public async Task <IActionResult> EditPlayer(int id) { if (!await this.CheckLoginStatus()) { return(RedirectToAction("Index", "Home", new { errorMsg = "You must join a league first." })); } if (Connector.League == null) { return(RedirectToAction("Index", "Home", new { errorMsg = "You must join a league first." })); } var viewModel = new AddEditPlayerViewModel(); viewModel.AddEdit = AddEditPlayer.Edit; string errorMessage = ""; Parameter[] paramList = new Parameter[2]; paramList[0] = new Parameter("apiToken", Connector.CurrentApiToken, ParameterType.QueryString); paramList[1] = new Parameter("Id", id, ParameterType.QueryString); viewModel.Player = this.ApiClient.Get <Player>("Players", paramList, ref errorMessage); if (viewModel.Player == null) { return(RedirectToAction("Index", "Teams", new { errorMsg = $"Error retrieving player info: {errorMessage}" })); } string webRootPath = _env.WebRootPath; string imageFolderDirector = "players"; var filePath = Path.Combine(webRootPath, imageFolderDirector); viewModel.PlayerImages = new List <ImageFile>(); var rawMediaFiles = System.IO.Directory.GetFiles(filePath); var imageFileNames = new List <string>(); foreach (var file in rawMediaFiles) { if (Path.GetExtension(file).ToUpper() == ".APNG" || Path.GetExtension(file).ToUpper() == ".BMP" || Path.GetExtension(file).ToUpper() == ".JPG" || Path.GetExtension(file).ToUpper() == ".JPEG" || Path.GetExtension(file).ToUpper() == ".PNG" || Path.GetExtension(file).ToUpper() == ".SVG" || Path.GetExtension(file).ToUpper() == ".WEBP") { imageFileNames.Add(file); } } foreach (var imageFile in imageFileNames) { double fileSizeInMb = Convert.ToInt32(new System.IO.FileInfo(Path.Combine(filePath, imageFile)).Length) / 1000000.0; viewModel.PlayerImages.Add(new ImageFile() { FileSize = fileSizeInMb.ToString("0.##"), FileName = Path.GetFileName(imageFile) }); } return(View(viewModel)); }
public async Task <IActionResult> AddPlayer(int teamId) { if (!await this.CheckLoginStatus()) { return(RedirectToAction("Index", "Home", new { errorMsg = "You must join a league first." })); } if (Connector.League == null) { return(RedirectToAction("Index", "Home", new { errorMsg = "You must join a league first." })); } var viewModel = new AddEditPlayerViewModel(); viewModel.AddEdit = AddEditPlayer.Add; viewModel.Player = new Player() { TeamId = teamId }; string webRootPath = _env.WebRootPath; string imageFolderDirector = "players"; var filePath = Path.Combine(webRootPath, imageFolderDirector); viewModel.PlayerImages = new List <ImageFile>(); var rawMediaFiles = System.IO.Directory.GetFiles(filePath); var imageFileNames = new List <string>(); foreach (var file in rawMediaFiles) { if (Path.GetExtension(file).ToUpper() == ".APNG" || Path.GetExtension(file).ToUpper() == ".BMP" || Path.GetExtension(file).ToUpper() == ".JPG" || Path.GetExtension(file).ToUpper() == ".JPEG" || Path.GetExtension(file).ToUpper() == ".PNG" || Path.GetExtension(file).ToUpper() == ".SVG" || Path.GetExtension(file).ToUpper() == ".WEBP") { imageFileNames.Add(file); } } foreach (var imageFile in imageFileNames) { double fileSizeInMb = Convert.ToInt32(new System.IO.FileInfo(Path.Combine(filePath, imageFile)).Length) / 1000000.0; viewModel.PlayerImages.Add(new ImageFile() { FileSize = fileSizeInMb.ToString("0.##"), FileName = Path.GetFileName(imageFile) }); } return(View(viewModel)); }