Initial
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BusinessLogic.LookupLogic.Interfaces;
|
||||
using Datamodels.Lookups;
|
||||
using Datamodels.BusinessModels;
|
||||
using Repositories.Interfaces;
|
||||
|
||||
namespace BusinessLogic.LookupLogic
|
||||
{
|
||||
public class FwLookupLogic: ILookupLogic
|
||||
{
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<FwLookupLogic> _logger;
|
||||
private readonly IFwMariaLookupRepo _lookupRepo;
|
||||
|
||||
public FwLookupLogic(ILogger<FwLookupLogic> logger, IConfiguration configuration, IFwMariaLookupRepo lookupRepo)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_lookupRepo = lookupRepo;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetAllLookups()
|
||||
{
|
||||
var result = await _lookupRepo.GetAllLookups();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<LookupCategory>> GetLookupCategoryById(long id)
|
||||
{
|
||||
var result = await _lookupRepo.GetLookupCategoryById(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetLookupCategoryByName(string categoryName)
|
||||
{
|
||||
var result = await _lookupRepo.GetLookupCategoryByName(categoryName);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetActiveLookupCategories()
|
||||
{
|
||||
var result = await _lookupRepo.GetActiveLookupCategories();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Datamodels.Lookups;
|
||||
using Datamodels.BusinessModels;
|
||||
|
||||
namespace BusinessLogic.LookupLogic.Interfaces
|
||||
{
|
||||
public interface ILookupLogic
|
||||
{
|
||||
Task<DataResult<List<LookupCategory>>> GetAllLookups();
|
||||
Task<DataResult<LookupCategory>> GetLookupCategoryById(long id);
|
||||
Task<DataResult<List<LookupCategory>>> GetLookupCategoryByName(string categoryName);
|
||||
Task<DataResult<List<LookupCategory>>> GetActiveLookupCategories();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.16" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.16" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Datamodels\Datamodels.csproj" />
|
||||
<ProjectReference Include="..\..\Repositories\Repositories.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.DatabaseModels;
|
||||
using Datamodels.SearchModels;
|
||||
|
||||
namespace SearchLogic
|
||||
{
|
||||
public interface ISearchLogic
|
||||
{
|
||||
Task<DataResult<List<Address>>> GetAllAddresses();
|
||||
Task<DataResult<List<IEntityClass>>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Datamodels\Datamodels.csproj" />
|
||||
<ProjectReference Include="..\..\Repositories\Repositories.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user