public ActionResult Index(CommentSearchModel model, string message = null, string method = null, int[] commentIds = null)
        {
            if (method != null)
            {
                if (method.Equals("Trash"))
                    return TrashList(commentIds);
                else if (method.Equals("Delete"))
                    return DeleteList(commentIds);
                else if (method.Equals("UnTrash"))
                    return UnTrashList(commentIds);
            }

            ViewBag.Message = message;
            int pageSize = int.Parse(_settingService.GetSetting("AdminCommentPageSize"));
            if (model.PageSize != null && model.PageSize > 0 && model.PageSize != pageSize)
            {
                _settingService.SetSetting("AdminCommentPageSize", model.PageSize.ToString());
            }
            else
            {
                model.PageSize = pageSize;
            }
            PageInfo<Comment> pageInfo = new PageInfo<Comment>();
            int count = (int)_commentService.Single(query => BulidCommentQuery(query, model).Count());

            pageInfo.TotalItem = count;
            pageInfo.PageSize = model.PageSize.Value;

            model.PageIndex = model.PageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : model.PageIndex;
			model.PageIndex = model.PageIndex < 1 ? 1 : model.PageIndex;
            
			IList<Comment> list = _commentService.Find(query => BulidCommentQuery(query, model).OrderByDescending(c => c.CreateDate).Skip((model.PageIndex - 1) * model.PageSize.Value).Take(model.PageSize.Value));
            pageInfo.PageItems = list;
            model.PageInfo = pageInfo;

            model.AllCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open) || (c.Status == CommentStatus.Verify)).Count());
            model.OpenCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open)).Count());
            model.VerifyCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Verify)).Count());
            model.DeleteCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Delete)).Count());


            IDictionary<int, int> VerifyComment = new Dictionary<int, int>();
            foreach (Comment comment in model.PageInfo)
            {
                if (!VerifyComment.ContainsKey(comment.Article.ArticleId))
                    VerifyComment[comment.Article.ArticleId] = (int)_commentService.GetCommentSingle(query => query.Where(c => c.Article.Type == ArticleType.Blog && c.Article.ArticleId == comment.Article.ArticleId && c.Status == CommentStatus.Verify).Count());
            }
            ViewBag.VerifyComment = VerifyComment;
            return View(model);
        }
 public CommentSearchModel Build(int pageIndex = 0)
 {
     CommentSearchModel model = new CommentSearchModel()
     {
         pageIndex = this.pageIndex,
         Status = Status,
         Search = Search,
         PageSize = PageSize,
         IpAddress = IpAddress
     };
     if (pageIndex != 0)
     {
         model.pageIndex = pageIndex;
     }
     return model;
 }
示例#3
0
        public CommentSearchModel Build(int pageIndex = 0)
        {
            CommentSearchModel model = new CommentSearchModel()
            {
                pageIndex = this.pageIndex,
                Status    = Status,
                Search    = Search,
                PageSize  = PageSize,
                IpAddress = IpAddress
            };

            if (pageIndex != 0)
            {
                model.pageIndex = pageIndex;
            }
            return(model);
        }
        public IQueryable<Comment> BulidCommentQuery(IQueryable<Comment> query, CommentSearchModel model)
        {
            if (!string.IsNullOrEmpty(model.Search))
            {
                query = query.Where(c => c.Author.Contains(model.Search) || c.Content.Contains(model.Search));
            }

            if (!string.IsNullOrEmpty(model.IpAddress))
            {
                query = query.Where(c => c.AuthorIP == model.IpAddress);
            }

            if (model.Status == null)
            {
                query = query.Where(c => c.Status == CommentStatus.Open || c.Status == CommentStatus.Verify);
            }
            else
            {
                query = query.Where(c => c.Status == model.Status);
            }

            return query;
        }