public ActionResult Index() { ViewBag.TotalCount = LeaveMessageService.GetQueryNoTracking(m => m.ParentId == 0 && m.Status == Status.Pended).Count(); return(CurrentUser.IsAdmin ? View("Index_Admin") : View()); }
/// <summary> /// 获取留言 /// </summary> /// <param name="page"></param> /// <param name="size"></param> /// <param name="cid"></param> /// <returns></returns> public async Task <ActionResult> GetMsgs([Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15, int?cid = null) { if (cid > 0) { var message = await LeaveMessageService.GetByIdAsync(cid.Value) ?? throw new NotFoundException("留言未找到"); using var layer = LeaveMessageService.GetQueryNoTracking(e => e.GroupTag == message.GroupTag).ToPooledList(); foreach (var m in layer) { m.PostDate = m.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); if (!CurrentUser.IsAdmin) { m.Email = null; m.IP = null; m.Location = null; } } return(ResultData(new { total = 1, parentTotal = 1, page, size, rows = layer.ToTree(e => e.Id, e => e.ParentId).Mapper <IList <LeaveMessageViewModel> >() })); } var parent = await LeaveMessageService.GetPagesAsync(page, size, m => m.ParentId == null && (m.Status == Status.Published || CurrentUser.IsAdmin), m => m.PostDate, false); if (!parent.Data.Any()) { return(ResultData(null, false, "没有留言")); } var total = parent.TotalCount; var tags = parent.Data.Select(c => c.GroupTag).ToArray(); using var messages = LeaveMessageService.GetQueryNoTracking(c => tags.Contains(c.GroupTag)).ToPooledList(); messages.ForEach(m => { m.PostDate = m.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); if (!CurrentUser.IsAdmin) { m.Email = null; m.IP = null; m.Location = null; } }); if (total > 0) { return(ResultData(new { total, parentTotal = total, page, size, rows = messages.OrderByDescending(c => c.PostDate).ToTree(c => c.Id, c => c.ParentId).Mapper <IList <LeaveMessageViewModel> >() })); } return(ResultData(null, false, "没有留言")); }