public JsonResult GetSolutionsData(int Page = 1, int PageSize = 25) { int UserID = WebSecurity.CurrentUserId; PaginatedList <Solution> solutions = repository .Solutions .OrderByDescending(s => s.SendTime) .ToPaginatedList <Solution>(Page, PageSize); var response = new JsonResponseSolutionsData(); // Get text view. using (var sw = new StringWriter()) { ViewData["Solutions"] = solutions; repository.ProgrammingLanguages.Each(pl => ViewData[pl.ProgrammingLanguageID.ToString()] = pl.Title); var viewResult = ViewEngines.Engines.FindPartialView(this.ControllerContext, "GetSolutionsData"); var viewContext = new ViewContext(this.ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(this.ControllerContext, viewResult.View); response.HtmlTable = sw.GetStringBuilder().ToString(); } response.Reload = solutions .FirstOrDefault(s => s.Result == TestResults.Waiting || s.Result == TestResults.Executing || s.Result == TestResults.Compiling) != null; return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult GetSolutionsData_ajax(int TournamentID, int ProblemID = -1, int Page = 1, int PageSize = 25) { int userID = WebSecurity.CurrentUserId; // Select problems bound with tournament. IEnumerable <Problem> problems = repository .Problems .Where(p => p.Tournaments.FirstOrDefault(t => t.TournamentID == TournamentID) != null ); if (ProblemID == -1) { ProblemID = problems.First().ProblemID; } Tournament tournament = repository .Tournaments .FirstOrDefault(t => t.TournamentID == TournamentID); Problem problem = repository .Problems .FirstOrDefault(p => p.ProblemID == ProblemID); UserProfile user = repository .Users .FirstOrDefault(u => u.UserId == userID); PaginatedList <Solution> solutions; if ((user != null && (user.CanModifyProblems.Contains(problem) || user.CanModifyTournaments.Contains(tournament))) || Roles.IsUserInRole("Administrator")) { solutions = repository .Solutions .Where(s => (s.Tournament.TournamentID == TournamentID) && (s.Problem.ProblemID == ProblemID) ) .OrderByDescending(s => s.SendTime) .ToPaginatedList <Solution>(Page, PageSize); } else { solutions = repository .Solutions .Where(s => (s.User.UserId == userID) && (s.Tournament.TournamentID == TournamentID) && (s.Problem.ProblemID == ProblemID) ) .OrderByDescending(s => s.SendTime) .ToPaginatedList <Solution>(Page, PageSize); } var response = new JsonResponseSolutionsData(); if (problem == null) { logger.Warn("Problem with id = " + ProblemID + " not found"); throw new HttpException(404, "Problem with id = " + ProblemID + " not found"); } if (tournament == null) { logger.Warn("Tournament with id = " + TournamentID + " not found"); throw new HttpException(404, "Tournament with id = " + TournamentID + " not found"); } // Get text view. using (var sw = new StringWriter()) { ViewData["Solutions"] = solutions; ViewData["TF"] = tournament.Format; ViewData["PT"] = problem.Type; repository.ProgrammingLanguages.Each(pl => ViewData[pl.ProgrammingLanguageID.ToString()] = pl.Title); var viewResult = ViewEngines.Engines.FindPartialView(this.ControllerContext, "GetSolutionsData"); var viewContext = new ViewContext(this.ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(this.ControllerContext, viewResult.View); response.HtmlTable = sw.GetStringBuilder().ToString(); } response.Reload = solutions .FirstOrDefault(s => s.Result == TestResults.Waiting || s.Result == TestResults.Executing || s.Result == TestResults.Compiling) != null; return(Json(response, JsonRequestBehavior.AllowGet)); }