First idea of ResultModel

This commit is contained in:
Roland Fieger
2021-08-28 15:40:03 +02:00
parent 2de05c3856
commit 3b5ae86ce5
21 changed files with 139 additions and 187 deletions

View File

@@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
using Repositories.Interfaces;
using Datamodels.BusinessModels;
using Datamodels.SearchModels;
using Newtonsoft.Json;
using System.Linq;
using System.Linq.Expressions;
@@ -28,41 +29,13 @@ namespace SearchLogic
return result;
}
public async Task<DataResult<List<IEntityClass>>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1)
public async Task<DataResult<ResultModel>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1)
{
List<Expression> expList = new List<Expression>();
foreach (SearchDescription filterModel in filter.SearchDescriptions)
{
var exp = GetFilterCondition<Address>(filterModel);
if (exp != null)
{
expList.Add(exp);
}
var result = new DataResult<ResultModel>();
result.Data = new ResultModel();
result.Data.SearchModel = filter;
}
var result = await _searchRepo.GetFilteredData<Address>(expList, 0, -1);
return result;
}
private Expression GetFilterCondition<T>(SearchDescription searchDescription) where T : IEntityClass
{
Expression<Func<T, bool>> predicate;
ParameterExpression pe = Expression.Parameter(typeof(T), typeof(T).Name);
if (typeof(T).GetProperty(searchDescription.SearchData.FieldName) != null)
{
//var exp = Expression.Parameter(typeof(T), "x");
var exp = Expression.Parameter(typeof(T), typeof(T).Name);
Expression left = Expression.Property(pe, searchDescription.SearchData.FieldName);
Expression right = Expression.Constant(searchDescription.SearchData.Values[0]);
Expression e1 = Expression.Equal(left, right);
//predicate = Expression.Lambda<Func<T, bool>>(e1, new ParameterExpression[] { pe });
return e1;
}
return null;
}
}
}