コード例 #1
0
        public async Task Delete(int id)
        {
            var model = await _clubRepository.GetAsync(id);

            if (model is null)
            {
                throw new ArgumentNullException($"Could not find item with Id: {id}");
            }

            await _clubRepository.DeleteAsync(model);
        }
コード例 #2
0
        public virtual async Task <ClubDto> GetAsync(Guid id)
        {
            Club club = await _clubRepository.GetAsync(id);

            return(ObjectMapper.Map <Club, ClubDto>(club));
        }
コード例 #3
0
        public async Task GenerateAsync(int seasonId)
        {
            var season = await _seasonRepository.GetAsync(seasonId);

            var clubs = await _clubRepository.GetBriefListAsync(seasonId);

            var clubList        = clubs.ToList();
            var clubCount       = clubList.Count;
            var roundCount      = clubCount - 1;
            var matchesPerRound = clubCount / 2;

            var matchTime = new DateTime(
                season.StartDate.Year,
                season.StartDate.Month,
                season.StartDate.Day,
                17, 00, 00);

            var matches = new List <Match>();

            for (var round = 0; round < roundCount; round++)
            {
                for (var match = 0; match < matchesPerRound; match++)
                {
                    var home = (round + match) % (clubCount - 1);
                    var away = (clubCount - 1 - match + round) % (clubCount - 1);

                    if (match == 0)
                    {
                        away = clubCount - 1;
                    }

                    var homeClub = await _clubRepository.GetAsync(clubList[home].Id);

                    var awayClub = await _clubRepository.GetAsync(clubList[away].Id);

                    var homeSquad = await _squadRepository
                                    .SingleOrDefaultAsync(s => s.SeasonId == seasonId &&
                                                          s.ClubId == homeClub.Id);

                    var awaySquad = await _squadRepository
                                    .SingleOrDefaultAsync(s => s.SeasonId == seasonId &&
                                                          s.ClubId == awayClub.Id);

                    var homeClubKit = await _kitRepository
                                      .SingleOrDefaultAsync(k => k.SquadId == homeSquad.Id &&
                                                            k.KitType == KitType.HomeKit);

                    var awayClubKit = await _kitRepository
                                      .SingleOrDefaultAsync(k => k.SquadId == awaySquad.Id &&
                                                            k.KitType == KitType.AwayKit);

                    matches.Add(new Match
                    {
                        SeasonId      = seasonId,
                        Round         = round + 1,
                        StadiumId     = homeClub.StadiumId,
                        HomeClubId    = clubList[home].Id,
                        AwayClubId    = clubList[away].Id,
                        HomeClubKitId = homeClubKit.Id,
                        AwayClubKitId = awayClubKit.Id,
                        MatchTime     = matchTime,
                        IsPlayed      = false
                    });

                    matches.Add(new Match
                    {
                        SeasonId      = seasonId,
                        Round         = round + 1 + roundCount,
                        StadiumId     = awayClub.StadiumId,
                        HomeClubId    = clubList[away].Id,
                        AwayClubId    = clubList[home].Id,
                        HomeClubKitId = awayClubKit.Id,
                        AwayClubKitId = homeClubKit.Id,
                        MatchTime     = matchTime.AddDays(roundCount * 7),
                        IsPlayed      = false
                    });
                }

                if (round < roundCount - 1)
                {
                    matchTime = matchTime.AddDays(7);
                }
            }

            _matchRepository.AddRange(matches);

            season.EndDate = matchTime.AddDays(roundCount * 7);

            await _unitOfWork.CompleteAsync();
        }
コード例 #4
0
 public async Task <PaginatedList <Club> > GetAsync(ClubQuery clubQuery)
 {
     return(await _clubRepository.GetAsync(clubQuery));
 }