コード例 #1
0
ファイル: ContestsService.cs プロジェクト: spaceorc/judge.net
        public ContestResultViewModel GetResults(int id)
        {
            using (var unitOfWork = this.factory.GetUnitOfWork())
            {
                var contestResultRepository = unitOfWork.ContestResultRepository;
                var contestTaskRepository   = unitOfWork.ContestTaskRepository;
                var contestRepository       = unitOfWork.ContestsRepository;
                var userRepository          = unitOfWork.UserRepository;

                var contest = contestRepository.Get(id);
                var tasks   = contestTaskRepository.GetTasks(id);
                var results = contestResultRepository.Get(id).ToArray();

                var userSpecification = new UserListSpecification(results.Select(o => o.UserId).Distinct());
                var users             = userRepository.Find(userSpecification).ToDictionary(o => o.Id, o => o.UserName);

                var contestFactory = GetFactory(contest.Rules);

                return(contestFactory.Convert(tasks, results, users, contest));
            }
        }
コード例 #2
0
        public SubmitQueueViewModel GetSubmitQueue(long?userId, int page, int pageSize)
        {
            using (var uow = _unitOfWorkFactory.GetUnitOfWork())
            {
                var submitResultRepository = uow.SubmitResultRepository;
                var languageRepository     = uow.LanguageRepository;
                var taskRepository         = uow.TaskRepository;
                var userRepository         = uow.UserRepository;

                var languages = languageRepository.GetLanguages().ToDictionary(o => o.Id, o => o.Name);
                var submits   = submitResultRepository.GetSubmits(AllProblemsSpecification.Instance, page, pageSize).ToArray();

                var userSpecification = new UserListSpecification(submits.Select(o => o.Submit.UserId).Distinct());
                var tasks             = taskRepository.GetTasks(submits.Select(o => o.Submit.ProblemId).Distinct()).ToDictionary(o => o.Id);
                var users             = userRepository.Find(userSpecification).ToDictionary(o => o.Id, o => o.UserName);

                var hasPermission = _principal.IsInRole("admin");

                var items = submits.Select(o => new SubmitQueueItem(o, languages[o.Submit.LanguageId], tasks[o.Submit.ProblemId], users[o.Submit.UserId])
                {
                    ResultsEnabled = userId == o.Submit.UserId || hasPermission
                }).ToArray();

                var count = submitResultRepository.Count(AllProblemsSpecification.Instance);

                var model = new SubmitQueueViewModel(items)
                {
                    Pagination = new ViewModels.PaginationViewModel
                    {
                        CurrentPage = page,
                        PageSize    = pageSize,
                        TotalPages  = (count + pageSize - 1) / pageSize
                    }
                };

                return(model);
            }
        }
コード例 #3
0
ファイル: AdminService.cs プロジェクト: spaceorc/judge.net
        public IEnumerable <SubmitQueueItem> GetSubmitQueue()
        {
            using (var uow = this.factory.GetUnitOfWork())
            {
                var submitResultRepository = uow.SubmitResultRepository;
                var languageRepository     = uow.LanguageRepository;
                var taskRepository         = uow.TaskRepository;
                var userRepository         = uow.UserRepository;
                var contestTaskRepository  = uow.ContestTaskRepository;

                var languages = languageRepository.GetLanguages().ToDictionary(o => o.Id, o => o.Name);
                var submits   = submitResultRepository.GetSubmits(AllSubmitsSpecification.Instance, 1, 100).ToArray();

                var userSpecification = new UserListSpecification(submits.Select(o => o.Submit.UserId).Distinct());
                var tasks             = taskRepository.GetTasks(submits.Select(o => o.Submit.ProblemId).Distinct()).ToDictionary(o => o.Id);
                var users             = userRepository.Find(userSpecification).ToDictionary(o => o.Id, o => o.UserName);

                var contestTasks = contestTaskRepository.GetTasks().ToArray();
                var items        = submits.Select(o => GetSubmitQueueItem(o, languages, users, tasks, contestTasks));

                return(items);
            }
        }