Esempio n. 1
0
        public static IEnumerable <RoundInfoViewModel> ToRoundInfoViewModel(this IEnumerable <Game> games)
        {
            if (Guard.IsEmptyIEnumerable(games))
            {
                return(new RoundInfoViewModel[0]);
            }

            IEnumerable <IGrouping <short, Game> > grouppedGamesByRound = games.GroupBy(g => g.roundId);
            var roundViews = new List <RoundInfoViewModel>();

            foreach (IGrouping <short, Game> roundGames in grouppedGamesByRound)
            {
                var firstGame = roundGames.First();
                var roundView = new RoundInfoViewModel()
                {
                    tourney   = firstGame?.round?.tourney?.Name ?? "Турнир",
                    logo      = string.Empty,
                    roundId   = firstGame.roundId,
                    name      = firstGame?.round?.Name ?? string.Empty,
                    nameFull  = firstGame?.round?.NameFull ?? string.Empty,
                    dateGames = new List <DayGamesShortViewModel>()
                };

                IEnumerable <IGrouping <string, Game> > grouppedGamesByDay =
                    roundGames.GroupBy(g => g.GameDate.ToString("MMM d"));

                foreach (var dayGames in grouppedGamesByDay)
                {
                    var dayGameInfo = dayGames.First();
                    roundView.dateGames.Add(new DayGamesShortViewModel()
                    {
                        date = new DateInfoFormat1()
                        {
                            date       = dayGameInfo.GameDate,
                            dateString = dayGameInfo.GameDate.ToString("d MMMM"),
                            dayString  = dayGameInfo.GameDate.ToString("dddd")
                        },
                        games = dayGames.ToGameShortViewModel()
                    });
                }

                roundViews.Add(roundView);
            }

            return(roundViews);
        }
Esempio n. 2
0
        public static IEnumerable <RoundSliderViewModel> GetRoundsSlider(int teamId, int[] tourneyIds, DateTime date)
        {
            IRoundBll roundBll = MainCfg.ServiceProvider.GetService <IRoundBll>();

            roundBll.FillTourneys = true;
            IEnumerable <int> roundIds = roundBll.GetRoundIdsOfTourneys(tourneyIds, teamId);

            if (Guard.IsEmptyIEnumerable(roundIds))
            {
                return(new RoundSliderViewModel[0]);
            }

            IGameBll gameBll = MainCfg.ServiceProvider.GetService <IGameBll>();

            gameBll.FillTourneys = true;
            gameBll.FillRounds   = true;
            gameBll.FillTeams    = true;

            IEnumerable <Game> roundGames = gameBll.GetTeamActualRoundGames(teamId, roundIds, date);

            if (Guard.IsEmptyIEnumerable(roundGames))
            {
                return(new RoundSliderViewModel[0]);
            }

            var roundsSlider = new List <RoundSliderViewModel>();

            RoundInfoViewModel roundView = roundGames.ToRoundInfoViewModel().FirstOrDefault();

            foreach (int roundId in roundIds)
            {
                roundsSlider.Add(new RoundSliderViewModel()
                {
                    roundId    = roundId,
                    current    = roundView?.roundId == roundId,
                    roundGames = roundView?.roundId == roundId ? roundView : null
                });
            }

            return(roundsSlider);
        }