public async Task <IActionResult> GroupCourses() { var role = User.FindFirstValue(ClaimTypes.Role); List <GroupCourse> groupCourses; if (role == "1") { var id = User.FindFirstValue(ClaimTypes.Sid); groupCourses = await groupCourseRepository.GetByLecturer(id); } else { groupCourses = await groupCourseRepository.GetAll(); } return(View(new GroupCoursesViewModel() { GroupCourses = groupCourses })); }
public async Task <List <FinalMarkFeatures> > GetDataForFinal(string groupCourseId) { var groupCourses = new List <GroupCourse>(); if (groupCourseId == null) { groupCourses.AddRange(await groupCourseRepository.GetAll()); } else { groupCourses.Add(await groupCourseRepository.Get(groupCourseId)); } var finalMarkDataList = new List <FinalMarkFeatures>(); foreach (var groupCourse in groupCourses) { var lessons = await lessonRepository.GetByGroupCourse(groupCourse.Id); var students = await studentRepository.GetByGroupId(groupCourse.GroupId); foreach (var student in students) { var finalMarkData = new FinalMarkFeatures { StudentId = student.Id, HasScholarship = student.FullScholarship }; var marks = await markRepository.GetMarksByStudentAndGroupCourse(student.Id, groupCourse.Id); var firstMiddleMark = marks.FirstOrDefault(m => m.Lesson.LessonType == LessonType.FirstMiddle); if (firstMiddleMark != null) { finalMarkData.FirstMiddleMark = !firstMiddleMark.Absent ? firstMiddleMark.Value : 0; } var secondMiddleMark = marks.FirstOrDefault(m => m.Lesson.LessonType == LessonType.SecondMiddle); if (secondMiddleMark != null) { finalMarkData.SecondMiddleMark = !secondMiddleMark.Absent ? secondMiddleMark.Value : 0; } var finalMark = marks.FirstOrDefault(m => m.Lesson.LessonType == LessonType.Final); if (finalMark != null) { finalMarkData.Mark = !finalMark.Absent ? finalMark.Value : 0; } var labMarks = marks.Where(m => m.Lesson.LessonType == LessonType.Lab); var labsCount = labMarks.Count(); finalMarkData.LabsCount = labsCount; if (labsCount > 0) { finalMarkData.LabAbsenceCount = labMarks.Where(m => m.Absent).Count(); finalMarkData.LabMarkCount = labMarks.Where(m => !m.Absent).Count(); if (finalMarkData.LabMarkCount > 0) { finalMarkData.LabMark = (float)labMarks.Where(m => !m.Absent && m.Value != 0).Sum(m => m.Value) / finalMarkData.LabMarkCount; } } var seminarMarks = marks.Where(m => m.Lesson.LessonType == LessonType.Seminar); var seminarsCount = seminarMarks.Count(); finalMarkData.SeminarsCount = seminarsCount; if (seminarsCount > 0) { finalMarkData.SeminarAbsenceCount = seminarMarks.Where(m => m.Absent).Count(); finalMarkData.SeminarMarkCount = seminarMarks.Where(m => !m.Absent).Count(); if (finalMarkData.SeminarMarkCount > 0) { finalMarkData.SeminarMark = (float)seminarMarks.Where(m => !m.Absent && m.Value != 0).Sum(m => m.Value) / finalMarkData.SeminarMarkCount; } } var lectureMarks = marks.Where(m => m.Lesson.LessonType == LessonType.Lecture); var lecturesCount = lectureMarks.Count(); finalMarkData.LecturesCount = lecturesCount; if (lecturesCount > 0) { finalMarkData.LectureAbsenceCount = lectureMarks.Where(m => m.Absent).Count(); finalMarkData.LectureMarkCount = lectureMarks.Where(m => !m.Absent).Count(); if (finalMarkData.LectureMarkCount > 0) { finalMarkData.LectureMark = (float)lectureMarks.Where(m => !m.Absent && m.Value != 0).Sum(m => m.Value) / finalMarkData.LectureMarkCount; } } finalMarkDataList.Add(finalMarkData); } } return(finalMarkDataList); }