Пример #1
0
 public static IActionResult GetPrint <T>(
     this ContestControllerBase <T> that)
     where T : class, IContestContext
 {
     if (!that.Contest.Settings.PrintingAvailable)
     {
         return(that.NotFound());
     }
     return(that.View("Print", new Models.AddPrintModel()));
 }
Пример #2
0
        public static async Task <IActionResult> GetRegister <T>(
            this ContestControllerBase <T> that,
            string homePage)
            where T : class, IContestContext
        {
            if (that.Contest.Team != null)
            {
                that.StatusMessage = "Already registered";
                return(that.RedirectToAction(homePage));
            }

            var context = that.CreateRegisterProviderContext();

            that.ViewBag.Context = context;

            var items = new List <(IRegisterProvider, object)>();

            foreach (var(_, provider) in RPBinderAttribute.Get(that.HttpContext))
            {
                if (provider.JuryOrContestant)
                {
                    continue;
                }
                if (!await provider.IsAvailableAsync(context))
                {
                    continue;
                }
                var input = await provider.CreateInputModelAsync(context);

                items.Add((provider, input));
            }

            if (items.Count == 0)
            {
                that.StatusMessage = "Registration is not for you.";
                return(that.RedirectToAction(homePage));
            }

            return(that.View("Register", items));
        }
Пример #3
0
        public static async Task <IActionResult> DomScoreboard <T>(
            this ContestControllerBase <T> that,
            bool isPublic, bool isJury, bool clear,
            int[] filtered_affiliations, int[] filtered_categories, int?page)
            where T : class, IContestContext
        {
            if (that.Contest.Feature != CcsDefaults.KindDom)
            {
                throw new NotSupportedException();
            }

            var pageVal = that.Contest.ShouldScoreboardPaging()
                ? page ?? 1
                : default(int?);

            that.ViewData["Paging"] = pageVal;
            if (pageVal.HasValue && pageVal < 1)
            {
                return(that.BadRequest());
            }

            if (clear)
            {
                filtered_categories = filtered_affiliations = Array.Empty <int>();
            }
            var scb = await that.Context.GetScoreboardAsync();

            var board = new FullBoardViewModel(scb, isPublic && !isJury, isJury);

            if (filtered_affiliations.Length > 0)
            {
                var aff2 = filtered_affiliations.ToHashSet();
                board.FilteredAffiliations           = aff2;
                that.ViewData["Filter_affiliations"] = aff2;
            }

            if (filtered_categories.Length > 0)
            {
                var cat2 = filtered_categories.ToHashSet();
                board.FilteredCategories           = cat2;
                that.ViewData["Filter_categories"] = cat2;
            }

            if (that.Request.Cookies.TryGetValue("domjudge_teamselection", out var teamselection))
            {
                try
                {
                    var vals = teamselection.AsJson <string[]>();
                    if (vals != null && vals.Length <= 20 && vals.Length > 0)
                    {
                        var teams = new HashSet <int>();
                        for (int i = 0; i < vals.Length; i++)
                        {
                            if (int.TryParse(vals[i], out int teamid))
                            {
                                teams.Add(teamid);
                            }
                        }
                        board.FavoriteTeams = teams;
                    }
                }
                catch
                {
                    // The field `domjudge_teamselection` is wrongly set.
                    that.Response.Cookies.Delete("domjudge_teamselection");
                }
            }

            return(that.View("Scoreboard", board));
        }