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

@@ -80,32 +80,7 @@ namespace Repositories
public async Task<DataResult<List<IEntityClass>>> GetFilteredData<T>(List<Expression> expressions, long skip = 0, long take = -1) where T : IEntityClass
{
var where = FilterLinq<T>.GetWherePredicate(wherefield, wherefieldvalue).Compile();
items = await _dbContext.Address.Where((Expression<Func<Address, bool>>)where).ToListAsync();
var result = new DataResult<List<IEntityClass>>();
if (typeof(T).Equals(typeof(Address)))
{
Expression combined = null;
foreach (var exp in expressions)
{
if (combined == null)
{
combined = exp;
}
else
{
combined = Expression.Or(combined, exp);
}
}
ParameterExpression pe = Expression.Parameter(typeof(T), typeof(T).Name);
combined = Expression.Lambda<Func<T, Boolean>>(combined, new ParameterExpression[] { pe });
//var addressFound = await _dbContext.Address.Where((Expression<Func<Address, bool>>)combined).ToListAsync();
var addressFound = await _dbContext.Address.Where(a => a.City == "Augsburg" | a.City == "München").ToListAsync();
result.Data = new List<IEntityClass>(addressFound.Cast<IEntityClass>());
}
return result;
throw new NotImplementedException();
}
}
@@ -113,39 +88,7 @@ namespace Repositories
{
public static Expression<Func<T, Boolean>> GetWherePredicate(string whereFieldList, string whereFieldValues)
{
//the 'IN' parameter for expression ie T=> condition
ParameterExpression pe = Expression.Parameter(typeof(T), typeof(T).Name);
//combine them with and 1=1 Like no expression
Expression combined = null;
if (whereFieldList != null)
{
string[] field = whereFieldList.Split(';');
string[] fieldValue = whereFieldValues.Split(';');
for (int i = 0; i < field.Count(); i++)
{
//Expression for accessing Fields name property
Expression columnNameProperty = Expression.Property(pe, field[i]);
//the name constant to match
Expression columnValue = Expression.Constant(fieldValue[i]);
//the first expression: PatientantLastName = ?
Expression e1 = Expression.Equal(columnNameProperty, columnValue);
if (combined == null)
{
combined = e1;
}
else
{
combined = Expression.And(combined, e1);
}
}
}
//create and return the predicate
return Expression.Lambda<Func<T, Boolean>>(combined, new ParameterExpression[] { pe });
throw new NotImplementedException();
}
}
}