Esempio n. 1
0
        public async Task <IActionResult> SubmitSolutionAsync(int pid, [FromForm] string lang, [FromForm] string code)
        {
            var user = HttpContext.Session.GetString("user");

            if (user is null)
            {
                return(Unauthorized("Not logged in."));
            }
            if (code.Length > maxSolutionSize)
            {
                return(StatusCode(StatusCodes.Status413PayloadTooLarge,
                                  $"Solution size should be less than {maxSolutionSize} bytes."));
            }
            if (!SolutionModel.LangMap.ContainsKey(lang))
            {
                return(BadRequest("No such language."));
            }
            var viewAll = await UserModel.Authorization.CanViewAllProblemsAsync(user);

            if (!viewAll)
            {
                if (await ProblemModel.IsProblemRestrictedAsync(pid))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, "This problem is private now."));
                }
            }
            if (!await ProblemModel.IsProblemExists(pid))
            {
                return(NotFound("No such problem."));
            }
            var submit_id = await SolutionModel.SubmitProblemAsync(user, pid, SolutionModel.LangMap[lang], code);

            return(Ok(submit_id));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetProblemAsync(int pid)
        {
            bool viewAll = await UserModel.Authorization.CanViewAllProblemsAsync(HttpContext.Session.GetString("user"));

            if (!viewAll)
            {
                if (await ProblemModel.IsProblemRestrictedAsync(pid))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, "This problem is private now."));
                }
            }
            var problem = await ProblemModel.GetProblemAsync(pid);

            if (problem is null)
            {
                return(NotFound("No such problem."));
            }
            return(Ok(problem));
        }