Пример #1
0
        public async Task <IHttpActionResult> FindAllReviews(int activityId, int?id = null,
                                                             int pageIndex          = 1, int pageSize = 10, string orderBy = "Id DESC", string include = null, int?userId = null)
        {
            try
            {
                Pager pager = new Pager()
                {
                    PageSize = pageSize, PageIndex = pageIndex
                };;


                Expression <Func <Review, bool> > Filter = x => !x.IsDeleted;

                Filter = Filter.And(x => x.ActivityId == activityId);

                if (id.HasValue)
                {
                    Filter = Filter.And((x) => x.Id >= id.Value);
                }


                if (userId.HasValue)
                {
                    Filter = Filter.And((x) => x.UserId == userId.Value);
                }


                var docs = await Mgr.FindAll_Async(Filter, orderBy, pager, Helper.ToStringArray(include));


                HttpContext.Current.Response.Headers.Add("access-control-expose-headers", "X-Pager");

                HttpContext.Current.Response.Headers.Add("X-Pager",
                                                         Newtonsoft.Json.JsonConvert.SerializeObject(pager));

                return(Ok(docs));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }