Ejemplo n.º 1
0
        public async Task <Game> CreateNewGameForMatchDay(string matchDayId, string tenantId)
        {
            var matchDay = (await _matchDayService.Find(m => m.Id == matchDayId,
                                                        nameof(MatchDay.Games),
                                                        nameof(MatchDay.MatchDayPlayers),
                                                        $"{nameof(MatchDay.MatchDayPlayers)}.{nameof(MatchDayPlayer.Player)}")).FirstOrDefault();

            if (matchDay == null)
            {
                throw new EntityNotFoundException($"MatchDay with id {matchDay} not found.");
            }

            if (matchDay.TenantId != tenantId)
            {
                throw new TenantMissmatchException();
            }

            if (matchDay.IsFinished)
            {
                throw new EntityClosedForUpdateException($"MatchDay with id {matchDayId} is already finished.");
            }

            var matchDayGames = (await _matchDayService.GetMatchDayGames(matchDayId, tenantId)).ToList();
            var nextPlayers   = matchDay.GetNextPlayers(matchDayGames);

            var game = await CreateGame(matchDay.TenantId, nextPlayers.PlayerOneId, nextPlayers.PlayerTwoId, matchDay.Id);

            game.MatchDayId = matchDay.Id;

            game = await Add(game);

            return(game);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get(
            [FromQuery] string orderBy = "Date",
            [FromQuery] bool desc      = false,
            [FromQuery] int pageSize   = 10,
            [FromQuery] int page       = 0)
        {
            var tenantId      = this.GetTenantId();
            var matchDayQuery = await _matchDayService
                                .Find(m => m.TenantId == tenantId,
                                      nameof(MatchDay.Games),
                                      nameof(MatchDay.MatchDayPlayers));

            matchDayQuery = desc ?
                            matchDayQuery.OrderByDescending(orderBy)
                : matchDayQuery.OrderBy(orderBy);

            var response = HandicapResponse <MatchDayResponse, MatchDay> .Create(matchDayQuery, null, page, pageSize, _mapper);

            return(Ok(response));
        }