public async Task <CommentSearchPagingResult> SearchCommentsAsync(CommentSearchPagingOption options, string currentUserId) { var query = GenerateCommentsDetailsQuery(); if (!string.IsNullOrEmpty(options.SearchKey)) { switch (options.SearchOn) { case CommentSearchOnEnum.ArticleId: query = query.Where(x => x.ArticleId == options.SearchKey.Trim()); break; case CommentSearchOnEnum.ParentId: query = query.Where(x => x.ParentId == options.SearchKey.Trim()); break; case CommentSearchOnEnum.CommentText: query = query.Where(x => x.CommentText.Contains(options.SearchKey.Trim())); break; default: break; } } switch (options.SortBy) { case SortByEnum.UpdatedOn: if (options.SortOrder == SortOrderEnum.Ascending) { query = query.OrderBy(x => x.UpdatedOn); } else { query = query.OrderByDescending(x => x.UpdatedOn); } break; } var docsCount = await query.CountAsync(); var documents = await query.Skip((options.CurrentPage - 1) *options.PageSize).Take(options.PageSize).ToListAsync(); foreach (var item in documents) { item.Ranking = await GetCommentRankingDetailsAsync(item.Id, currentUserId); } return(new CommentSearchPagingResult(documents, docsCount, options)); }
public async Task <IActionResult> SearchComments(CommentSearchPagingOption options) { try { var searchResult = await databaseService.SearchCommentsAsync(options, currentUserId); return(Ok(searchResult)); } catch (Exception ex) { logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public Task <CommentSearchPagingResult> SearchCommentsAsync(CommentSearchPagingOption options, string currentUserId) { throw new NotImplementedException(); }