diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj index 3c54c85..5df1faf 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj @@ -13,7 +13,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 679b491..33b7efa 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index c26d2ac..22a99cf 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs index d660359..dbf49a8 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs @@ -13,6 +13,7 @@ using EasyMicroservices.Mapper.SerializerMapper.Providers; using EasyMicroservices.Serialization.Newtonsoft.Json.Providers; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Linq; @@ -294,7 +295,8 @@ public virtual IMapperProvider GetMapper() { var mapper = new CompileTimeMapperProvider(new SerializerMapperProvider(new NewtonsoftJsonProvider(new Newtonsoft.Json.JsonSerializerSettings() { - ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore, + Error = HandleDeserializationError }))); if (MapperTypeAssembly != null) { @@ -311,6 +313,17 @@ public virtual IMapperProvider GetMapper() return mapper; } + /// + /// + /// + /// + /// + public virtual void HandleDeserializationError(object sender, ErrorEventArgs errorArgs) + { + //var currentError = errorArgs.ErrorContext.Error.Message; + errorArgs.ErrorContext.Handled = true; + } + /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs index 8b70411..53bb422 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs @@ -11,7 +11,7 @@ public class FilterRequestContract /// /// /// - public bool? IsDeleted { get; set; } + public bool? IsDeleted { get; set; } = false; /// /// /// @@ -57,10 +57,14 @@ public class FilterRequestContract /// /// /// - public string SortColumnName { get; set; } + public string SortColumnNames { get; set; } /// /// /// public bool IsDescending { get; set; } + /// + /// text to search + /// + public string Text { get; set; } } } diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/SoftDeleteRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/SoftDeleteRequestContract.cs index 92f79d9..9dd2210 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/SoftDeleteRequestContract.cs +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/SoftDeleteRequestContract.cs @@ -8,7 +8,7 @@ public class SoftDeleteRequestContract : DeleteRequestContract /// /// /// - public bool IsDelete { get; set; } + public bool IsDelete { get; set; } = true; /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 46c10e0..be30312 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index 87a3bd5..abf4b69 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -215,8 +215,7 @@ public async Task> GetBy(IEasyRea var entityResult = await GetBy(easyReadableQueryable, predicate, query, true, cancellationToken); if (!entityResult) return entityResult.ToContract(); - var result = await _mapperProvider.MapAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapAsync(entityResult.Result); return result; } @@ -238,8 +237,7 @@ protected async Task> GetById(); - var result = await _mapperProvider.MapAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapAsync(entityResult.Result); return result; } @@ -263,8 +261,7 @@ public async Task> GetByUniqueIdentity(); - var result = await _mapperProvider.MapAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapAsync(entityResult.Result); return result; } @@ -335,8 +332,7 @@ protected async Task> Filter( var entityResult = await Filter(filterRequest, easyReadableQueryable, query, cancellationToken); if (!entityResult) return entityResult.ToAnotherListContract(); - var result = await _mapperProvider.MapToListAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapToListAsync(entityResult.Result); return result; } @@ -377,8 +373,7 @@ protected async Task> GetAll( var entityResult = await GetAll(easyReadableQueryable, query, cancellationToken); if (!entityResult) return entityResult.ToAnotherListContract(); - var result = await _mapperProvider.MapToListAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapToListAsync(entityResult.Result); return result; } @@ -402,8 +397,7 @@ public async Task> GetAllByUniqueIdentity(); - var result = await _mapperProvider.MapToListAsync(entityResult.Result); - ValidateMappedResult(ref result); + var result = await MapToListAsync(entityResult.Result); return result; } @@ -474,13 +468,11 @@ private async Task> InternalUpdateBulk(IEa public async Task> Update(IEasyWritableQueryableAsync easyWritableQueryable, TUpdateContract contract, CancellationToken cancellationToken = default) where TEntity : class { - var entity = await _mapperProvider.MapAsync(contract); - ValidateMappedResult(ref entity); + var entity = await MapAsync(contract); var result = await Update(easyWritableQueryable, entity, cancellationToken); if (!result) return result.ToContract(); - var mappedResult = await _mapperProvider.MapAsync(result.Result); - ValidateMappedResult(ref mappedResult); + var mappedResult = await MapAsync(result.Result); return mappedResult; } @@ -496,8 +488,7 @@ public async Task> Update UpdateBulk(IEasyWritableQueryableAsync easyWritableQueryable, UpdateBulkRequestContract request, CancellationToken cancellationToken = default) where TEntity : class { - var entities = await _mapperProvider.MapToListAsync(request.Items); - ValidateMappedResult(ref entities); + var entities = await MapToListAsync(request.Items); var result = await InternalUpdateBulk(easyWritableQueryable, entities, cancellationToken, false, true); return result; } @@ -740,8 +731,7 @@ public async Task AddBulk(IEasyWritableQueryableAsync< public async Task> Add(IEasyWritableQueryableAsync easyWritableQueryable, TContract contract, CancellationToken cancellationToken = default) where TEntity : class { - var entity = await _mapperProvider.MapAsync(contract); - ValidateMappedResult(ref entity); + var entity = await MapAsync(contract); var result = await Add(easyWritableQueryable, entity, cancellationToken); return result; } @@ -758,9 +748,44 @@ public async Task> Add(IEasyWritabl public async Task AddBulk(IEasyWritableQueryableAsync easyWritableQueryable, CreateBulkRequestContract request, CancellationToken cancellationToken = default) where TEntity : class { - var entities = await _mapperProvider.MapToListAsync(request.Items); - ValidateMappedResult(ref entities); - var result = await AddBulk(easyWritableQueryable, entities, cancellationToken); + var entities = await MapToListAsync(request.Items); + var result = await AddBulk(easyWritableQueryable, entities, cancellationToken); + return result; + } + + #endregion + + #region Map + + /// + /// + /// + /// + /// + /// + /// + protected async Task> MapToListAsync(IEnumerable items) + { + if (typeof(TFrom) == typeof(TTo)) + return items.Cast().ToList(); + var result = await _mapperProvider.MapToListAsync(items); + ValidateMappedResult(ref result); + return result; + } + + /// + /// + /// + /// + /// + /// + /// + protected async Task MapAsync(TFrom item) + { + if (typeof(TFrom) == typeof(TTo)) + return (TTo)(object)item; + var result = await _mapperProvider.MapAsync(item); + ValidateMappedResult(ref result); return result; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs index aa2328b..a40539e 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs @@ -6,7 +6,6 @@ using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; -using System.Diagnostics.Contracts; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -112,7 +111,7 @@ public async Task> Add(TCreateRequestContract var result = await Add(_easyWriteableQueryable, contract, cancellationToken); if (!result) return result.ToContract(); - var mapped = await _mapperProvider.MapAsync(result.Result); + var mapped = await MapAsync(result.Result); ValidateMappedResult(ref mapped); return mapped; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 242d913..4b3176e 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 core of database. EasyMicroservices@gmail.com core,cores,base,database @@ -20,7 +20,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 40c4968..c096adc 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore @@ -17,7 +17,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index c5e7edf..b8f1205 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.46 + 0.0.0.47 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj index 803688a..a2ccdb3 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj @@ -16,7 +16,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all