From 3ebfc6d8f5d6c5814e28c5286c4d0f59777d3f18 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 27 Dec 2023 18:30:42 +0330 Subject: [PATCH] Support for current user identity --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- ...yMicroservices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Clients.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../Database/Interfaces/IUniqueIdentityManager.cs | 8 +++----- .../Database/Logics/DatabaseLogicInfrastructure.cs | 9 ++++++--- .../Database/Managers/DefaultUniqueIdentityManager.cs | 5 ++++- .../EasyMicroservices.Cores.Database.csproj | 2 +- .../EasyMicroservices.Cores.EntityFrameworkCore.csproj | 2 +- ...oservices.Cores.Relational.EntityFrameworkCore.csproj | 2 +- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 3d3f80f..a521d84 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 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 43816b1..bb22d21 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index e52cc12..3807be9 100644 --- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 core of database. EasyMicroservices@gmail.com core,cores,base,client,clients diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 38642df..b4b4dad 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs index 3bd7e6a..b5200a3 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs @@ -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 { @@ -15,10 +12,11 @@ public interface IUniqueIdentityManager /// update unique identity /// /// + /// /// /// /// is need update database - bool UpdateUniqueIdentity(IContext context, TEntity entity); + bool UpdateUniqueIdentity(string currentUserUniqueIdentity, IContext context, TEntity entity); /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index cae37ad..21c7c41 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -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; @@ -62,6 +61,8 @@ private async Task> UniqueIdentityQueryMake { if (!typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity))) return easyReadableQueryable; + if (uniqueIdentity.IsNullOrEmpty()) + uniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity(); var uniqueIdentityManager = await GetIUniqueIdentityManager(); IEasyReadableQueryableAsync queryable = easyReadableQueryable; if (!uniqueIdentityManager.IsUniqueIdentityForThisTable(easyReadableQueryable.Context, uniqueIdentity)) @@ -799,8 +800,9 @@ public async Task> Add(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(); @@ -835,10 +837,11 @@ public async Task> AddBulk(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; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs index d395c3f..b35bafd 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs @@ -29,14 +29,17 @@ public DefaultUniqueIdentityManager(WhiteLabelInfo whiteLabelInfo) /// /// /// + /// /// /// /// /// - public bool UpdateUniqueIdentity(IContext context, TEntity entity) + public bool UpdateUniqueIdentity(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); diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 7ab19e8..cfe1460 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 80341db..ba9b1c4 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore 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 ea21c92..a699013 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 @@ -4,7 +4,7 @@ net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.79 + 0.0.0.80 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational