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)); } }
public async Task <List <string> > GetAllValidPlayers(string homeTeamName, string awayTeamName) { var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync(); var homeTeamTask = _teamRosterRepository.GetByTeamNameAsync(homeTeamName, seasonInfo.Id); var awayTeamTask = _teamRosterRepository.GetByTeamNameAsync(awayTeamName, seasonInfo.Id); var players = (await _summonerInfoRepository.GetAllValidSummonersAsync()).ToDictionary(x => x.Id, x => x); var homeTeam = await homeTeamTask; var awayTeam = await awayTeamTask; var homeTeamPlayers = await _teamPlayerRepository.ReadAllForRosterAsync(homeTeam.Id); var awayTeamPlayers = await _teamPlayerRepository.ReadAllForRosterAsync(awayTeam.Id); var returningList = new List <string>(); returningList.Add("Home Team Players: "); foreach (var homePlayer in homeTeamPlayers) { if (players.TryGetValue(homePlayer.SummonerId, out var summoner)) { returningList.Add(summoner.SummonerName); players.Remove(homePlayer.SummonerId); } } returningList.Add("Away Team Players: "); foreach (var awayPlayer in awayTeamPlayers) { if (players.TryGetValue(awayPlayer.SummonerId, out var summoner)) { returningList.Add(summoner.SummonerName); players.Remove(awayPlayer.SummonerId); } } returningList.Add("Valid e-subs: "); foreach (var player in players.OrderBy(x => x.Value.SummonerName)) { returningList.Add(player.Value.SummonerName); } return(returningList); }