public async Task <ActionResult <PaginatedResult <LinLogResource> > > SearchForLog( [FromQuery] SearchLogParameters searchLogParameters) { if (string.IsNullOrWhiteSpace(searchLogParameters.Keyword)) { throw new BadRequestException { Msg = "搜索关键字不可为空" }; } var list = await _linLogRepository.SearchAllLogsAsync(searchLogParameters); var resources = MyMapper.Map <IEnumerable <LinLog>, IEnumerable <LinLogResource> >(list); var result = WrapPaginatedResult(list, resources); return(Ok(result)); }
public async Task <PaginatedList <LinLog> > SearchAllLogsAsync(SearchLogParameters searchLogParameters) { var query = _linContext.LinLogs .AsQueryable(); if (!string.IsNullOrWhiteSpace(searchLogParameters.Keyword)) { query = query.Where(u => u.Message != null && u.Message.Contains(searchLogParameters.Keyword)); } query = BuildQueryForLinLogs(searchLogParameters, query); var total = await query.CountAsync(); var data = await query .Skip(searchLogParameters.Start + searchLogParameters.Page *searchLogParameters.Count) .Take(searchLogParameters.Count) .ToListAsync(); return(new PaginatedList <LinLog>(searchLogParameters.Page, searchLogParameters.Count, total, data)); }