public async Task <JudgingPageModel> BuildJudgingPageModel(JudgeEntity judge, JudgingType type)
        {
            var model = new JudgingPageModel {
                Judge = judge, Type = type
            };

            var projectsE = await ProjectsRepo.GetAll(p =>
                                                      p.Category == judge.Category && (type == JudgingType.Project || p.IsInOpen));

            model.Category = judge.Category;
            model.Projects = Mapper.Map <List <ProjectViewModel> >(projectsE);

            var sections = await SectionsRepo.GetAll(s => s.Category == model.Category && s.Type == type);

            foreach (var section in sections)
            {
                section.Criteria = section.Criteria.OrderBy(c => c.Name).ToList();
            }

            model.JudgingSections = Mapper.Map <List <JudgingCriteriaSectionViewModel> >(sections);

            model.InitialPoints = Mapper.Map <List <ProjectJudgingCriterionPointsViewModel> >(
                await PointsRepo.GetAll(p =>
                                        p.Judge == model.Judge && p.Criterion.Type == type));


            return(model);
        }
 public async Task <List <ProjectResultsModel> > GetProjectsPointsTypeForCategory(string categoryId,
                                                                                  JudgingType type)
 {
     return(await(
                from project in ProjectsRepo.DbSet.Where(p => p.Category.Id == categoryId)
                join points in PointsRepo.DbSet.Where(p =>
                                                      p.Criterion.Type == type) on project equals
                points.Project into pointsProjects
                from pointsProject in pointsProjects.DefaultIfEmpty()
                group pointsProject by new { project.Id, project.Title }
                into grouped
                select new ProjectResultsModel
     {
         TotalProjectPoints = grouped.Sum(p => p.Points),
         ProjectId = grouped.Key.Id,
         ProjectTitle = grouped.Key.Title
     }
                ).ToListAsync());
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Judging([FromRoute][Optional] JudgingType type)
        {
            var model = await JudgingService.BuildJudgingPageModel(await GetJudgeProfileOrThrow(), type);

            return(View(model));
        }