Exemplo n.º 1
0
        /// <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 BindTournamentsToProblem(int ProblemID = -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 ProblemsManagement/Problem/BindTournamentsToProblem");

            if (ProblemID == -1)
            {
                ManageProblemsViewModel viewModel = new ManageProblemsViewModel();
                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.PaginatedProblemList = repository.Problems
                                .OrderByDescending(p => p.ProblemID)
                                .ToPaginatedList<Problem>(Page, PageSize);
                    }
                    else if (!string.IsNullOrEmpty(SearchTerm))
                    {
                        if (FilterBy == "name")
                        {
                            viewModel.PaginatedProblemList = repository.Problems
                                .Where(p => p.Name.ToLower().IndexOf(SearchTerm.ToLower()) != -1)
                                .OrderByDescending(p => p.ProblemID)
                                .ToPaginatedList<Problem>(Page, PageSize);
                        }
                    }
                }
                return View("TournamentsForProblem", viewModel);
            }

            BindTournamentsToProblemViewModel model = new BindTournamentsToProblemViewModel();
            Problem problem = repository.Problems
                .FirstOrDefault(p => p.ProblemID == ProblemID);
            if (problem == null)
            {
                logger.Warn("Problem with id = " + ProblemID + " not found");
                throw new HttpException(404, "Problem not found");
            }

            model.ProblemID = problem.ProblemID;
            model.ProblemName = problem.Name;

            // AsEnumerable() need, because Except() for IQueryable work in DB.
            if (problem.Tournaments != null)
            {

                model.AvailableTournaments = new SelectList(repository.Tournaments.AsEnumerable().Except(problem.Tournaments).OrderByDescending(t => t.TournamentID), "TournamentID", "Name");
                model.BoundTournaments = new SelectList(problem.Tournaments, "TournamentID", "Name");
            }
            else
            {
                model.AvailableTournaments = new SelectList(repository.Tournaments.AsEnumerable().OrderByDescending(t => t.TournamentID), "TournamentID", "Name");
                model.BoundTournaments = null;
            }

            return View(model);
        }
Exemplo n.º 2
0
        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 ProblemsManagement/Problem/Index");

            ManageProblemsViewModel viewModel = new ManageProblemsViewModel();
            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.PaginatedProblemList = repository.Problems
                            .OrderByDescending(p => p.ProblemID)
                            .ToPaginatedList<Problem>(Page, PageSize);
                }
                else if (!string.IsNullOrEmpty(SearchTerm))
                {
                    if (FilterBy == "name")
                    {
                        viewModel.PaginatedProblemList = repository.Problems
                            .Where(p => p.Name.ToLower().IndexOf(SearchTerm.ToLower()) != -1)
                            .OrderByDescending(p => p.ProblemID)
                            .ToPaginatedList<Problem>(Page, PageSize);
                    }
                }
            }

            return View(viewModel);
        }