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), }); }