Example #1
0
        public async Task <MatchModel> AddAsync(MatchModel matchModel)
        {
            var matchEntity = mapper.Map <MatchEntity>(matchModel);
            var response    = await matchRepository.AddAsync(matchEntity);

            return(mapper.Map <MatchModel>(response));
        }
Example #2
0
        public async Task <Guid> Handle(CreateMatchCommand request, CancellationToken cancellationToken)
        {
            var match = Match.CreateNew(request.Name, new TeamId(request.HomeTeamId), new TeamId(request.AwayTeamId),
                                        request.Score, request.Season,
                                        request.UtcDate, request.ExternalId, request.Status);

            await _matchRepository.AddAsync(match);

            return(match.Id.Value);
        }
Example #3
0
        public async Task <MatchDTO> CreateMatch(CreateMatchModel createMatch)
        {
            var participantHome = await _participantRepository.GetAsync(createMatch.IdParticipantHome);

            if (participantHome == null)
            {
                throw new AppException("Home participant doesn't exist.");
            }

            var participantAway = await _participantRepository.GetAsync(createMatch.IdParticipantAway);

            if (participantAway == null)
            {
                throw new AppException("Away participant doesn't exist.");
            }

            var matchParticipant = new ParticipantsMatch(participantHome, participantAway);

            var match = new Match(new Guid(), matchParticipant, DateTime.Now, createMatch.BeginsAt);

            await _matchRepository.AddAsync(match);

            return(_mapper.Map <MatchDTO>(match));
        }
Example #4
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)));
        }
Example #5
0
        public async Task SaveChessMatchOnDatabase(string roomId)
        {
            var chessMatch = await GetChessMatch(roomId);

            await _matchRepository.AddAsync(chessMatch.Match);
        }
Example #6
0
 public async Task AddMatch(Match newMatch)
 {
     await _matchRepository.AddAsync(_mapper.Map <DataRepository.DataEntities.Match>(newMatch));
 }