Initial
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using Datamodels.DatabaseModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Repositories.Interfaces;
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.SearchModels;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SearchLogic
|
||||
{
|
||||
public class SearchLogic : ISearchLogic
|
||||
{
|
||||
private readonly ILogger<SearchLogic> _logger;
|
||||
private readonly IFwMariaSearchRepo _searchRepo;
|
||||
|
||||
public SearchLogic(ILogger<SearchLogic> logger, IFwMariaSearchRepo searchRepo)
|
||||
{
|
||||
_logger = logger;
|
||||
_searchRepo = searchRepo;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<Address>>> GetAllAddresses()
|
||||
{
|
||||
var result = await _searchRepo.GetAllAddresses();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<IEntityClass>>> 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 = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user