Ejemplo n.º 1
0
        public IHttpActionResult GetFavouriteCourses(int page = 1, int pageSize = 10)
        {
            int userId = JwtAuthManager.GetUserIdFromRequest(Request);
            IQueryable <Course> favCourses = db.Users.Find(userId).Favorites.AsQueryable();
            var coursesPage = Pagination.CreateMappedPage <Course, CourseCard>(
                favCourses, page, pageSize, "Title", true
                );

            return(Ok(coursesPage));
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetCourses([FromUri] CourseFilter courseFilter)
        {
            var queryable = Course.FilterCourses(db.Courses, courseFilter);

            if (courseFilter.Favourites)
            {
                int userId       = JwtAuthManager.GetUserIdFromRequest(Request);
                var favouriteIds = db.Users.Find(userId).Favorites.Select(course => course.Id).ToList();
                queryable = queryable.Where(c => favouriteIds.Contains(c.Id));
            }
            var coursesPage = Pagination.CreateMappedPage <Course, CourseCard>(
                queryable, courseFilter.Page, courseFilter.PageSize, "Title", true
                );

            return(Ok(coursesPage));
        }