public HttpResponseMessage GetCoursesBySubject(int subjectid)
        {
            Learning.Data.LearningContext ctx = null;
            Learning.Data.ILearningRepository repo = null;
            IQueryable<Course> query;

            try
            {
                ctx = new Learning.Data.LearningContext();
                repo = new Learning.Data.LearningRepository(ctx);

                query = repo.GetCoursesBySubject(subjectid);
                var coursesList = query.Select(c => c.Name).ToList();
                if (coursesList != null)
                {
                    return Request.CreateResponse(HttpStatusCode.OK, coursesList);
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }
            finally
            {
                ctx.Dispose();
            }
        }
예제 #2
0
        public List<Course> Get()
        {
            ILearningRepository repository = new LearningRepository(new LearningContext());

            return repository.GetAllCourses().ToList();
        }