/// <summary> /// Will always go through here /// </summary> /// <param name="view"></param> /// <param name="user"></param> /// <returns></returns> public async Task <bool> UpdateSummonerInfoAsync(SummonerInfoView view, UserEntity user) { try { view.RemoveEmptyViewsForDb(); var readEntity = await _summonerInfoRepository.ReadOneByUserIdAsync(user.Id); if (readEntity == null) { return(await CreateSummonerInfoAsync(view, user)); } var summonerInfo = _summonerMapper.Map(view); summonerInfo.Id = readEntity.Id; summonerInfo.UserId = readEntity.UserId; summonerInfo.IsValidPlayer = readEntity.IsValidPlayer; summonerInfo.UpdatedOn = TimeZoneExtensions.GetCurrentTime(); var altAccountTask = UpdateAlternateAccountsAsync(summonerInfo.Id, view.AlternateAccounts); var updateSummonerInfoTask = _summonerInfoRepository.UpdateAsync(new List <SummonerInfoEntity> { summonerInfo }); return(await altAccountTask && await updateSummonerInfoTask); } catch (SummonerInfoException) { throw; } catch (Exception e) { var message = $"Error updating summoner info for: {user.Email}"; _logger.LogError(e, message); throw new Exception(message, e); } }
public async Task <IActionResult> SendMatchDetailsAsync(SimplifiedMatchSubmissionView view) { try { var user = await _userManager.GetUserAsync(User); view.GameDetails = view.GameDetails.Where(x => x.GamePlayed || x.AwayTeamForfeit || x.HomeTeamForfeit) .ToList(); var isNullCheck = false; if (user == null) { throw new Exception("You were logged out unexpectedly. Im sorry."); } var userPlayer = await _summonerInfoRepository.ReadOneByUserIdAsync(user.Id); foreach (var gameInfo in view.GameDetails) { isNullCheck = Properties <GameDetail> .HasEmptyProperties(gameInfo); if (isNullCheck) { break; } } if (!view.GameDetails.Any() || view.GameDetails.Count < 2 || isNullCheck) { throw new Exception("Form was not setup right"); } var result = await _matchDetailService.SendFileData(view, userPlayer); if (!result) { throw new Exception($"Failed to send match data for: {view.FileName}"); } StatusMessage = "Successfully submitted match data. Stats will be reflected soon."; } catch (RiotSharpException e) { StatusMessage = $"{e.Message} Note. This is an error with Riot's Api. Please contact Ansem571 to let him know"; _logger.LogError(e, StatusMessage); } catch (Exception e) { StatusMessage = e.Message; _logger.LogError(e, StatusMessage); } var playersList = await _accountService.GetAllValidPlayers(view.HomeTeamName, view.AwayTeamName); view.ValidPlayers = playersList; view.StatusMessage = StatusMessage; return(View(view)); }
public async Task <PlayerProfileView> GetPlayerProfileAsync(Guid userId) { var seasonsTask = _seasonInfoRepository.GetAllSeasonsAsync(); var summonerTask = _summonerInfoRepository.ReadOneByUserIdAsync(userId); var achievementsTask = _achievementRepository.GetAchievementsForUserAsync(userId); var summoner = await summonerTask; if (summoner == null) { var message = $"User {userId} was not found."; _logger.LogError(message); throw new SummonerInfoException($"User {userId} was not found."); } var achievements = await achievementsTask; var alternateAccountsTask = _alternateAccountRepository.ReadAllForSummonerAsync(summoner.Id); var teamPlayer = (await _teamPlayerRepository.GetAllRostersForPlayerAsync(summoner.Id)).ToList(); var seasons = (await seasonsTask).OrderBy(x => x.SeasonStartDate).ToList(); var alternateAccounts = await alternateAccountsTask; var altAccountsMapped = _alternateAccountMapper.Map(alternateAccounts); var achievementViews = new List <AchievementView>(); foreach (var achievement in achievements) { var achievementView = new AchievementView(achievement); var seasonAchieved = seasons.FirstOrDefault(x => x.SeasonStartDate <achievement.AchievedDate && (x.SeasonEndDate ?? DateTime.MaxValue)> achievement.AchievedDate); achievementView.Season = seasonAchieved != null ? seasonAchieved.SeasonName : "PreSeason"; achievementViews.Add(achievementView); } var playerStatsDictionary = new Dictionary <int, PlayerStatsView>(); var matchDetails = await _matchDetailRepository.GetMatchDetailsForPlayerAsync(new List <Guid> { summoner.Id }); var statIds = matchDetails.Values.SelectMany(x => x.Select(y => y.PlayerStatsId)); var allPlayerStats = await _playerStatsRepository.GetStatsAsync(statIds); var teamname = "None"; if (teamPlayer.Any()) { var latestSeason = seasons.Last(); var team = await _teamRosterRepository.GetTeamAsync(latestSeason.Id, teamPlayer.Select(x => x.TeamRosterId)); if (team != null) { teamname = team.TeamName; } } foreach (var seasonKvp in allPlayerStats) { var season = seasons.First(x => x.Id == seasonKvp.Key.SeasonId); var seasonStats = allPlayerStats.SelectMany(x => x.Value.Where(y => y.SeasonInfoId == season.Id)); var mappedStats = _playerStatsMapper.MapForSeason(seasonStats, 0); if (int.TryParse(season.SeasonName.Split(" ").Last(), out var seasonNum)) { playerStatsDictionary.Add(seasonNum, mappedStats); } } var view = new PlayerProfileView { PlayerName = summoner.SummonerName, Rank = _tierDivisionMapper.Map(summoner.Tier_DivisionId), TeamName = string.IsNullOrEmpty(teamname) ? "None" : teamname, Achievements = achievementViews, PlayerStats = playerStatsDictionary, AlternateAccountViews = altAccountsMapped }; if (summoner.PreviousSeasonRankId != null) { view.PreviousSeasonRank = _tierDivisionMapper.Map(summoner.PreviousSeasonRankId.Value); } return(view); }