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 _logger; private readonly IFwMariaSearchRepo _searchRepo; public SearchLogic(ILogger logger, IFwMariaSearchRepo searchRepo) { _logger = logger; _searchRepo = searchRepo; } public async Task>> GetAllAddresses() { var result = await _searchRepo.GetAllAddresses(); return result; } public async Task>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1) { List expList = new List(); foreach (SearchDescription filterModel in filter.SearchDescriptions) { var exp = GetFilterCondition
(filterModel); if (exp != null) { expList.Add(exp); } } var result = await _searchRepo.GetFilteredData
(expList, 0, -1); return result; } private Expression GetFilterCondition(SearchDescription searchDescription) where T : IEntityClass { Expression> 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>(e1, new ParameterExpression[] { pe }); return e1; } return null; } } }