public async Task <IActionResult> Details(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }

            GetMatchDto requiredMatch = await _matchService.GetMatchById(id);

            int hostTeamId = await _teamService.GetTeamIdByName(requiredMatch.HostTeam);

            GetTeamDto hostTeam = await _teamService.GetTeamById(hostTeamId);

            int guestTeamId = await _teamService.GetTeamIdByName(requiredMatch.GuestTeam);

            GetTeamDto guestTeam = await _teamService.GetTeamById(guestTeamId);

            if (requiredMatch == null)
            {
                return(NotFound());
            }
            ViewBag.Guest = guestTeam.Players;
            ViewBag.Host  = hostTeam.Players;
            return(View(requiredMatch));
        }
示例#2
0
        public async Task <GetMatchDto> GetMatchById(int id)
        {
            Match dbMatch = await _context.Matches.FirstOrDefaultAsync(a => a.MatchId == id);

            GetMatchDto matchForDisplaying = _mapper.Map <GetMatchDto>(dbMatch);

            return(matchForDisplaying);
        }
        public async Task <IActionResult> PlayerScored(PlayerGoalDto playerGoal)
        {
            // part for Rest task

            PlayerGoalMatch playerFromDb = await _context.PlayerGoalMatches.FirstOrDefaultAsync(
                p => p.PlayerName.ToLower().Equals(playerGoal.PlayerName.ToLower()) && p.MatchId == int.Parse(playerGoal.MatchId));

            if (playerFromDb != null)
            {
                playerFromDb.Goals = playerFromDb.Goals + 1;

                _context.PlayerGoalMatches.Update(playerFromDb);
                await _context.SaveChangesAsync();
            }
            else
            {
                PlayerGoalMatch newForDb = new PlayerGoalMatch();
                newForDb.PlayerName = playerGoal.PlayerName;
                newForDb.MatchId    = int.Parse(playerGoal.MatchId);
                newForDb.Goals      = 1;
                await _context.PlayerGoalMatches.AddAsync(newForDb);

                await _context.SaveChangesAsync();
            }
            //

            await _matchService.Goal(playerGoal.MatchId, playerGoal.TeamName);

            await _playerService.PlayerScored(playerGoal.PlayerName, playerGoal.MatchId);

            Match matchFromDb = await _context.Matches.FirstOrDefaultAsync(m => m.MatchId == int.Parse(playerGoal.MatchId));

            GetMatchDto match = _mapper.Map <GetMatchDto>(matchFromDb);

            return(Ok(match));
        }