public IHttpActionResult GetMarks() { var marks = _repo.GetMarks().Select(c => new MarkDto() { Id = c.Id, MarkValue = c.MarkValue, Importance = c.Importance }); return(Ok(marks)); }
public IHttpActionResult GetStudentsByTeacherId(string id) { if (!TeacherExists(id)) { return(NotFound()); } if (!HasAccesToTeacher(id)) { return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.Forbidden))); } Teacher teacherEntity = _repo.GetTeacherById(id); if (teacherEntity == null) { return(NotFound()); } var students = _repo.GetTeacherStudents(teacherEntity).Select(s => new StudentBasicDto() { Id = s.Id, FirstName = s.FirstName, LastName = s.LastName, Email = s.Email, UserName = s.UserName, PhoneNumber = s.PhoneNumber } ); var attendances = _attendanceRepo.GetAttendances().ToList(); var marks = _markRepo.GetMarks().ToList(); List <StudentBasicDto> studentList = students.ToList(); for (int i = 0; i < studentList.Count; i++) { var attendancesForStudent = new List <Attendance>(); var marksForStudent = new List <Mark>(); var studentBasicDto = studentList[i]; var studentAttendances = attendances.Where(a => a.Student.Id == studentBasicDto.Id).ToList(); attendancesForStudent.AddRange(studentAttendances); studentBasicDto.Attendances = attendancesForStudent.Select(a => new AttendanceDto() { Id = a.Id, WasPresent = a.WasPresent, Lesson = new LessonDto() { Id = a.Lesson != null ? a.Lesson.Id : (int?)null, Date = a.Lesson != null ? a.Lesson.Date : (DateTime?)null } }).ToList(); var studentMarks = marks.Where(a => a.Student.Id == studentBasicDto.Id).ToList(); marksForStudent.AddRange(studentMarks); studentBasicDto.Marks = marksForStudent.Select(m => new MarkDto() { Id = m.Id, Importance = m.Importance, MarkValue = m.MarkValue, Lesson = new LessonDto() { Id = m.Lesson != null ? m.Lesson.Id : (int?)null, Date = m.Lesson != null ? m.Lesson.Date : (DateTime?)null } }).ToList(); studentList[i] = studentBasicDto; } //s.Marks = _repo.GetStudentMarks(s).Select(m => new MarkDto() // { // Importance = m.Importance, // MarkValue = m.MarkValue, // Lesson = new LessonDto() // { // Id = m.Lesson != null ? m.Lesson.Id : (int?)null, // Date = m.Lesson != null ? m.Lesson.Date : (DateTime?)null // } // }), //s.Attendances = _attendanceRepo.GetAttendances()/*.Where(x=> x.Student.Id == s.Id)*/.Select(a => new AttendanceDto() // { // Id = a.Id, // WasPresent = a.WasPresent, // Lesson = new LessonDto() // { // Id = a.Lesson != null ? a.Lesson.Id : (int?)null, // Date = a.Lesson != null ? a.Lesson.Date : (DateTime?)null // } // })); return(Ok(studentList)); }