Exemplo n.º 1
0
        public ActionResult Problem(int id, bool official)
        {
            this.ViewBag.IsOfficial  = official;
            this.ViewBag.CompeteType = official ? CompeteActionName : PracticeActionName;

            var problem = this.problemsData.GetWithContestById(id);

            if (problem == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.ContestsGeneral.Problem_not_found);
            }

            this.ValidateContest(problem.Contest, official);

            if (!this.Data.Participants.Any(problem.ContestId, this.UserProfile.Id, official))
            {
                return(this.RedirectToAction("Register", new { id = problem.ContestId, official }));
            }

            if (official &&
                !this.contestsBusiness.IsContestIpValidByContestAndIp(problem.ContestId, this.Request.UserHostAddress))
            {
                return(this.RedirectToAction("NewContestIp", new { id = problem.ContestId }));
            }

            var problemViewModel = new ContestProblemViewModel(problem)
            {
                UserHasAdminRights = this.CheckIfUserHasProblemPermissions(problem.Id)
            };

            return(this.PartialView("_ProblemPartial", problemViewModel));
        }
Exemplo n.º 2
0
 public IActionResult Select([FromForm] ContestProblemViewModel model)
 {
     if (ModelState.IsValid)
     {
         foreach (var item in model.ProblemId)
         {
             var problemContest = new ProblemContest
             {
                 ProblemContestId = Guid.NewGuid(),
                 ContestId        = model.ContestId,
                 ProblemId        = item
             };
             _problemContestRepository.Create(problemContest);
         }
         _problemContestRepository.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(RedirectToAction(nameof(AddProblems), new { id = model.ContestId }));
 }
Exemplo n.º 3
0
        public IActionResult AddProblems(Guid id)
        {
            var problemList = _problemRepository.GetAll();
            var contest     = _contestRepository.GetItem(id);
            var contestBig  = _problemContestRepository.GetListOfProblemForSpecificContest(id).ToList();

            var         problemDtoList = new List <ProblemDto>();
            List <Guid> ids            = new List <Guid>();

            foreach (var item in problemList)
            {
                ids.Add(item.ProblemId);
                problemDtoList.Add(new ProblemDto
                {
                    ProblemId   = item.ProblemId,
                    ProblemName = item.ProblemName
                });
            }

            var existingProblemInContest = new List <ProblemDto>();

            foreach (var item in contestBig)
            {
                existingProblemInContest.Add(new ProblemDto
                {
                    ProblemId   = item.Problem.ProblemId,
                    ProblemName = item.Problem.ProblemName
                });
            }

            var contestproblemViewModel = new ContestProblemViewModel
            {
                ProblemId   = ids,
                Problems    = problemDtoList,
                ContestId   = id,
                ContestName = contest.Title,
                ProblemsForCurrentContest = existingProblemInContest
            };

            return(View(contestproblemViewModel));
        }
Exemplo n.º 4
0
        public ActionResult Problem(int id, bool official)
        {
            this.ViewBag.CompeteType = official ? CompeteUrl : PracticeUrl;

            var problem = this.Data.Problems.GetById(id);

            if (problem == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "Problem not found!");
            }

            ValidateContest(problem.Contest, official);

            if (!this.Data.Participants.Any(problem.ContestId, this.UserProfile.Id, official))
            {
                return(this.RedirectToAction("Register", new { id = problem.ContestId, official }));
            }

            var problemViewModel = new ContestProblemViewModel(problem);

            return(this.PartialView("_ProblemPartial", problemViewModel));
        }