Example #1
0
        public async Task <IActionResult> GetById(int id)
        {
            var match = await _matchRepository.GetByIdAsync(id);

            if (match == null)
            {
                return(BadRequest($"Invalid match id : { id }"));
            }

            var dto = MatchDto.FromEntity(match);

            return(Ok(dto));
        }
Example #2
0
        public async Task <IActionResult> Create(MatchCreateDto model)
        {
            var teamA = await _teamRepository.GetByIdAsync(model.TeamAId);

            if (teamA == null)
            {
                return(BadRequest($"Invalid Team A Id { model.TeamAId }"));
            }

            var teamB = await _teamRepository.GetByIdAsync(model.TeamBId);

            if (teamB == null)
            {
                return(BadRequest($"Invalid Team B Id { model.TeamBId }"));
            }

            var match = new Match(teamA, teamB, model.MatchDate);

            await _matchRepository.AddAsync(match);

            await _unitOfWork.Commit();

            return(CreatedAtAction(nameof(GetById), new { id = match.Id }, MatchDto.FromEntity(match)));
        }