Пример #1
0
        public async Task <IActionResult> ImportResult([RPBinder] IRegisterProvider provider)
        {
            if (provider == null || !provider.JuryOrContestant)
            {
                return(NotFound());
            }
            var context = CreateRegisterProviderContext();

            if (!await provider.IsAvailableAsync(context))
            {
                return(BadRequest());
            }
            ViewBag.Provider = provider;
            ViewBag.Context  = context;
            var model = await provider.CreateInputModelAsync(context);

            await provider.ReadAsync(model, this);

            await provider.ValidateAsync(context, model, ModelState);

            if (ModelState.IsValid)
            {
                var output = await provider.ExecuteAsync(context, model);

                await HttpContext.AuditAsync("import", null, "via " + provider.Name);

                return(Window("ImportResult", output));
            }
            else
            {
                // something got wrong, re-display the form.
                return(Window(model));
            }
        }
Пример #2
0
        public static async Task <IActionResult> PostRegister <T>(
            this ContestControllerBase <T> that,
            IRegisterProvider provider,
            string homePage,
            string registerPage = "Register")
            where T : class, IContestContext
        {
            if (that.Contest.Team != null)
            {
                that.StatusMessage = "Already registered";
                return(that.RedirectToAction(homePage));
            }

            var context = that.CreateRegisterProviderContext();

            if (provider == null ||
                provider.JuryOrContestant ||
                !await provider.IsAvailableAsync(context))
            {
                return(that.NotFound());
            }

            var model = await provider.CreateInputModelAsync(context);

            await provider.ReadAsync(model, that);

            await provider.ValidateAsync(context, model, that.ModelState);

            if (that.ModelState.IsValid)
            {
                var output = await provider.ExecuteAsync(context, model);

                if (output is StatusMessageModel status)
                {
                    if (status.Succeeded)
                    {
                        await that.HttpContext.AuditAsync("created", status.TeamId?.ToString(), "via " + provider.Name);

                        that.StatusMessage = status.Content;
                        return(that.RedirectToAction(homePage));
                    }
                    else
                    {
                        that.StatusMessage = "Error " + status.Content;
                        return(that.RedirectToAction(registerPage));
                    }
                }
                else
                {
                    throw new System.NotImplementedException();
                }
            }

            that.StatusMessage = "Error " + that.ModelState.GetErrorStrings();
            return(that.RedirectToAction(registerPage));
        }