Exemplo n.º 1
0
        /// <summary>
        /// 获取留言
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="cid"></param>
        /// <returns></returns>
        public ActionResult GetMsgs([Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15, int cid = 0)
        {
            int total;

            if (cid != 0)
            {
                int pid    = LeaveMessageService.GetParentMessageIdByChildId(cid);
                var single = LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(pid).ToList();
                if (single.Any())
                {
                    total = 1;
                    foreach (var m in single)
                    {
                        m.PostDate = m.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone));
                    }

                    return(ResultData(new
                    {
                        total,
                        parentTotal = total,
                        page,
                        size,
                        rows = single.Mapper <IList <LeaveMessageViewModel> >()
                    }));
                }
            }
            var parent = LeaveMessageService.GetPagesNoTracking(page, size, m => m.ParentId == 0 && (m.Status == Status.Published || CurrentUser.IsAdmin), m => m.PostDate, false);

            if (!parent.Data.Any())
            {
                return(ResultData(null, false, "没有留言"));
            }
            total = parent.TotalCount;
            var qlist = parent.Data.SelectMany(c => LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(c.Id)).Where(c => c.Status == Status.Published || CurrentUser.IsAdmin).Select(m =>
            {
                m.PostDate = m.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone));
                return(m);
            });

            if (total > 0)
            {
                return(ResultData(new
                {
                    total,
                    parentTotal = total,
                    page,
                    size,
                    rows = Mapper.Map <List <LeaveMessageViewModel> >(qlist)
                }));
            }

            return(ResultData(null, false, "没有留言"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取留言
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="cid"></param>
        /// <returns></returns>
        public ActionResult GetMsgs(int page = 1, int size = 10, int cid = 0)
        {
            int total;

            if (cid != 0)
            {
                int pid    = LeaveMessageService.GetParentMessageIdByChildId(cid);
                var single = LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(pid).ToList();
                if (single.Any())
                {
                    total = 1;
                    return(ResultData(new
                    {
                        total,
                        parentTotal = total,
                        page,
                        size,
                        rows = single.Mapper <IList <LeaveMessageViewModel> >()
                    }));
                }
            }
            var parent = LeaveMessageService.GetPagesNoTracking(page, size, out total, m => m.ParentId == 0 && (m.Status == Status.Pended || CurrentUser.IsAdmin), m => m.PostDate, false);

            if (!parent.Any())
            {
                return(ResultData(null, false, "没有留言"));
            }

            var qlist = parent.AsEnumerable().SelectMany(c => LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(c.Id)).Where(c => c.Status == Status.Pended || CurrentUser.IsAdmin);

            if (total > 0)
            {
                return(ResultData(new
                {
                    total,
                    parentTotal = total,
                    page,
                    size,
                    rows = Mapper.Map <List <LeaveMessageViewModel> >(qlist)
                }));
            }

            return(ResultData(null, false, "没有留言"));
        }