Example #1
0
        private CourseReadDTO MapToCourseReadDTO(Course course)
        {
            CourseReadDTO courseData = new CourseReadDTO
            {
                Id      = course.Id,
                Title   = course.Title,
                Teacher = new TeacherBasicDetailDTO
                {
                    Id        = course.Teacher.Id,
                    FirstName = course.Teacher.FirstName,
                    LastName  = course.Teacher.LastName,
                    Gender    = course.Teacher.Gender,
                    Salary    = course.Teacher.Salary,
                    StaffId   = course.Teacher.StaffId
                },
                Subject     = course.Subject.ToString(),
                CourseId    = course.CourseId,
                CourseLevel = course.CourseLevel.ToString()
            };

            courseData.Students = context.Enrollments
                                  .Where(e => e.CourseId == course.Id)
                                  .Select(e => new StudentBasicDetailDTO
            {
                Id        = e.Student.Id,
                FirstName = e.Student.FirstName,
                LastName  = e.Student.LastName
            })
                                  .ToList();

            return(courseData);
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <CourseReadDTO> > > GetCourses()
        {
            var courses = context.Courses
                          .Include(c => c.Teacher)
                          .ToList();

            var coursesData = new List <CourseReadDTO>();

            foreach (var course in courses)
            {
                CourseReadDTO courseData = MapToCourseReadDTO(course);

                coursesData.Add(courseData);
            }

            return(coursesData);
        }
Example #3
0
        public async Task <ActionResult <IEnumerable <CourseReadDTO> > > SearchCourses(string query)
        {
            var courses = await context.Courses
                          .Where(c => c.Title.Contains(query))
                          .Include(c => c.Teacher)
                          .ToListAsync();

            var coursesData = new List <CourseReadDTO>();

            if (courses.Count > 0)
            {
                foreach (var course in courses)
                {
                    CourseReadDTO courseData = MapToCourseReadDTO(course);

                    coursesData.Add(courseData);
                }
            }

            return(coursesData);
        }
Example #4
0
        public async Task <List <CourseReadDTO> > GetCoursesBySubject(Subject subject)
        {
            var courses = context.Courses
                          .Where(c => c.Subject == subject)
                          .Include(c => c.Teacher)
                          .ToList();

            var coursesData = new List <CourseReadDTO>();

            if (courses.Count > 0)
            {
                foreach (var course in courses)
                {
                    CourseReadDTO courseData = MapToCourseReadDTO(course);

                    coursesData.Add(courseData);
                }
            }

            return(coursesData);
        }