예제 #1
0
        public async Task <RatingByLessonDto> GetWorstLessonByMarkByStudentId(int studentId, DateTime startDate, DateTime endDate)
        {
            var today       = DateTime.Today;
            var marksStream = _repository.GetMarksForTimeByStudentId(studentId, startDate, endDate);
            var marks       = new List <Mark>();

            await foreach (var mark in marksStream)
            {
                marks.Add(mark);
            }

            var worstLesson = new RatingByLessonDto();

            foreach (var group in marks.GroupBy(x => x.SubjectId))
            {
                var count = 0;
                var sum   = 0.0;
                foreach (var item in group)
                {
                    count++;
                    sum += item.Grade ?? 0;
                }

                if (count != 0 && (sum / count < worstLesson.Rating || worstLesson.Rating == 0))
                {
                    worstLesson.Rating   = Math.Round((sum / count), 2);
                    worstLesson.LessonId = group.Key;
                    //worstLesson.LessonId = group.FirstOrDefault()?.Subject?.Id;
                }
            }

            return(worstLesson);
        }
예제 #2
0
        public static RatingByLessonViewModel ToViewModel(this RatingByLessonDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(RatingByLessonDto));
            }

            return(new RatingByLessonViewModel
            {
                Rating = dto.Rating,
                LessonId = dto.LessonId
            });
        }