コード例 #1
0
        public IHttpActionResult Get(bool includeReplies = true, int page = 0, int pageSize = 2)

        {
            IEnumerable <Topic> topics;

            if (includeReplies)
            {
                try {
                    topics = _repo.GetTopicsIncludeReplies().OrderBy(t => t.Id);
                    var totalCount = topics.Count();
                    var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

                    var pager = topics
                                .Skip(pageSize * page)
                                .Take(pageSize)
                                .ToList();

                    var result = new { totalcount = totalCount, totalPages = totalPages, PageSize = pageSize, topics = pager };
                    return(Ok(result));
                }

                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    return(BadRequest());
                }
            }
            else
            {
                topics = _repo.GetTopics().Take(10).ToList();
            }

            return(Ok(topics));
        }