Beispiel #1
0
        public ActionResult List(int id, bool desOrder, bool isChronological = false,
                                 int dateFilterType = Schedules.DateFilterPeriod.BeginningOfMonth,
                                 DateTime?dateFrom  = null, DateTime?dateTo = null, int?inpSeasonId = null)
        {
            var res = new Schedules();

            res.dateFilterType = dateFilterType;
            res.dateFrom       = dateFrom ?? Schedules.FirstDayOfMonth;
            res.dateTo         = dateTo ?? Schedules.Tomorrow;
            var league = leagueRepo.GetById(id);
            var cond   = new GamesRepo.GameFilterConditions
            {
                seasonId    = inpSeasonId ?? leagueRepo.GetById(id).SeasonId ?? seasonsRepository.GetLastSeason().Id,
                auditoriums = new List <AuditoriumShort>(),
                leagues     = new List <LeagueShort>
                {
                    new LeagueShort
                    {
                        Id      = id,
                        UnionId = league.UnionId,
                        Check   = true,
                        Name    = league.Name
                    }
                }
            };

            if (dateFilterType == Schedules.DateFilterPeriod.BeginningOfMonth && isChronological)
            {
                cond.dateFrom = Schedules.FirstDayOfMonth;
                cond.dateTo   = null;
            }
            else if (dateFilterType == Schedules.DateFilterPeriod.Ranged && isChronological)
            {
                cond.dateFrom = dateFrom;
                cond.dateTo   = dateTo;
            }
            else
            {
                cond.dateFrom = null;
                cond.dateTo   = null;
            }
            res.Games = gamesRepo.GetCyclesByFilterConditions(cond,
                                                              User.IsInAnyRole(AppRole.Admins, AppRole.Editors, AppRole.Workers), false)
                        .Select(gc => new GamesInLeague(gc)
            {
                LeagueId    = gc.Stage.LeagueId,
                LeagueName  = gc.Stage.League.Name,
                IsPublished = gc.IsPublished,
            }).ToList();

            if (desOrder)
            {
                res.Games = res.Games.OrderByDescending(x => x.Stage.Number).ToList();
            }

            string alias = string.Empty;

            Session["desOrder"] = desOrder;
            var unionId = league.UnionId;

            if (unionId.HasValue)
            {
                res.Referees = usersRepo.GetUnionAndLeageReferees(unionId.Value, id).ToArray();

                res.Auditoriums = auditoriumsRepo.GetByUnionAndSeason(unionId.Value, cond.seasonId)
                                  .Select(au => new AuditoriumShort
                {
                    Id   = au.AuditoriumId,
                    Name = au.Name
                }).ToArray();

                alias = league.Union.Section?.Alias;
            }

            res.Leagues                = cond.leagues.ToArray();
            res.SeasonId               = cond.seasonId;
            res.UnionId                = unionId;
            res.teamsByGroups          = teamRepo.GetGroupTeamsBySeasonAndLeagues(cond.seasonId, new int[] { league.LeagueId });
            Session["isChronological"] = isChronological;

            switch (alias)
            {
            case GamesAlias.WaterPolo:
            case GamesAlias.BasketBall:
                if (isChronological)
                {
                    return(PartialView("BasketBallWaterPolo/_ChronologicalList", res));
                }
                else
                {
                    return(PartialView("BasketBallWaterPolo/_List", res));
                }

            default:
                if (isChronological)
                {
                    return(PartialView("_ChronologicalList", res));
                }
                else
                {
                    return(PartialView("_List", res));
                }
            }
        }
Beispiel #2
0
        public ActionResult List(Schedules model, int seasonId, int?idUnion = null)
        {
            if (model == null && idUnion != null)
            {
                model = new Schedules()
                {
                    UnionId = (int)idUnion,
                }
            }
            ;
            if (TempData.ContainsKey(leaguesKey) && model.Leagues == null)
            {
                model.Leagues = (LeagueShort[])TempData[leaguesKey];
            }
            if (TempData.ContainsKey(auditoriumsKey) && model.Auditoriums == null)
            {
                model.Auditoriums = (AuditoriumShort[])TempData[auditoriumsKey];
            }

            var res = new Schedules();

            res.UnionId  = model.UnionId;
            res.SeasonId = seasonId;
            res.Games    = new List <GamesInLeague>();
            var leagueShortList = leagueRepo.GetLeaguesFilterList(model.UnionId ?? 0, seasonId);

            if (model.Leagues != null)
            {
                foreach (var league in leagueShortList)
                {
                    if (model.Leagues[0].Check || model.Leagues
                        .Where(l => l.Id == league.Id).Select(l => l.Check).SingleOrDefault())
                    {
                        league.Check = true;
                    }
                }
            }
            //  Fill in auditoriums list
            var auditoriumShortList = auditoriumsRepo.GetAuditoriumsFilterList(model.UnionId ?? 0, seasonId);

            if (model.Auditoriums != null)
            {
                foreach (var aud in auditoriumShortList)
                {
                    if (model.Auditoriums[0].Check || model.Auditoriums
                        .Where(a => a.Id == aud.Id).Select(a => a.Check).SingleOrDefault())
                    {
                        aud.Check = true;
                    }
                }
            }

            //  Fill in games list
            var userIsEditor = User.IsInAnyRole(AppRole.Admins, AppRole.Editors, AppRole.Workers);
            var cond         = new GamesRepo.GameFilterConditions
            {
                seasonId    = seasonId,
                leagues     = leagueShortList,
                auditoriums = auditoriumShortList
            };

            if (model.dateFilterType == Schedules.DateFilterPeriod.BeginningOfMonth)
            {
                cond.dateFrom = Schedules.FirstDayOfMonth;
                cond.dateTo   = null;
            }
            else if (model.dateFilterType == Schedules.DateFilterPeriod.Ranged)
            {
                cond.dateFrom = model.dateFrom;
                cond.dateTo   = model.dateTo;
            }
            else
            {
                cond.dateFrom = null;
                cond.dateTo   = null;
            }
            var result                 = gamesRepo.GetCyclesByFilterConditions(cond, userIsEditor);
            var someLeaguesChecked     = cond.leagues.Any(l => l.Check);
            var allLeaguesChecked      = cond.leagues.All(l => l.Check);
            var someAuditoriumsChecked = cond.auditoriums.Any(a => a.Check);
            var allAuditoriumsChecked  = cond.auditoriums.All(a => a.Check);
            var gamesSelected          = result.Count() > 0;

            if (gamesSelected)
            {
                res.Games = result.Select(gc => new GamesInLeague(gc)
                {
                    LeagueId    = gc.Stage.LeagueId,
                    LeagueName  = gc.Stage.League.Name,
                    IsPublished = gc.IsPublished
                }).ToList();
                var uRepo = new UsersRepo();
                res.Referees = uRepo.GetUnionWorkers(model.UnionId ?? 0, "referee").ToArray();

                // If all games for selected leagues are published
                if (res.Games.All(gc => gc.IsPublished))
                {
                    res.IsPublished = true;
                }
                // If all games for selected leagues aren't published
                else if (res.Games.All(gc => !gc.IsPublished))
                {
                    res.IsPublished = false;
                }
                // If there are published and unpublished games for selected leagues
                else
                {
                    res.IsPublished = null;
                }
            }
            else
            {
                res.IsPublished = false;
            }

            res.Leagues        = leagueShortList.ToArray();
            res.Auditoriums    = auditoriumShortList.ToArray();
            res.dateFilterType = model?.dateFilterType ?? 0;
            res.dateFrom       = model?.dateFrom ?? Schedules.FirstDayOfMonth;
            res.dateTo         = model?.dateTo ?? Schedules.Tomorrow;
            int[] leagueIdArray;
            if (res.Leagues.Any(l => l.Check))
            {
                leagueIdArray = res.Leagues.Where(l => l.Id > 0 && l.Check).Select(l => l.Id).ToArray();
            }
            else
            {
                leagueIdArray = res.Games.Select(g => g.LeagueId).Distinct().ToArray();
            }
            res.teamsByGroups = teamRepo.GetGroupTeamsBySeasonAndLeagues(seasonId, leagueIdArray,
                                                                         gamesSelected && ((allLeaguesChecked || !someLeaguesChecked) &&
                                                                                           (allAuditoriumsChecked || !someAuditoriumsChecked)));
            if (model != null)
            {
                res.Sort = model.Sort;

                if (res.Sort == 1)
                {
                    res.Games = res.Games.OrderBy(x => x.StartDate).ToList();
                }
                if (res.Sort == 2)
                {
                    res.Games = res.Games.OrderBy(x => x.Auditorium != null ? x.Auditorium.Name : "").ToList();
                }
                if (res.Sort == 0)
                {
                    res.Sort = Session["GamesSort"] == null ? 1 : (int)Session["GamesSort"];

                    if (res.Sort == 1)
                    {
                        res.Games = res.Games.OrderBy(x => x.StartDate).ToList();
                    }
                    if (res.Sort == 2)
                    {
                        res.Games = res.Games.OrderBy(x => x.Auditorium != null ? x.Auditorium.Name : "").ToList();
                    }
                }
            }
            Session["GamesSort"]     = res.Sort;
            TempData[leaguesKey]     = res.Leagues;
            TempData[auditoriumsKey] = res.Auditoriums;
            int?unionSection = null;

            if (idUnion.HasValue)
            {
                unionSection = idUnion.Value;
            }
            else if (res.UnionId.HasValue)
            {
                unionSection = res.UnionId.Value;
            }
            if (unionSection.HasValue)
            {
                var section = unionsRepo.GetSectionByUnionId(unionSection.Value);
                switch (section.Alias)
                {
                case GamesAlias.WaterPolo:
                case GamesAlias.BasketBall:
                    return(PartialView("BasketBallWaterpolo/_List", res));

                default:
                    return(PartialView("_List", res));
                }
            }
            return(PartialView("_List", res));
        }