Пример #1
0
        public async Task <object> GetProblemCountAsync()
        {
            var viewAll = await UserModel.Authorization.CanViewAllProblemsAsync(HttpContext.Session.GetString("user"));

            var problemCount = await ProblemModel.GetProblemsCountAsync(viewAll);

            var maxPageCount = (problemCount + problemsPerPage - 1) / problemsPerPage;

            return(new
            {
                TotalPages = maxPageCount,
                ProblemCount = problemCount,
            });
        }
Пример #2
0
        public async Task <object> GetProblemListAsync(int page)
        {
            if (page <= 0)
            {
                return(BadRequest());
            }
            bool viewAll = await UserModel.Authorization.CanViewAllProblemsAsync(HttpContext.Session.GetString("user"));

            int maxPageCount = (await ProblemModel.GetProblemsCountAsync(viewAll) + problemsPerPage - 1) / problemsPerPage;

            if (page > maxPageCount)
            {
                return(NotFound("I don't have so many problems..."));
            }
            return(new
            {
                TotalPages = maxPageCount,
                ProblemList = await ProblemModel.GetProblemListAsync((page - 1) *problemsPerPage, problemsPerPage, viewAll),
            });
        }