Skip to content

Commit

Permalink
Merge pull request #100 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
add support for GetLogic
  • Loading branch information
Ali-YousefiTelori authored Dec 21, 2023
2 parents 43d8241 + e1c6826 commit 4d755f5
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet,aspcore,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, long> GetLongL
return GetInternalLongContractLogic<TEntity, TEntity, TEntity, TEntity>();
}

/// <summary>
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public IContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity> GetLogic<TEntity>() where TEntity : class
{
return GetInternalContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity>();
}

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,client,clients</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>core contracts.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,contract,contracts,dto,dtos</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ public async Task<MessageContract<TResponseContract>> GetBy(Expression<Func<TEnt
return await GetBy<TEntity, TResponseContract>(_easyReadableQueryable, predicate, func, cancellationToken);
}

TId MapToTId<T>(T result)
{
if (result is IIdSchema<TId> schema)
return schema.Id;
else if (result is TId tid)
return tid;
else if ((typeof(TId) == typeof(long) || typeof(TId) == typeof(int)) && result?.GetType() != typeof(string) && (result?.GetType()?.IsClass).GetValueOrDefault())
throw new Exception($"I think you cannot convert TId from type {typeof(TId).Name} to type {result?.GetType()?.Name}, maybe you don't need to use LongLogic?");
return MapperProvider.Map<TId>(result);
}

/// <summary>
///
Expand All @@ -107,11 +117,7 @@ public async Task<MessageContract<TId>> Add(TCreateRequestContract contract, Can
{
var result = await Add(_easyWriteableQueryable, contract, cancellationToken);
if (result)
{
if (result.Result is IIdSchema<TId> schema)
return schema.Id;
return MapperProvider.Map<TId>(result.Result);
}
return MapToTId(result.Result);
return result.ToContract<TId>();
}

Expand All @@ -130,10 +136,7 @@ public async Task<ListMessageContract<TId>> AddBulk(CreateBulkRequestContract<TC
List<TId> items = new List<TId>();
foreach (var item in result.Result)
{
if (item is IIdSchema<TId> schema)
items.Add(schema.Id);
else
items.Add(MapperProvider.Map<TId>(item));
items.Add(MapToTId(item));
}
return items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ IContractLogic<TEntity, TContract, TContract, TContract, long> GetLongReadableCo
IContractLogic<TEntity, TEntity, TEntity, TEntity, TId> GetLogic<TEntity, TId>()
where TEntity : class;

/// <summary>
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
IContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity> GetLogic<TEntity>()
where TEntity : class;

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>ef core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.67</Version>
<Version>0.0.0.68</Version>
<Description>ef core of Relational database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore,Relational</PackageTags>
Expand Down

0 comments on commit 4d755f5

Please sign in to comment.