Пример #1
0
        public static IList <StandardGradingViewData> Create(IList <GradingStandardInfo> gradingStandards, IList <int> studentIds)
        {
            var gradigDic = gradingStandards.GroupBy(x => x.Standard.Id).ToDictionary(x => x.Key, x => x.ToList());
            var res       = new List <StandardGradingViewData>();

            foreach (var kv in gradigDic)
            {
                var gradingSt       = kv.Value.First();
                var standardGrading = new StandardGradingViewData
                {
                    Standard   = StandardViewData.Create(gradingSt.Standard),
                    NumericAvg = (int?)kv.Value.Average(x => x.NumericGrade),
                    Items      = new List <StandardGradingItemViewData>()
                };
                res.Add(standardGrading);
                foreach (var studentId in studentIds)
                {
                    var gradingInfo = kv.Value.FirstOrDefault(x => x.StudentId == studentId);
                    if (gradingInfo != null)
                    {
                        standardGrading.Items.Add(StandardGradingItemViewData.Create(gradingInfo));
                    }
                }
            }
            return(res);
        }
Пример #2
0
        public static StandardGradingGridViewData Create(GradingPeriod gradingPeriod, IList <GradingStandardInfo> gradingStandardInfos, IList <Student> students)
        {
            var res = new StandardGradingGridViewData
            {
                GradingPeriod = GradingPeriodViewData.Create(gradingPeriod),
                Students      = students.Select(x => GradeStudentViewData.Create(x, x.IsWithdrawn)).ToList()
            };

            gradingStandardInfos = gradingStandardInfos.Where(x => students.Any(y => y.Id == x.StudentId) &&
                                                              gradingPeriod.Id == x.GradingPeriodId).ToList();
            res.GradingItems = StandardGradingViewData.Create(gradingStandardInfos, res.Students.Select(x => x.StudentInfo.Id).ToList());
            if (res.GradingItems.Count > 0)
            {
                res.Avg = (int?)res.GradingItems.Average(x => x.NumericAvg);
            }
            return(res);
        }