예제 #1
0
        public async Task <IActionResult> Add()
        {
            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 AddEditTeamViewModel();

            viewModel.AddEdit = AddEditTeam.Add;
            viewModel.League  = Connector.League;
            viewModel.Team    = new Team();

            string webRootPath         = _env.WebRootPath;
            string imageFolderDirector = "teams";
            var    filePath            = Path.Combine(webRootPath, imageFolderDirector);

            viewModel.TeamImages = 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.TeamImages.Add(new ImageFile()
                {
                    FileSize = fileSizeInMb.ToString("0.##"),
                    FileName = Path.GetFileName(imageFile)
                });
            }

            return(View(viewModel));
        }
예제 #2
0
        public async Task <IActionResult> Edit(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 AddEditTeamViewModel();

            viewModel.AddEdit = AddEditTeam.Edit;
            viewModel.League  = Connector.League;

            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.Team = this.ApiClient.Get <Team>("Teams", paramList, ref errorMessage);
            if (viewModel.Team == null)
            {
                return(RedirectToAction("Index", "Teams", new { errorMsg = $"Error loading team: {errorMessage}" }));
            }

            errorMessage      = "";
            paramList         = new Parameter[2];
            paramList[0]      = new Parameter("apiToken", Connector.CurrentApiToken, ParameterType.QueryString);
            paramList[1]      = new Parameter("teamId", id, ParameterType.QueryString);
            viewModel.Players = this.ApiClient.Get <List <Player> >("Players/ByTeam", paramList, ref errorMessage);

            errorMessage = "";
            paramList    = new Parameter[3];
            paramList[0] = new Parameter("apiToken", Connector.CurrentApiToken, ParameterType.QueryString);
            paramList[1] = new Parameter("teamId", id, ParameterType.QueryString);
            paramList[2] = new Parameter("seasonId", Connector.Season.SeasonId, ParameterType.QueryString);

            viewModel.TeamHistory = this.ApiClient.Get <List <CompleteGame> >("Game/CompleteByTeam", paramList, ref errorMessage);
            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(RedirectToAction("Index", "Teams", new { errorMsg = $"Error getting team stats: {errorMessage}" }));
            }

            viewModel.TeamHistory = viewModel.TeamHistory.OrderByDescending(x => x.Date).ToList();

            string webRootPath         = _env.WebRootPath;
            string imageFolderDirector = "teams";
            var    filePath            = Path.Combine(webRootPath, imageFolderDirector);

            viewModel.TeamImages = 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.TeamImages.Add(new ImageFile()
                {
                    FileSize = fileSizeInMb.ToString("0.##"),
                    FileName = Path.GetFileName(imageFile)
                });
            }

            return(View(viewModel));
        }