feat: 条件查询支持包含

This commit is contained in:
Argo Zhang 2020-01-15 16:03:37 +08:00
parent 9c15d0ed15
commit 9341dc1089
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
2 changed files with 4 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Components;
using Bootstrap.Security;
using System;
using System.Collections.Generic;
using System.Linq;
@ -37,8 +38,8 @@ namespace Bootstrap.Pages.Admin.Components
{
var data = DataAccess.DictHelper.RetrieveDicts();
if (QueryModel.Define != -1) data = data.Where(d => d.Define == QueryModel.Define);
if (QueryModel.Name != "") data = data.Where(d => d.Name == QueryModel.Name);
if (QueryModel.Category != "") data = data.Where(d => d.Category == QueryModel.Category);
if (!string.IsNullOrEmpty(QueryModel.Name)) data = data.Where(d => d.Name.Contains(QueryModel.Name, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(QueryModel.Category)) data = data.Where(d => d.Category.Contains(QueryModel.Category, StringComparison.OrdinalIgnoreCase));
var totalCount = data.Count();
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
return new QueryData<BootstrapDict>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };

View File

@ -19,7 +19,7 @@ namespace Bootstrap.Pages.Admin.Components
protected override QueryData<Group> Query(int pageIndex, int pageItems)
{
var data = GroupHelper.Retrieves();
if (!string.IsNullOrEmpty(QueryModel.GroupName)) data = data.Where(d => d.GroupName.Equals(QueryModel.GroupName, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(QueryModel.GroupName)) data = data.Where(d => d.GroupName.Contains(QueryModel.GroupName, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(QueryModel.Description)) data = data.Where(d => d.Description != null && d.Description.Contains(QueryModel.Description, StringComparison.OrdinalIgnoreCase));
var totalCount = data.Count();
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);