コード例 #1
0
        // GET: Comments
        public ActionResult Index([FromQuery] CommentSearch commentSearch)
        {
            commentSearch.PageNumber = 0;
            var comments = _searchCommentsCommand.Execute(commentSearch);

            return(View(comments.Data));
        }
コード例 #2
0
        public PagedResponse <CommentDto> Execute(CommentSearch search)
        {
            var query = _context.Comments.AsQueryable();

            if (!string.IsNullOrEmpty(search.Username) || !string.IsNullOrWhiteSpace(search.Username))
            {
                query = query.Where(x => x.User.Username.ToLower().Contains(search.Username.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);
            var response  = new PagedResponse <CommentDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new CommentDto
                {
                    text      = x.Text,
                    ArticleId = x.ArticleId,
                    UserId    = x.UserId,
                    User      = new UserDto
                    {
                        Username = x.User.Username
                    }
                }).ToList()
            };

            return(response);
        }
コード例 #3
0
        public IEnumerable <GetCommentDto> Execute(CommentSearch request)
        {
            var query = context.Comments.Include(x => x.ApplicationUser).AsQueryable();

            if (request.TextKeyword != null)
            {
                query = query.Where(x => x.Text.ToLower().Contains(request.TextKeyword.ToLower()));
            }

            if (request.ApplicationUserId != null)
            {
                query = query.Where(x => x.ApplicationUserId == request.ApplicationUserId);
            }

            if (request.TicketId != null)
            {
                query = query.Where(x => x.TicketId == request.TicketId);
            }

            if (request.OnlyActive != null)
            {
                if (request.OnlyActive == true)
                {
                    query = query.Where(x => x.DeletedAt == null);
                }
            }

            query = query.SkipItems(request.Page, request.ItemsPerPage);

            return(query.Select(x => _mapper.Map <Comment, GetCommentDto>(x)).ToList());
        }
コード例 #4
0
ファイル: ArticleController.cs プロジェクト: szp11/HGShareBBS
        /// <summary>
        /// 详细页
        /// </summary>
        /// <returns></returns>
        public ActionResult Detail(CommentSearch search)
        {
            var model = new ArticleWebEntity
            {
                //public中是实时数据
                Article =
                    UserIsLogin
                        ? ArticlesPublic.GetArticleInfoById((int)search.AId)
                        : Articles.GetArticleInfoById((int)search.AId)
            };



            if (model.Article == null || model.Article.IsNull)
            {
                return(new RedirectResult(Url.Action("Tip404", "Tips")));
            }

            //非审核通过的帖子,只能自己看
            if ((model.Article.State != 1) && (CurrentUserInfo == null || CurrentUserInfo.Id != model.Article.UserId))
            {
                return(new RedirectResult(Url.Action("Tip404", "Tips")));
            }

            model.User = Users.GetUserById(model.Article.UserId);
            ViewData["HeadNavCurrent"] = model.Article.Type;
            model.CommentSearch        = search;

            return(View(model));
        }
コード例 #5
0
        public PagedResponse <GetCommentDto> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.Active.HasValue)
            {
                query = query.Where(c => c.IsDeleted != request.Active);
            }
            else
            {
                query = query.Where(c => c.IsDeleted == false);
            }


            if (request.UserId.HasValue)
            {
                if (!Context.Users.Any(u => u.Id == request.UserId))
                {
                    throw new EntityNotFoundException("User");
                }
                query = query.Where(c => c.UserId == request.UserId);
            }

            if (request.PostId.HasValue)
            {
                if (!Context.Posts.Any(p => p.Id == request.PostId))
                {
                    throw new EntityNotFoundException("Post");
                }
                query = query.Where(c => c.PostId == request.PostId);
            }


            var totalCount = query.Count();

            query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);


            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);


            var response = new PagedResponse <GetCommentDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(c => new GetCommentDto
                {
                    Id      = c.Id,
                    Comment = c.Text,
                    User    = c.User.Username,
                    Post    = c.Post.Title,
                })
            };

            return(response);
        }
コード例 #6
0
 /// <summary>
 /// Sets the WorkoutSearch object with the stored session search variables if they exist
 /// </summary>
 /// <param name="search">The WorkoutSearch object to set</param>
 /// <returns>The WorkoutSearch object set with the session search variables if the session exists, else the passed in WorkoutSearch object</returns>
 private CommentSearch setSearchFromSession(CommentSearch search)
 {
     if (Session != null)
     {
         search.message  = Session["MessageSearchParam"] as String;
         search.username = Session["UsernameSearchParam"] as String;
     }
     return(search);
 }
コード例 #7
0
        public PagedResponse <CommentDto> Execute(CommentSearch search)
        {
            var query = context.Comments.Include(c => c.User).Include(u => u.Post).AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Text.ToLower().Contains(search.Name.ToLower()));
            }
            return(query.Paged <CommentDto, Domain.Entities.Comment>(search, mapper));
        }
コード例 #8
0
 public IActionResult Get([FromQuery] CommentSearch obj)
 {
     try
     {
         var comments = _getComment.Execute(obj);
         return(Ok(comments));
     }
     catch
     {
         return(StatusCode(500));
     }
 }
コード例 #9
0
 public IActionResult Get([FromQuery] CommentSearch search)
 {
     try
     {
         var dto = _getCommentsCommand.Execute(search);
         return(Ok(dto));
     }
     catch (EntityNotFoundException)
     {
         return(Conflict("There's no data for your request."));
     }
 }
コード例 #10
0
        public void Delete(CommentSearch request)
        {
            var matches = Get(request) as List <Comment>;

            if (true != matches?.Any())
            {
                throw new HttpError(HttpStatusCode.NotFound, "No matches for request");
            }
            matches.ForEach(match =>
            {
                Delete(match);
            });
        }
コード例 #11
0
        public void Initialize()
        {
            DbContextHelpers contextHelpers = new DbContextHelpers();

            search = new CommentSearch();

            db       = contextHelpers.getDbContext();
            adminCon = new AdminCommentsController(db.Object)
            {
                // sign in as admin
                ControllerContext = MockContext.AuthenticationContext("admin")
            };
        }
コード例 #12
0
        // GET: AdminComments
        public ActionResult Index(string filterString, string sortBy, int?page, CommentSearch commentSearch)
        {
            //var comments = db.comments.Include(c => c.user).Include(c => c.workout);
            //return View(comments.ToList());
            var comments = from c in db.comments select c;

            comments = this.doSearch(comments, commentSearch, filterString, sortBy, page);
            comments = this.doSort(comments, sortBy);

            int pageNumber = (page ?? 1);
            var view       = View("Index", comments.ToPagedList(pageNumber, pageSize));

            return(view);
        }
コード例 #13
0
        public IEnumerable <CommentDTO> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.Comment != null)
            {
                query = query.Where(c => c.CommentText.ToLower().Contains(request.Comment.ToLower()));
            }

            return(query.Select(c => new CommentDTO
            {
                Id = c.Id,
                CommentText = c.CommentText
            }));
        }
コード例 #14
0
 public ActionResult <IEnumerable <GetCommentDto> > Get([FromQuery] CommentSearch search)
 {
     try
     {
         var comments = _getCommand.Execute(search);
         return(Ok(comments));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error has occurred."));
     }
 }
コード例 #15
0
 public ActionResult <IEnumerable <CreateCommentDto> > Get([FromQuery] CommentSearch cs)
 {
     try
     {
         var comments = _getAll.Execute(cs);
         return(Ok(comments));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
コード例 #16
0
ファイル: CommentController.cs プロジェクト: szp11/HGShareBBS
        /// <summary>
        ///
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public PartialViewResult Index(CommentSearch search)
        {
            string order = search.Order == 0 ? "ASC" : "DESC";

            if (search.PageIndex < 1)
            {
                search.PageIndex = 1;
            }
            int pageSize  = Site.Config.PageConfig.WebCommentPageSize;
            int dataCount = 0;
            var list      = new List <CommentEntity>();
            var comments  = Comments.GetComments(search.PageIndex, pageSize, search.AId, search.AuthorId, order, out dataCount);

            if (comments != null)
            {
                var users = Users.GetUsersByIds(comments.Select(n => n.UserId).ToArray());
                foreach (var comment in comments)
                {
                    var user = new UserVModel();
                    if (users.Any(n => n.Id == comment.UserId))
                    {
                        user = users.FirstOrDefault(n => n.Id == comment.UserId);
                    }
                    list.Add(new CommentEntity
                    {
                        Comment = comment,
                        User    = user
                    });
                }
            }
            PagedList <CommentEntity> pageList = list.ToPagedList(search.PageIndex, pageSize);

            pageList.TotalItemCount   = dataCount;
            pageList.CurrentPageIndex = search.PageIndex;
            //如果登录的话取得登录用户对该帖子下所有评论的点赞记录
            if (UserIsLogin)
            {
                List <long> commentIds = DianZanLogsPublic.GetUserAllDianZanCommentId(CurrentUserInfo.Id, search.AId);
                if (commentIds.Count > 0)
                {
                    pageList.ForEach(c => c.IsZan = commentIds.Any(n => n == c.Comment.Id));
                }
            }
            ViewBag.search = search;
            return(PartialView(pageList));
        }
コード例 #17
0
        public PagedResponse <CommentDto> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.Text != null)
            {
                query = query.Where(c => c.Text.ToLower().Contains(request.Text.ToLower()));
            }

            if (request.UserFirstName != null)
            {
                query = query.Where(c => c.User.FirstName.ToLower() == request.UserFirstName.ToLower());
            }

            if (request.UserLastName != null)
            {
                query = query.Where(c => c.User.LastName.ToLower() == request.UserLastName.ToLower());
            }

            if (request.PageNumber != 0)
            {
                query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);
            }

            var totalCount = query.Count();
            var pagesCount = (int)System.Math.Ceiling((double)totalCount / request.PerPage);

            return(new PagedResponse <CommentDto>
            {
                TotalCount = totalCount,
                PagesCount = pagesCount,
                CurrentPage = request.PageNumber,
                Data = query.Select(c => new CommentDto
                {
                    Id = c.Id,
                    Text = c.Text,
                    CreatedAt = c.CreatedAt,
                    UpdatedAt = c.UpdatedAt,
                    ArticleId = c.ArticleId,
                    UserId = c.UserId,
                    Article = c.Article.Title,
                    User = c.User.FirstName + " " + c.User.LastName
                })
            });
        }
コード例 #18
0
        public Pagination <CommentDto> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.Keyword != null)
            {
                query = query.Where(p => p.Text
                                    .ToLower()
                                    .Contains(request.Keyword.ToLower()));
            }

            if (request.IsDeleted)
            {
                query = query.Where(p => p.IsDeleted == request.IsDeleted);
            }
            if (!request.IsDeleted)
            {
                query = query.Where(p => p.IsDeleted == request.IsDeleted);
            }

            var totalCount = query.Count();

            query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            return(new Pagination <CommentDto>
            {
                CurrentPage = request.PageNumber,
                Pages = pagesCount,
                Total = totalCount,
                Data = query.Include(u => u.User)
                       .Select(p => new CommentDto
                {
                    id = p.Id,
                    IsDeleted = p.IsDeleted,
                    CreatedAt = p.CreatedAt,
                    ModifidedAt = p.CreatedAt,
                    Text = p.Text,
                    UserId = p.UserId,
                    PostId = p.PostId
                })
            });
        }
コード例 #19
0
        public IEnumerable <GetCommentDto> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.Active.HasValue)
            {
                query = query.Where(c => c.IsDeleted != request.Active);
            }
            else
            {
                query = query.Where(c => c.IsDeleted == false);
            }


            if (request.UserId.HasValue)
            {
                if (!Context.Users.Any(u => u.Id == request.UserId))
                {
                    throw new EntityNotFoundException("User");
                }
                query = query.Where(c => c.UserId == request.UserId);
            }

            if (request.PostId.HasValue)
            {
                if (!Context.Posts.Any(p => p.Id == request.PostId))
                {
                    throw new EntityNotFoundException("Post");
                }
                query = query.Where(c => c.PostId == request.PostId);
            }


            return(query.Select(c => new GetCommentDto
            {
                Id = c.Id,
                Comment = c.Text,
                User = c.User.Username,
                Post = c.Post.Title
            }));
        }
コード例 #20
0
        public PagedResponse <CommentDto> Execute(CommentSearch search)
        {
            var query = _context.Comments.AsQueryable();

            if (!string.IsNullOrEmpty(search.Content) && !string.IsNullOrWhiteSpace(search.Content))
            {
                query = query.Where(x => x.Content.ToLower().Contains(search.Content.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <CommentDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => _mapper.Map <CommentDto>(x)).ToList()
            };

            return(response);
        }
コード例 #21
0
        public IEnumerable <CreateCommentDto> Execute(CommentSearch request)
        {
            var query = _context.Commnets.AsQueryable();

            if (request.Keyword != null)
            {
                if (!_context.Commnets.Any(c => c.Text.ToLower().Contains(request.Keyword.ToLower())))
                {
                    throw new EntityNotFoundException("Comment");
                }
                query = query.Where(c => c.Text.ToLower().Contains(request.Keyword.ToLower()));
            }


            return(query.Select(c => new CreateCommentDto
            {
                PostId = c.PostId,
                UserId = c.UserId,
                Text = c.Text
            }));
        }
コード例 #22
0
        public PageResponse <CommentDto> Execute(CommentSearch request)
        {
            var comments = Context.Comments.Include(n => n.News).AsQueryable().Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            if (request.Keyword != null)
            {
                comments = comments.Include(n => n.News).Where(n => n.Email
                                                               .ToLower()
                                                               .Contains(request.Keyword.ToLower()));
            }

            if (request.Name != null)
            {
                comments = comments.Include(n => n.News).Where(n => n.Name == request.Name);
            }

            var totalRecords = comments.Count();
            var pagesCount   = (int)Math.Ceiling((double)totalRecords / request.PerPage);

            var response = new PageResponse <CommentDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalRecords,
                PagesCount  = pagesCount,
                Data        = comments.Select(comment => new CommentDto
                {
                    Email   = comment.Email,
                    Id      = comment.Id,
                    Comment = comment.Comment,
                    Name    = comment.Name,
                    News    = new NewsCommentDto
                    {
                        NewsId  = comment.News.Id,
                        Heading = comment.News.Heading
                    }
                })
            };

            return(response);
        }
コード例 #23
0
        public PagedResponse <ReadCommentDto> Execute(CommentSearch search)
        {
            var query = _context.Comments.Include(x => x.User).AsQueryable();

            if (!string.IsNullOrEmpty(search.Comment) || !string.IsNullOrWhiteSpace(search.Comment))
            {
                query = query.Where(x => x.CommentText.ToLower().Contains(search.Comment.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.PostTitle) || !string.IsNullOrWhiteSpace(search.PostTitle))
            {
                query = query.Where(x => x.Post.Title.ToLower().Contains(search.PostTitle.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.UserEmail) || !string.IsNullOrWhiteSpace(search.UserEmail))
            {
                query = query.Where(x => x.User.Email.ToLower().Contains(search.UserEmail.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <ReadCommentDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new ReadCommentDto
                {
                    Id          = x.Id,
                    CommentText = x.CommentText,
                    UserId      = x.User.Id,
                    UserEmail   = x.User.Email,
                    PostId      = x.Post.Id,
                    PostTitle   = x.Post.Title
                }).ToList()
            };

            return(response);
        }
コード例 #24
0
        /// <summary>
        /// Private helper method to perform a new search or maintain a previous search through
        /// pagination and filter changes
        /// </summary>
        /// <param name="workouts">The base workout query result</param>
        /// <param name="sortBy">The passed sort string if it exists, else null</param>
        /// <param name="page">The passed page param if it exists, else null</param>
        /// <returns>The searched workouts</returns>
        private IQueryable <comment> doSearch(IQueryable <comment> comments, CommentSearch search, String filterString, string sortBy, int?page)
        {
            if (page != null || !String.IsNullOrEmpty(sortBy) || !String.IsNullOrEmpty(filterString))
            {
                search = this.setSearchFromSession(search);
            }
            else
            {
                setSessionFromSearch(search);
            }

            if (!String.IsNullOrEmpty(search.message))
            {
                comments = comments.Where(c => c.message.Contains(search.message));
            }
            if (!String.IsNullOrEmpty(search.username))
            {
                comments = comments.Where(c => c.user.username.Contains(search.username));
            }

            return(comments);
        }
コード例 #25
0
        public PagedResponses <CommentDto> Execute(CommentSearch request)
        {
            var query      = Context.Comments.AsQueryable();
            var totalCount = query.Count();

            query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            var response = new PagedResponses <CommentDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(p => new CommentDto
                {
                    Id      = p.Id,
                    Comment = p.Comments
                })
            };

            return(response);
        }
コード例 #26
0
        public PagedResponses <CommentDto> Execute(CommentSearch search)
        {
            var query      = _context.Comments.AsQueryable();
            var totalCount = query.Count();

            query = query.Skip((search.PageNumber - 1) * search.PerPage).Take(search.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / search.PerPage);

            var response = new PagedResponses <CommentDto>
            {
                CurrentPage  = search.PageNumber,
                TotalCount   = totalCount,
                ItemsPerPage = pagesCount,
                data         = query.Select(p => new CommentDto
                {
                    Id      = p.Id,
                    Comment = p.Comment
                })
            };

            return(response);
        }
コード例 #27
0
        /// <summary>
        /// Sets the session search parameters based on the current search values
        /// </summary>
        /// <param name="search">The WorkoutSearch object containing the values to set in the session</param>
        private void setSessionFromSearch(CommentSearch search)
        {
            if (Session != null)
            {
                if (!String.IsNullOrEmpty(search.message))
                {
                    Session["MessageSearchParam"] = search.message;
                }
                else
                {
                    Session["MessageSearchParam"] = "";
                }

                if (!String.IsNullOrEmpty(search.username))
                {
                    Session["UsernameSearchParam"] = search.username;
                }
                else
                {
                    Session["UsernameSearchParam"] = "";
                }
            }
        }
コード例 #28
0
        public Pagination <CommentDTO> Execute(CommentSearch request)
        {
            var data = Context.Comments.AsQueryable();

            if (request.CommentText != null)
            {
                var wanted = request.CommentText.ToLower();
                data = data.Where(c => c.CommentText.ToLower().Contains(wanted) &&
                                  c.Deleted == false);
            }
            if (request.OnlyActive.HasValue)
            {
                data = data.Where(c => c.Deleted != request.OnlyActive);
            }

            var totalCount = data.Count();

            data = data.Skip((request.PerPage - 1) * request.PageNumber).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            var res = new Pagination <CommentDTO>
            {
                CurrentPage = request.PageNumber,
                PagesCount  = pagesCount,
                TotalCount  = totalCount,
                Data        = data.Select(c => new CommentDTO
                {
                    CommentText = c.CommentText,
                    ShowId      = c.Show.Id,
                    UserId      = c.UserId
                })
            };

            return(res);
        }
コード例 #29
0
        public IEnumerable <CommentDto> Execute(CommentSearch request)
        {
            var query = Context.Comments.AsQueryable();

            if (request.IsDeleted.HasValue)
            {
                query = query.Where(p => p.IsDeleted == request.IsDeleted);
            }
            else
            {
                query = query.Where(p => !p.IsDeleted);
            }
            if (request.Email != null)
            {
                query = query.Where(p => p.User.Email.ToLower().Contains(request.Email.ToLower()));
            }
            if (request.Movie != null)
            {
                query = query.Where(p => p.Movie.Title.ToLower().Contains(request.Movie.ToLower()));
            }
            var TotalRecords = query.Count();

            if (request.page.HasValue && request.PageSize.HasValue)
            {
                query = query.Skip((request.page ?? 0 - 1) * request.PageSize ?? 0).Take(request.PageSize ?? 0);
            }
            return(query.Select(p => new CommentDto
            {
                Id = p.Id,
                Text = p.Text,
                User = p.User.Email,
                Movie = p.Movie.Title,
                CreatedAt = p.CreatedAt,
                TotalRecords = TotalRecords
            }));
        }
コード例 #30
0
        public PagedResponse <ReadCommentDto> Execute(CommentSearch search)
        {
            var query = _context.Comments
                        .Include(x => x.User)
                        .Include(o => o.Product).AsQueryable();

            if (!string.IsNullOrEmpty(search.User) || !string.IsNullOrWhiteSpace(search.User))
            {
                query = query.Where(x => x.User.Username.ToLower().Contains(search.User.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.ProductName) || !string.IsNullOrWhiteSpace(search.ProductName))
            {
                query = query.Where(x => x.Product.Name.ToLower().Contains(search.ProductName.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <ReadCommentDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new ReadCommentDto
                {
                    Id          = x.Id,
                    ProductId   = x.ProductId,
                    UserId      = x.UserId,
                    ProductName = x.Product.Name,
                    UserName    = x.User.Username,
                    Text        = x.Text
                }).ToList()
            };

            return(response);
        }