Skip to content

Commit

Permalink
Support for current user identity
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Dec 27, 2023
1 parent a4fbcdb commit 3ebfc6d
Show file tree
Hide file tree
Showing 10 changed files with 20 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.79</Version>
<Version>0.0.0.80</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.79</Version>
<Version>0.0.0.80</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 @@ -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.79</Version>
<Version>0.0.0.80</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.79</Version>
<Version>0.0.0.80</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
@@ -1,8 +1,5 @@
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.Cores.Models;
using EasyMicroservices.Database.Interfaces;
using EasyMicroservices.Database.Interfaces;
using System;
using System.Threading.Tasks;

namespace EasyMicroservices.Cores.Database.Interfaces
{
Expand All @@ -15,10 +12,11 @@ public interface IUniqueIdentityManager
/// update unique identity
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="currentUserUniqueIdentity"></param>
/// <param name="context"></param>
/// <param name="entity"></param>
/// <returns>is need update database</returns>
bool UpdateUniqueIdentity<TEntity>(IContext context, TEntity entity);
bool UpdateUniqueIdentity<TEntity>(string currentUserUniqueIdentity, IContext context, TEntity entity);
/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -62,6 +61,8 @@ private async Task<IEasyReadableQueryableAsync<TEntity>> UniqueIdentityQueryMake
{
if (!typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity)))
return easyReadableQueryable;
if (uniqueIdentity.IsNullOrEmpty())
uniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity();
var uniqueIdentityManager = await GetIUniqueIdentityManager();
IEasyReadableQueryableAsync<TEntity> queryable = easyReadableQueryable;
if (!uniqueIdentityManager.IsUniqueIdentityForThisTable<TEntity>(easyReadableQueryable.Context, uniqueIdentity))
Expand Down Expand Up @@ -799,8 +800,9 @@ public async Task<MessageContract<TEntity>> Add<TEntity>(IEasyWritableQueryableA
await easyWritableQueryable.SaveChangesAsync();
if (typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity)))
{
var currentUserUniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity();
var uniqueIdentityManager = await GetIUniqueIdentityManager();
if (uniqueIdentityManager.UpdateUniqueIdentity(easyWritableQueryable.Context, result.Entity))
if (uniqueIdentityManager.UpdateUniqueIdentity(currentUserUniqueIdentity, easyWritableQueryable.Context, result.Entity))
{
await InternalUpdate(easyWritableQueryable, result.Entity, false, true, true, cancellationToken);
await easyWritableQueryable.SaveChangesAsync();
Expand Down Expand Up @@ -835,10 +837,11 @@ public async Task<ListMessageContract<TEntity>> AddBulk<TEntity>(IEasyWritableQu
bool anyUpdate = false;
if (typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity)))
{
var currentUserUniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity();
var uniqueIdentityManager = await GetIUniqueIdentityManager();
foreach (var item in result)
{
if (uniqueIdentityManager.UpdateUniqueIdentity(easyWritableQueryable.Context, item.Entity))
if (uniqueIdentityManager.UpdateUniqueIdentity(currentUserUniqueIdentity, easyWritableQueryable.Context, item.Entity))
{
anyUpdate = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public DefaultUniqueIdentityManager(WhiteLabelInfo whiteLabelInfo)
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="currentUserUniqueIdentity"></param>
/// <param name="context"></param>
/// <param name="entity"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public bool UpdateUniqueIdentity<TEntity>(IContext context, TEntity entity)
public bool UpdateUniqueIdentity<TEntity>(string currentUserUniqueIdentity, IContext context, TEntity entity)
{
if (entity is IUniqueIdentitySchema uniqueIdentitySchema)
{
if (uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty())
uniqueIdentitySchema.UniqueIdentity = currentUserUniqueIdentity;
if (uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty())
uniqueIdentitySchema.UniqueIdentity = _whiteLabelInfo.StartUniqueIdentity;
var ids = uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty() ? null : DecodeUniqueIdentity(uniqueIdentitySchema.UniqueIdentity);
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.79</Version>
<Version>0.0.0.80</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 @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.79</Version>
<Version>0.0.0.80</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.79</Version>
<Version>0.0.0.80</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 3ebfc6d

Please sign in to comment.