/// <summary> /// Return two lists: /// 1) a list of Problems not bound to the tournament /// 2) a list of Problems granted to the tournament /// </summary> /// <param name="userName"></param> /// <returns></returns> public ActionResult BindProblemsToTournament(int TournamentID = -1, int Page = 1, int PageSize = 25, string FilterBy = "all", string SearchTerm = null) { logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" visited TournamentsManagement/Tournament/BindProblemsToTournament"); if (TournamentID == -1) { ManageTournamentsViewModel viewModel = new ManageTournamentsViewModel(); viewModel.FilterBy = FilterBy; viewModel.SearchTerm = SearchTerm; if (System.Web.HttpContext.Current.Request.HttpMethod == "POST") { Page = 1; } if (PageSize == 0) PageSize = 25; viewModel.PageSize = PageSize; if (!string.IsNullOrEmpty(FilterBy)) { if (FilterBy == "all" || string.IsNullOrEmpty(SearchTerm)) { viewModel.PaginatedTournamentList = repository.Tournaments .OrderByDescending(t => t.TournamentID) .ToPaginatedList<Tournament>(Page, PageSize); } else if (!string.IsNullOrEmpty(SearchTerm)) { if (FilterBy == "name") { viewModel.PaginatedTournamentList = repository.Tournaments .Where(t => t.Name.ToLower().IndexOf(SearchTerm.ToLower()) != -1) .OrderByDescending(t => t.TournamentID) .ToPaginatedList<Tournament>(Page, PageSize); } } } return View("ProblemsForTournament", viewModel); } BindProblemsToTournamentViewModel model = new BindProblemsToTournamentViewModel(); Tournament tournament = repository.Tournaments .FirstOrDefault(t => t.TournamentID == TournamentID); if (tournament == null) { logger.Warn("Tournament with id = " + TournamentID + " not found"); throw new HttpException(404, "Tournament not found"); } model.TournamentID = tournament.TournamentID; model.TournamentName = tournament.Name; // AsEnumerable() need, because Except() for IQueryable work in DB // and return 'not supported' (really hard to work) data. if (tournament.Problems != null) { model.AvailableProblems = new SelectList(repository.Problems.AsEnumerable().Except(tournament.Problems).OrderByDescending(p => p.ProblemID), "ProblemID", "Name"); model.BoundProblems = new SelectList(tournament.Problems, "ProblemID", "Name"); } else { model.AvailableProblems = new SelectList(repository.Problems.AsEnumerable().OrderByDescending(p => p.ProblemID), "ProblemID", "Name"); model.BoundProblems = null; } return View(model); }
public ActionResult Index(int Page = 1, int PageSize = 25, string FilterBy = "all", string SearchTerm = null) { logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" visited TournamentsManagement/Tournament/Index"); ManageTournamentsViewModel viewModel = new ManageTournamentsViewModel(); viewModel.FilterBy = FilterBy; viewModel.SearchTerm = SearchTerm; if (System.Web.HttpContext.Current.Request.HttpMethod == "POST") { Page = 1; } if (PageSize == 0) PageSize = 25; viewModel.PageSize = PageSize; if (!string.IsNullOrEmpty(FilterBy)) { if (FilterBy == "all" || string.IsNullOrEmpty(SearchTerm)) { viewModel.PaginatedTournamentList = repository.Tournaments .OrderByDescending(t => t.TournamentID) .ToPaginatedList<Tournament>(Page, PageSize); } else if (!string.IsNullOrEmpty(SearchTerm)) { if (FilterBy == "name") { viewModel.PaginatedTournamentList = repository.Tournaments .Where(t => t.Name.ToLower().IndexOf(SearchTerm.ToLower()) != -1) .OrderByDescending(t => t.TournamentID) .ToPaginatedList<Tournament>(Page, PageSize); } } } return View(viewModel); }