Beispiel #1
0
        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));
            }
        }
        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);
            }
        }
Beispiel #3
0
        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);
            }
        }