First idea of ResultModel
This commit is contained in:
		| @@ -11,6 +11,6 @@ namespace SearchLogic | ||||
|     public interface ISearchLogic | ||||
|     { | ||||
|         Task<DataResult<List<Address>>> GetAllAddresses(); | ||||
|         Task<DataResult<List<IEntityClass>>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1); | ||||
|         Task<DataResult<ResultModel>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,6 +4,10 @@ | ||||
|     <TargetFramework>netstandard2.1</TargetFramework> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\..\Datamodels\Datamodels.csproj" /> | ||||
|     <ProjectReference Include="..\..\Repositories\Repositories.csproj" /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user