// GET: api/Staffs
        public IHttpActionResult GetStaff([FromUri] StaffFilter staffFilter)
        {
            IQueryable <Staff> queryable = db.Staffs;

            if (!string.IsNullOrEmpty(staffFilter.SearchTerm))
            {
                string lowerCased = staffFilter.SearchTerm.ToLower();
                queryable = queryable.Where(s =>
                                            s.FirstName.ToLower().Contains(lowerCased) ||
                                            s.LastName.ToLower().Contains(lowerCased)
                                            );
            }
            var staffPage = Pagination.CreatePage <Staff>(
                queryable, staffFilter.Page, staffFilter.PageSize, staffFilter.OrderBy, staffFilter.Ascending, Request
                );

            return(Ok(staffPage));
        }
示例#2
0
        public IHttpActionResult GetUsersPaged(int page = 1, int pageSize = 10, string searchTerm = "")
        {
            IQueryable <User> queryable = db.Users;

            if (!string.IsNullOrEmpty(searchTerm))
            {
                string lowerCased = searchTerm.ToLower();
                queryable = queryable.Where(s =>
                                            s.UserDetails.FirstName.ToLower().Contains(lowerCased) ||
                                            s.UserDetails.LastName.ToLower().Contains(lowerCased)
                                            );
            }
            var usersPage = Pagination.CreatePage <User>(
                queryable, page, pageSize, "Email", true, Request
                );

            return(Ok(usersPage));
        }
        public IHttpActionResult GetPostFromCourse(int courseId, int page = 1, int pageSize = 10)
        {
            if (db.Courses.Count(c => c.Id == courseId) == 0)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(
                        string.Format("Cannot retrieve posts. Course with ID = {0} doesn't exist", courseId)
                        )
                };
                throw new HttpResponseException(resp);
            }
            var queryable = db.Posts.Where(p => p.CourseId == courseId);
            var postsPage = Pagination.CreatePage <Post>(
                queryable, page, pageSize, "CreatedAt", false, Request
                );

            return(Ok(postsPage));
        }