public IActionResult Index() { List<Season> seasons = _seasonLogic.GetSeasons(); var vm = new SeasonsAdministrationViewModel { Seasons = seasons }; return View(vm); }
public async Task <IActionResult> ResetLeaderboards() { var seasons = await _seasonLogic.GetSeasons(); foreach (var season in seasons) { await _leaderboardService.RecalculateLeaderboard(season); } return(Ok()); }
public IActionResult SaveMatch(SaveMatchesRequest saveMatchesRequest) { if (saveMatchesRequest == null) { return(BadRequest()); } //var validated = _userRepository.Validate(saveMatchesRequest.User); //if (!validated) //{ // return Unauthorized(); //} var seasons = _seasonLogic.GetSeasons(); if (seasons.All(x => x.EndDate != null)) { return(BadRequest("No active seaons")); } var currentSeason = seasons.Single(x => x.EndDate == null); var matches = saveMatchesRequest.Matches.OrderBy(x => x.TimeStampUtc).ToList(); //Sat i AddMatch java foreach (var match in matches) { if (match.TimeStampUtc == DateTime.MinValue) { match.TimeStampUtc = DateTime.UtcNow; } match.SeasonName = currentSeason.Name; var leaderboards = _leaderboardService.GetLatestLeaderboardViews(); var activeLeaderboard = leaderboards.SingleOrDefault(x => x.SeasonName == currentSeason.Name); _leaderboardService.AddMatchToLeaderboard(activeLeaderboard, match); _matchRepository.Upsert(match); _leaderboardViewRepository.Upsert(activeLeaderboard); } return(Ok()); }
public async Task <LeaderboardView> RecalculateLeaderboard(Season season) { var seasons = await _seasonLogic.GetSeasons(); await _playerRankHistoryRepository.RemovePlayerHistoryFromSeason(season.Name); var playerRankHistories = await _playerRankHistoryRepository.GetPlayerRankHistories(season.Name); var matches = (await _matchRepository.GetMatches(season.StartDate, HelperMethods.GetNextSeason(seasons, season)?.StartDate)) .OrderBy(x => x.TimeStampUtc); var existingLeaderboard = await _leaderboardViewRepository.GetLeaderboardView(season); var leaderboardView = existingLeaderboard ?? new LeaderboardView(season.Name); leaderboardView.Entries = new List <LeaderboardViewEntry>(); //Clear old matches if existing leaderboard exists foreach (var match in matches) { var matchPointsChanged = AddMatchToLeaderboard(leaderboardView, match); UpdatePlayerRanks(playerRankHistories, leaderboardView.Entries.OrderByDescending(x => x.EloRating).ToList(), season.Name, match.TimeStampUtc); if (matchPointsChanged) { await _matchRepository.Upsert(match); } } leaderboardView.Entries = leaderboardView.Entries.OrderByDescending(x => x.EloRating).ToList(); await _leaderboardViewRepository.Upsert(leaderboardView); //Only update those who played this season foreach (PlayerRankSeasonEntry playerRankHistory in playerRankHistories.Where(x => leaderboardView.Entries.Select(x => x.UserName).Contains(x.Email))) { await _playerRankHistoryRepository.Upsert(playerRankHistory); } return(leaderboardView); }
public async Task <AchievementsView> Index(string?seasonName) { var seasons = await _seasonLogic.GetSeasons(); Season selectedSeason; if (seasonName != null) { selectedSeason = seasons.SingleOrDefault(x => x.Name == seasonName); } else { selectedSeason = await _seasonLogic.GetActiveSeason(seasons); } var ach = await _achievementsService.GetAchievementsView(seasons, selectedSeason); return(ach); }
public List <LeaderboardView> GetLatestLeaderboardViews() { var seasons = _seasonLogic.GetSeasons(); var latestLeaderboardViews = _leaderboardViewRepository.GetLeaderboardViews(); foreach (var season in seasons) { var existingLeaderboard = latestLeaderboardViews.Any(x => x.SeasonName == season.Name); if (existingLeaderboard == false) { latestLeaderboardViews.Add(RecalculateLeaderboard(season.Name)); } } foreach (var season in latestLeaderboardViews) { season.Entries = season.Entries.OrderByDescending(x => x.EloRating).ToList(); } return(latestLeaderboardViews); }
public async Task <IActionResult> SaveMatch(SaveMatchesRequest saveMatchesRequest) { if (saveMatchesRequest == null) { throw new ArgumentNullException(nameof(saveMatchesRequest)); } if (saveMatchesRequest.Email == null) { throw new ArgumentNullException(nameof(saveMatchesRequest.Email)); } if (saveMatchesRequest.Matches == null) { throw new ArgumentNullException(nameof(saveMatchesRequest.Matches)); } var hasAdminClaim = HttpContext.User.HasClaim(x => x.Type == "Role" && x.Value == ClaimRoles.Admin.ToString()); foreach (var match in saveMatchesRequest.Matches) { if (!match.PlayerList.Contains(saveMatchesRequest.Email) && !hasAdminClaim) { return(Unauthorized()); } if (!ValidateScore(match)) { return(Forbid($"Invalid match score {match.MatchResult.Team1Score} - {match.MatchResult.Team2Score}")); } } var seasons = await _seasonLogic.GetSeasons(); var currentSeason = HelperMethods.GetCurrentSeason(seasons); if (currentSeason == null) { return(BadRequest()); //"No active seaons" } var isEdit = saveMatchesRequest.Matches.Any(x => x.Id != Guid.Empty); var fromPreviousSeason = saveMatchesRequest.Matches.Any(x => x.TimeStampUtc < currentSeason.StartDate); if (isEdit && fromPreviousSeason && !hasAdminClaim) { return(Forbid()); } var matches = saveMatchesRequest.Matches.OrderBy(x => x.TimeStampUtc).ToList(); foreach (var match in matches) { match.SubmittedBy = saveMatchesRequest.Email; if (match.TimeStampUtc == DateTime.MinValue) { match.TimeStampUtc = DateTime.UtcNow; } var leaderboards = await _leaderboardService.GetLatestLeaderboardViews(); var playerRankHistories = await _playerRankHistoryRepository.GetPlayerRankHistories(currentSeason.Name); var activeLeaderboard = leaderboards.SingleOrDefault(x => x.SeasonName == currentSeason.Name); if (!isEdit) { _leaderboardService.AddMatchToLeaderboard(activeLeaderboard, match); } await _matchRepository.Upsert(match); _leaderboardService.UpdatePlayerRanks(playerRankHistories, activeLeaderboard.Entries.OrderByDescending(x => x.EloRating).ToList(), currentSeason.Name, match.TimeStampUtc); //Only update those who played this season foreach (PlayerRankSeasonEntry playerRankHistory in playerRankHistories.Where(x => activeLeaderboard.Entries.Select(x => x.UserName).Contains(x.Email))) { await _playerRankHistoryRepository.Upsert(playerRankHistory); } if (!isEdit) { await _leaderboardViewRepository.Upsert(activeLeaderboard); } } if (isEdit) { if (fromPreviousSeason) { var season = HelperMethods.GetSeasonOfDate(seasons, matches.First().TimeStampUtc); await _leaderboardService.RecalculateLeaderboard(season); } else { await _leaderboardService.RecalculateLeaderboard(currentSeason); } } await _hubContext.Clients.All.MatchAdded(); return(Ok()); }
public async Task <IActionResult> GetSeasonsAsync() { var seasons = await _seasonLogic.GetSeasons(); return(Ok(seasons)); }
public async Task<List<PartnerPercentResult>> GetPlayerPartnerResults(string email) { List<Season> seasons = await _seasonLogic.GetSeasons(); Season activeSeason = await _seasonLogic.GetActiveSeason(seasons); return await _matchupHistoryCreator.GetPartnerWinPercent(seasons, email, activeSeason); }
public IActionResult Index() { List <Season> seasons = _seasonLogic.GetSeasons(); return(View(seasons)); }