public async Task <bool> AssignTeamCaptain(TeamCaptainView view) { var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync(); var summoner = (await _summonerInfoRepository.GetAllForSummonerNamesAsync(new List <string> { view.SummonerName })).FirstOrDefault(); var roster = await _teamRosterRepository.GetByTeamNameAsync(view.RosterName.Trim(), seasonInfo.Id); if (summoner == null || roster == null) { return(false); } var entity = new TeamCaptainEntity { SummonerId = summoner.Id, TeamRosterId = roster.Id }; var captain = await _teamCaptainRepository.GetCaptainByRosterId(roster.Id); if (captain == null) { return(await _teamCaptainRepository.CreateCaptainAsync(entity)); } else { await _teamCaptainRepository.DeleteCaptainAsync(captain); return(await _teamCaptainRepository.CreateCaptainAsync(entity)); } }
/// <summary> /// For Roster specific View /// </summary> /// <param name="rosterId"></param> /// <returns></returns> public async Task <RosterView> GetRosterAsync(Guid rosterId) { var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync(); var alternateAccountsTask = _alternateAccountRepository.ReadAllAsync(); var rosterTask = _teamRosterRepository.GetByTeamIdAsync(rosterId); var captainTask = _teamCaptainRepository.GetCaptainByRosterId(rosterId); var playersSummoner = (await _teamPlayerRepository.ReadAllForRosterAsync(rosterId)).ToList(); var summonersTask = _summonerInfoRepository.GetAllForSummonerIdsAsync(playersSummoner.Select(x => x.SummonerId)); var matchDetails = await _matchDetailRepository.GetMatchDetailsForPlayerAsync(playersSummoner.Select(x => x.SummonerId)); var schedule = (await GetTeamSchedule(rosterId)).ToList(); matchDetails = matchDetails.Where(x => x.Key.SeasonId == seasonInfo.Id).ToDictionary(x => x.Key, x => x.Value); var scheduleIds = schedule.Select(x => x.ScheduleId).ToList(); var statIds = matchDetails.Values.SelectMany(x => x.Where(z => z.SeasonInfoId == seasonInfo.Id && scheduleIds.Contains(z.TeamScheduleId)).Select(y => y.PlayerStatsId)); var mappedStats = await SetupPlayerStatsViews(statIds, schedule, matchDetails); var alternateAccounts = (await alternateAccountsTask).ToList(); var summoners = (await summonersTask).ToList(); var summonerViews = _summonerMapper.MapDetailed(summoners, alternateAccounts, mappedStats).ToList(); var divisions = (await _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id)).ToList(); var captain = await captainTask; var roster = await rosterTask; foreach (var teamPlayerEntity in playersSummoner) { var player = summoners.First(x => x.Id == teamPlayerEntity.SummonerId); var isSub = teamPlayerEntity.IsSub ?? false; var summonerView = summonerViews.First(x => x.SummonerName == player.SummonerName); summonerView.IsSub = isSub; } var division = divisions.First(x => x.LowerLimit <= roster.TeamTierScore && x.UpperLimit >= roster.TeamTierScore); var rosterView = new RosterView { RosterId = roster.Id, Captain = summoners.FirstOrDefault(x => x.Id == captain?.SummonerId)?.SummonerName, TeamName = roster.TeamName, Wins = roster.Wins ?? 0, Loses = roster.Loses ?? 0, Players = summonerViews, TeamTierScore = roster.TeamTierScore.GetValueOrDefault(), Division = new DivisionView { DivisionName = division.Name, DivisionMinScore = division.LowerLimit, DivisionId = division.Id }, Schedule = schedule }; var directory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\logos"); var path = Directory.GetFiles(directory).FirstOrDefault(x => x.Contains(rosterId.ToString())); if (File.Exists(path)) { var byteData = await File.ReadAllBytesAsync(path); var base64 = Convert.ToBase64String(byteData); var type = GetContentType(path); var imgSrc = string.Format($"data:{type};base64,{base64}"); rosterView.FileSource = imgSrc; } rosterView.Cleanup(); return(rosterView); }