public async Task <GetRuleListResponse> GetRuleList([FromBody] GetRuleListRequest request) { var response = new GetRuleListResponse(); if (request.PageIndex <= 1) { request.PageIndex = 0; } else { request.PageIndex = request.PageIndex - 1; } if (request.PageSize < 20) { request.PageSize = 20; } try { response = await _ruleRepository.GetRules(request); response.Success = true; } catch (Exception e) { response.Message = e.Message; _logger.LogError($"GetRuleList 出现异常:{e.Message}", e); } return(response); }
public async Task <GetRuleListResponse> GetRules(GetRuleListRequest request) { var response = new GetRuleListResponse(); var query = Rules.AsQueryable(); if (request.RuleName.IsNotNullOrEmpty()) { query = query.Where(x => x.Name.Contains(request.RuleName)); } if (request.RuleType.IsNotNullOrEmpty()) { query = query.Where(x => x.Type.Contains(request.RuleType)); } if (request.RuleStatus.HasValue && request.RuleStatus.Value != -1) { var enabled = request.RuleStatus == 1; query = query.Where(x => x.Enabled == enabled); } var totalCount = query.Count(); var data = query.OrderByDescending(x => x.Id).Skip(request.PageIndex * request.PageSize).Take(request.PageSize).ToList(); response.TotalCount = totalCount; response.Data = await Task.FromResult(data); return(response); }