public async Task <IEnumerable <Comment> > SearchComments(SearchCommentModel searchCommentModel) { var comments = await this.GetAllComments(); if (searchCommentModel.PostId != null) { comments = comments.Where(x => x.PostId == searchCommentModel.PostId); } if (searchCommentModel.Id != null) { comments = comments.Where(x => x.Id == searchCommentModel.Id); } if (searchCommentModel.Name != null) { comments = comments.Where(x => x.Name.Contains(searchCommentModel.Name, StringComparison.OrdinalIgnoreCase)); } if (searchCommentModel.Body != null) { comments = comments.Where(x => x.Body.Contains(searchCommentModel.Body, StringComparison.OrdinalIgnoreCase)); } if (searchCommentModel.Email != null) { comments = comments.Where(x => x.Email.Contains(searchCommentModel.Email, StringComparison.OrdinalIgnoreCase)); } return(comments); }
public async Task <IActionResult> GetAllComments([FromQuery] SearchCommentModel model) { var result = await _commentService.GetAllCommentByTicketId(model); return(Ok(new { data = result, totalCount = result.TotalCount, totalPages = result.TotalPages, })); }
public async Task <PagedList <CommentModel> > GetAllByTicketId(SearchCommentModel model) { var query = _context.Comment.Where(t => t.TicketId == model.TicketId && t.DelFlg == false) .Select(t => new CommentModel { Id = t.Id, TicketId = t.TicketId, Username = t.User.Username, FullName = t.User.FullName, Content = t.Content, DelFlg = t.DelFlg, InsBy = t.InsBy, InsDatetime = t.InsDatetime, UpdBy = t.UpdBy, UpdDatetime = t.UpdDatetime }); var totalCount = await query.CountAsync(); List <CommentModel> result = null; //if (model.SortBy == Constants.SortBy.SORT_NAME_ASC) //{ // query = query.OrderBy(t => t.InsDatetime); //} //else if (model.SortBy == Constants.SortBy.SORT_NAME_DES) //{ // query = query.OrderByDescending(t => t.InsDatetime); //} result = await query.Skip(model.Size *(model.Page - 1)) .Take(model.Size) .OrderByDescending(t => t.InsDatetime) .ToListAsync(); return(PagedList <CommentModel> .ToPagedList(result, totalCount, model.Page, model.Size)); }
public async Task <IActionResult> SearchComments([FromQuery] SearchCommentModel comment) { return(Ok(await this.commentRepository.SearchComments(comment))); }
public async Task <PagedList <CommentModel> > GetAllCommentByTicketId(SearchCommentModel model) { var comments = await _unitOfWork.CommentRepository.GetAllByTicketId(model); return(comments); }