Esempio n. 1
0
        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());
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdateTeam([FromBody] MatchTeamDto dto)
        {
            await this._matchService.SetMatchTeamScore(dto);

            return(Ok());
        }
Esempio n. 5
0
        public async Task <IActionResult> DeleteTeam([FromBody] MatchTeamDto dto)
        {
            await this._matchService.RemoveMatchTeam(dto);

            return(Ok());
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateTeam([FromBody] MatchTeamDto dto)
        {
            await this._matchService.AddMatchTeam(dto);

            return(Ok());
        }
Esempio n. 7
0
 private async Task <MatchTeam> FindMatchTeam(MatchTeamDto dto)
 {
     return((await this.FindSingleMatchAsync(dto.MatchId)).Teams.Single(t => t.TeamId == dto.TeamId));
 }
Esempio n. 8
0
 public async Task RemoveMatchTeam(MatchTeamDto dto)
 {
     this._context.MatchTeams.Remove(await this.FindMatchTeam(dto));
     await this._context.SaveChangesAsync();
 }