Esempio n. 1
0
        public virtual ActionResult DataTable(string term = "", int page = 0, int count = 10,
                                              Order order = Order.Descending, CommentOrderBy orderBy = CommentOrderBy.AddDate,
                                              CommentSearchBy searchBy = CommentSearchBy.UserName)
        {
            ViewBag.CurrentPage = page;
            ViewBag.Count       = count;


            ViewBag.TERM     = term;
            ViewBag.PAGE     = page;
            ViewBag.COUNT    = count;
            ViewBag.ORDER    = order;
            ViewBag.ORDERBY  = orderBy;
            ViewBag.SEARCHBY = searchBy;

            ViewBag.OrderByList = DropDownList.OrderList(order);
            ViewBag.CountList   = DropDownList.CountList(count);

            var selectListOrderBy = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "AddDate", Text = "تاریخ ارسال"
                },
                new SelectListItem {
                    Value = "IsApproved", Text = "وضعیت"
                },
                new SelectListItem {
                    Value = "LikeCount", Text = "رای ها"
                },
                new SelectListItem {
                    Value = "UserName", Text = "نام کاربری"
                },
                new SelectListItem {
                    Value = "Author", Text = "نویسنده"
                },
                new SelectListItem {
                    Value = "IP", Text = "IP"
                }
            };

            ViewBag.OrderByItems = new SelectList(selectListOrderBy, "Value", "Text", orderBy);


            IList <CommentDataTableModel> model = _commentService.GetDataTable(term, page, count, order, orderBy,
                                                                               searchBy);


            ViewBag.TotalRecords = (string.IsNullOrEmpty(term)) ? _commentService.Count : model.Count;


            foreach (CommentDataTableModel item in model)
            {
                item.AvatarPath = Url.Content("~/Content/Images/user.gif");
            }

            return(PartialView(MVC.Admin.Comment.Views._DataTable, model));
        }
        /// <summary>
        /// Searches the specified key.
        /// </summary>
        /// <param name="keyword">the keyword</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="parentCommentId">The parent comment identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="reportId">The report identifier.</param>
        /// <param name="page">The page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns>
        /// the comments
        /// </returns>
        public async Task <IPagedList <Comment> > Search(
            string keyword         = null,
            CommentOrderBy orderBy = CommentOrderBy.Recent,
            int?parentCommentId    = default(int?),
            int?userId             = null,
            int?reportId           = null,
            int page     = 0,
            int pageSize = int.MaxValue)
        {
            var query = this.commentRepository.Table
                        .Include(c => c.User)
                        .Include(c => c.ParentComment)
                        .Where(c => !c.Deleted);

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(c => c.Value.Contains(keyword));
            }

            ////filters by parent comment
            if (parentCommentId.HasValue)
            {
                query = query.Where(c => c.ParentCommentId == parentCommentId.Value);
            }

            if (userId.HasValue)
            {
                query = query.Where(c => c.UserId == userId.Value);
            }

            if (reportId.HasValue)
            {
                query = query.Where(c => c.ReportId == reportId.Value);
            }

            switch (orderBy)
            {
            case CommentOrderBy.Recent:
            default:
                query = query.OrderByDescending(c => c.CreationDate);
                break;

            case CommentOrderBy.MostCommented:
                query = query.OrderByDescending(c => c.CountSubcomments);
                break;
            }

            return(await new PagedList <Comment>().Async(query, page, pageSize));
        }
Esempio n. 3
0
        public virtual ActionResult DataTable(string term = "", int page = 0, int count = 10,
            Order order = Order.Descending, CommentOrderBy orderBy = CommentOrderBy.AddDate,
            CommentSearchBy searchBy = CommentSearchBy.UserName)
        {
            ViewBag.CurrentPage = page;
            ViewBag.Count = count;


            ViewBag.TERM = term;
            ViewBag.PAGE = page;
            ViewBag.COUNT = count;
            ViewBag.ORDER = order;
            ViewBag.ORDERBY = orderBy;
            ViewBag.SEARCHBY = searchBy;

            ViewBag.OrderByList = DropDownList.OrderList(order);
            ViewBag.CountList = DropDownList.CountList(count);

            var selectListOrderBy = new List<SelectListItem>
            {
                new SelectListItem {Value = "AddDate", Text = "تاریخ ارسال"},
                new SelectListItem {Value = "IsApproved", Text = "وضعیت"},
                new SelectListItem {Value = "LikeCount", Text = "رای ها"},
                new SelectListItem {Value = "UserName", Text = "نام کاربری"},
                new SelectListItem {Value = "Author", Text = "نویسنده"},
                new SelectListItem {Value = "IP", Text = "IP"}
            };

            ViewBag.OrderByItems = new SelectList(selectListOrderBy, "Value", "Text", orderBy);


            IList<CommentDataTableModel> model = _commentService.GetDataTable(term, page, count, order, orderBy,
                searchBy);


            ViewBag.TotalRecords = (string.IsNullOrEmpty(term)) ? _commentService.Count : model.Count;


            foreach (CommentDataTableModel item in model)
            {
                item.AvatarPath = Url.Content("~/Content/Images/user.gif");
            }

            return PartialView(MVC.Admin.Comment.Views._DataTable, model);
        }
Esempio n. 4
0
        public IList <CommentDataTableModel> GetDataTable(string term, int page, int count, Order order
                                                          , CommentOrderBy orderBy, CommentSearchBy searchBy)
        {
            IQueryable <Comment> selectedComments =
                _comments.Include(comment => comment.Post)
                .Include(comment => comment.User).AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (searchBy)
                {
                case CommentSearchBy.UserName:
                    selectedComments =
                        selectedComments.Where(comment => comment.User.UserName.Contains(term)).AsQueryable();
                    break;

                case CommentSearchBy.Author:
                    selectedComments = selectedComments.Where(comment => comment.AnonymousUser
                                                              .Name.Contains(term)).AsQueryable();
                    break;

                case CommentSearchBy.Body:
                    selectedComments = selectedComments.Where(comment => comment.Body.Contains(term)).AsQueryable();
                    break;

                case CommentSearchBy.Ip:
                    selectedComments = selectedComments.Where(comment => comment.User.IP.Contains(term)).
                                       Where(comment => comment.AnonymousUser.IP.Contains(term))
                                       .AsQueryable();
                    break;
                }
            }

            if (order == Order.Asscending)
            {
                switch (orderBy)
                {
                case CommentOrderBy.AddDate:
                    selectedComments = selectedComments.OrderBy(comment => comment.AddedDate).AsQueryable();
                    break;

                case CommentOrderBy.IsApproved:
                    selectedComments = selectedComments.OrderBy(comment => comment.IsApproved).AsQueryable();
                    break;

                case CommentOrderBy.LikeCount:
                    selectedComments = selectedComments.OrderBy(comment => comment.LikeCount).AsQueryable();
                    break;

                case CommentOrderBy.UserName:
                    selectedComments = selectedComments.OrderBy(comment => comment.User.UserName).AsQueryable();
                    break;

                case CommentOrderBy.Author:
                    selectedComments = selectedComments.OrderBy(comment => comment.AnonymousUser.Name).AsQueryable();
                    break;

                case CommentOrderBy.Ip:
                    selectedComments = selectedComments.OrderBy(comment => comment.User.IP)
                                       .ThenBy(comment => comment.AnonymousUser.IP).AsQueryable();
                    break;
                }
            }
            else
            {
                switch (orderBy)
                {
                case CommentOrderBy.AddDate:
                    selectedComments =
                        selectedComments.OrderByDescending(comment => comment.AddedDate).AsQueryable();
                    break;

                case CommentOrderBy.IsApproved:
                    selectedComments =
                        selectedComments.OrderByDescending(comment => comment.IsApproved).AsQueryable();
                    break;

                case CommentOrderBy.LikeCount:
                    selectedComments =
                        selectedComments.OrderByDescending(comment => comment.LikeCount).AsQueryable();
                    break;

                case CommentOrderBy.UserName:
                    selectedComments =
                        selectedComments.OrderByDescending(comment => comment.User.UserName).AsQueryable();
                    break;

                case CommentOrderBy.Author:
                    selectedComments =
                        selectedComments.OrderByDescending(comment => comment.AnonymousUser.Name).AsQueryable();
                    break;

                case CommentOrderBy.Ip:
                    selectedComments = selectedComments.OrderByDescending(comment => comment.User.IP)
                                       .ThenByDescending(comment => comment.AnonymousUser.IP)
                                       .AsQueryable();
                    break;
                }
            }

            return(selectedComments.Skip(page * count).Take(count).Select(comment => new CommentDataTableModel
            {
                AddDate = comment.AddedDate,
                AuthorName = comment.AnonymousUser.Name,
                Body = comment.Body,
                Id = comment.Id,
                PostTitle = comment.Post.Title,
                AuthorId = comment.AnonymousUser.Id,
                UserName = comment.User.UserName,
                IsApproved = comment.IsApproved,
                LikeCount = comment.LikeCount,
                PostId = comment.Post.Id,
                UserId = comment.User.Id
            }).ToList());
        }
Esempio n. 5
0
        public IList<CommentDataTableModel> GetDataTable(string term, int page, int count, Order order
            , CommentOrderBy orderBy, CommentSearchBy searchBy)
        {
            IQueryable<Comment> selectedComments =
                _comments.Include(comment => comment.Post)
                    .Include(comment => comment.User).AsQueryable();
            if (!string.IsNullOrEmpty(term))
            {
                switch (searchBy)
                {
                    case CommentSearchBy.UserName:
                        selectedComments =
                            selectedComments.Where(comment => comment.User.UserName.Contains(term)).AsQueryable();
                        break;
                    case CommentSearchBy.Author:
                        selectedComments = selectedComments.Where(comment => comment.AnonymousUser
                            .Name.Contains(term)).AsQueryable();
                        break;
                    case CommentSearchBy.Body:
                        selectedComments = selectedComments.Where(comment => comment.Body.Contains(term)).AsQueryable();
                        break;
                    case CommentSearchBy.Ip:
                        selectedComments = selectedComments.Where(comment => comment.User.IP.Contains(term)).
                            Where(comment => comment.AnonymousUser.IP.Contains(term))
                            .AsQueryable();
                        break;
                }
            }

            if (order == Order.Asscending)
            {
                switch (orderBy)
                {
                    case CommentOrderBy.AddDate:
                        selectedComments = selectedComments.OrderBy(comment => comment.AddedDate).AsQueryable();
                        break;
                    case CommentOrderBy.IsApproved:
                        selectedComments = selectedComments.OrderBy(comment => comment.IsApproved).AsQueryable();
                        break;
                    case CommentOrderBy.LikeCount:
                        selectedComments = selectedComments.OrderBy(comment => comment.LikeCount).AsQueryable();
                        break;
                    case CommentOrderBy.UserName:
                        selectedComments = selectedComments.OrderBy(comment => comment.User.UserName).AsQueryable();
                        break;
                    case CommentOrderBy.Author:
                        selectedComments = selectedComments.OrderBy(comment => comment.AnonymousUser.Name).AsQueryable();
                        break;
                    case CommentOrderBy.Ip:
                        selectedComments = selectedComments.OrderBy(comment => comment.User.IP)
                            .ThenBy(comment => comment.AnonymousUser.IP).AsQueryable();
                        break;
                }
            }
            else
            {
                switch (orderBy)
                {
                    case CommentOrderBy.AddDate:
                        selectedComments =
                            selectedComments.OrderByDescending(comment => comment.AddedDate).AsQueryable();
                        break;
                    case CommentOrderBy.IsApproved:
                        selectedComments =
                            selectedComments.OrderByDescending(comment => comment.IsApproved).AsQueryable();
                        break;
                    case CommentOrderBy.LikeCount:
                        selectedComments =
                            selectedComments.OrderByDescending(comment => comment.LikeCount).AsQueryable();
                        break;
                    case CommentOrderBy.UserName:
                        selectedComments =
                            selectedComments.OrderByDescending(comment => comment.User.UserName).AsQueryable();
                        break;
                    case CommentOrderBy.Author:
                        selectedComments =
                            selectedComments.OrderByDescending(comment => comment.AnonymousUser.Name).AsQueryable();
                        break;
                    case CommentOrderBy.Ip:
                        selectedComments = selectedComments.OrderByDescending(comment => comment.User.IP)
                            .ThenByDescending(comment => comment.AnonymousUser.IP)
                            .AsQueryable();
                        break;
                }
            }

            return selectedComments.Skip(page * count).Take(count).Select(comment => new CommentDataTableModel
            {
                AddDate = comment.AddedDate,
                AuthorName = comment.AnonymousUser.Name,
                Body = comment.Body,
                Id = comment.Id,
                PostTitle = comment.Post.Title,
                AuthorId = comment.AnonymousUser.Id,
                UserName = comment.User.UserName,
                IsApproved = comment.IsApproved,
                LikeCount = comment.LikeCount,
                PostId = comment.Post.Id,
                UserId = comment.User.Id
            }).ToList();
        }