public async Task SetMatchTeamScore(MatchTeamDto dto) { var tm = await this.FindMatchTeam(dto); tm.Score = dto.Score; await this._context.SaveChangesAsync(); }
private static MatchTeam ConvertMatchTeamDtoToMatchTeam(MatchTeamDto matchTeamDto, IEnumerable <MatchEventDto> matchEventsDtoList) { if (matchTeamDto == null || matchEventsDtoList == null) { return(new MatchTeam()); } try { return(new MatchTeam { TeamId = matchTeamDto.TeamId, BaronKills = matchTeamDto.BaronKills, DragonKills = matchTeamDto.DragonKills, InhibitorKills = matchTeamDto.InhibitorKills, RiftHeraldKills = matchTeamDto.RiftHeraldKills, TeamKills = matchTeamDto.Players.Sum(x => x.Kills), TeamDeaths = matchTeamDto.Players.Sum(x => x.Deaths), TeamAssists = matchTeamDto.Players.Sum(x => x.Assists), PlayerOne = ConvertMatchPlayerDtoToMatchPlayer( matchTeamDto.Players.ElementAtOrDefault(0), matchEventsDtoList.Where(x => x.ParticipantId == matchTeamDto.Players.ElementAtOrDefault(0)?.ParticipantId)), PlayerTwo = ConvertMatchPlayerDtoToMatchPlayer( matchTeamDto.Players.ElementAtOrDefault(1), matchEventsDtoList.Where(x => x.ParticipantId == matchTeamDto.Players.ElementAtOrDefault(1)?.ParticipantId)), PlayerThree = ConvertMatchPlayerDtoToMatchPlayer( matchTeamDto.Players.ElementAtOrDefault(2), matchEventsDtoList.Where(x => x.ParticipantId == matchTeamDto.Players.ElementAtOrDefault(2)?.ParticipantId)), PlayerFour = ConvertMatchPlayerDtoToMatchPlayer( matchTeamDto.Players.ElementAtOrDefault(3), matchEventsDtoList.Where(x => x.ParticipantId == matchTeamDto.Players.ElementAtOrDefault(3)?.ParticipantId)), PlayerFive = ConvertMatchPlayerDtoToMatchPlayer( matchTeamDto.Players.ElementAtOrDefault(4), matchEventsDtoList.Where(x => x.ParticipantId == matchTeamDto.Players.ElementAtOrDefault(4)?.ParticipantId)) }); } catch (Exception e) { Console.WriteLine("Exception caught when converting MatchTeamDto to MatchTeam : " + e.Message); } return(new MatchTeam()); }
public async Task AddMatchTeam(MatchTeamDto dto) { var match = await this.FindSingleMatchAsync(dto.MatchId); if (match.Teams.Any(t => t.TeamId == dto.TeamId)) { return; } var mt = new MatchTeam { MatchId = dto.MatchId, TeamId = dto.TeamId, Score = 0 }; await this._context.MatchTeams.AddAsync(mt); await this._context.SaveChangesAsync(); }
public async Task <IActionResult> UpdateTeam([FromBody] MatchTeamDto dto) { await this._matchService.SetMatchTeamScore(dto); return(Ok()); }
public async Task <IActionResult> DeleteTeam([FromBody] MatchTeamDto dto) { await this._matchService.RemoveMatchTeam(dto); return(Ok()); }
public async Task <IActionResult> CreateTeam([FromBody] MatchTeamDto dto) { await this._matchService.AddMatchTeam(dto); return(Ok()); }
private async Task <MatchTeam> FindMatchTeam(MatchTeamDto dto) { return((await this.FindSingleMatchAsync(dto.MatchId)).Teams.Single(t => t.TeamId == dto.TeamId)); }
public async Task RemoveMatchTeam(MatchTeamDto dto) { this._context.MatchTeams.Remove(await this.FindMatchTeam(dto)); await this._context.SaveChangesAsync(); }