Пример #1
0
        public async Task <JsonResult> Get(int pageIndex, int pageSize, string pageOrder, int?articleID, string email, sbyte?articleCommentStatus)
        {
            if (pageOrder.Trim() == "ID")
            {
                pageOrder = "LastUpdate desc";
            }
            ArticleCommentStatus?status = null;

            if (articleCommentStatus.HasValue && articleCommentStatus != -1)
            {
                status = (ArticleCommentStatus)articleCommentStatus;
            }
            var list = ArticleComments.Get(pageIndex,
                                           pageSize,
                                           pageOrder,
                                           articleID,
                                           email,
                                           status);

            foreach (var item in list)
            {
                item.UserFullName = item.UserID != null
                                 ? (await UserManager.FindByIdAsync(item.UserID)).Firstname + " " + (await UserManager.FindByIdAsync(item.UserID)).Lastname
                                 : item.UserName;
            }

            int total     = ArticleComments.Count(articleID, email, status);
            int totalPage = (int)Math.Ceiling((decimal)total / pageSize);

            if (pageSize > total)
            {
                pageSize = total;
            }

            if (list.Count < pageSize)
            {
                pageSize = list.Count;
            }

            JsonResult result = new JsonResult()
            {
                Data = new
                {
                    TotalPages = totalPage,
                    PageIndex  = pageIndex,
                    PageSize   = pageSize,
                    Rows       = list
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }