public GetCoursesByInstructorResponse GetCoursesByInstructor(GetCoursesByInstructorRequest request) { string sqlcourse = @"select c.id,c.title,c.description,c.rating,c.price,ins.fullname as instructorName,cat.name as categoryName,fr.name as frameworkName from course as c inner join instructor as ins on c.instructorId = ins.id inner join category as cat on c.categoryId = cat.categoryId inner join framework as fr on c.frameworkId = fr.frameworkId Where ins.id=@id"; string sqlins = @"select * from instructor where id=@id"; var parameters = new { id = request.InstructorId }; using (var con = GetSqlConnection()) { var courses = con.Query <CourseResponse>(sqlcourse, parameters); var instructors = con.Query <Instructor>(sqlins, parameters).FirstOrDefault(); return(new GetCoursesByInstructorResponse { Instructor = instructors, Courses = courses.ToList() }); } }
public void GetCoursesByInstructor() { var request = new GetCoursesByInstructorRequest { InstructorId = 2, }; var res = service.GetCoursesByInstructor(request); Xunit.Assert.NotNull(res.Instructor); Xunit.Assert.True(res.Courses.ToList().Count > 0); }
public HttpResponseMessage GetCoursesByInstructor([FromBody] GetCoursesByInstructorRequest request) { var response = _service.FetchCoursesByInstructor(request); if (response.Instructor != null && response.Courses != null) { return(Request.CreateResponse <GetCoursesByInstructorResponse>(HttpStatusCode.OK, response)); } else if (response.Instructor != null && response.Courses == null) { return(Request.CreateErrorResponse(HttpStatusCode.NoContent, "This instructor has no courses")); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Something went wrong...")); } }
public GetCoursesByInstructorResponse FetchCoursesByInstructor(GetCoursesByInstructorRequest request) { _validation.NotValidId(request.InstructorId, $"{nameof(request.InstructorId)}"); return(_dbService.GetCoursesByInstructor(request)); }