From b610755b5e491fa3120d1820b35c2a20ab97049f Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Sat, 13 Jan 2024 00:54:29 +0330 Subject: [PATCH] Fix Update and add --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- ...vices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Clients.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../Interfaces/IUniqueIdentityManager.cs | 3 +-- .../Logics/DatabaseLogicInfrastructure.cs | 17 ++++++++++------- .../Managers/DefaultUniqueIdentityManager.cs | 14 +++++++++++--- .../EasyMicroservices.Cores.Database.csproj | 2 +- ...croservices.Cores.EntityFrameworkCore.csproj | 2 +- ....Cores.Relational.EntityFrameworkCore.csproj | 2 +- 10 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 97568c0..0eb3e0f 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.98 + 0.0.0.99 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 755a340..77ba6e0 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.98 + 0.0.0.99 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 c231bc2..8c6cc13 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.98 + 0.0.0.99 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 82e1b72..4b6260c 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.98 + 0.0.0.99 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 b5200a3..41ed804 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs @@ -11,12 +11,11 @@ public interface IUniqueIdentityManager /// /// update unique identity /// - /// /// /// /// /// is need update database - bool UpdateUniqueIdentity(string currentUserUniqueIdentity, IContext context, TEntity entity); + bool UpdateUniqueIdentity(string currentUserUniqueIdentity, IContext context, object entity); /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index 7483ee0..0059460 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -578,7 +578,8 @@ private async Task> InternalUpdateBulk(IEa return (FailedReasonType.AccessDenied, $"Some items you want to update not found!"); var result = await easyWritableQueryable.UpdateBulkAsync(entities, cancellationToken); - var uniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity(_logicOptions); + var currentUserUniqueIdentity = await _baseUnitOfWork.GetCurrentUserUniqueIdentity(_logicOptions); + var uniqueIdentityManager = await GetIUniqueIdentityManager(); foreach (var entityEntry in easyWritableQueryable.Context.GetTrackerEntities().ToArray()) { @@ -593,7 +594,10 @@ private async Task> InternalUpdateBulk(IEa } if (entityEntry.Entity is IUniqueIdentitySchema uidschema) { - uidschema.UniqueIdentity = uniqueIdentity; + if (uniqueIdentityManager.UpdateUniqueIdentity(currentUserUniqueIdentity, easyWritableQueryable.Context, entityEntry.Entity)) + { + FixUniqueIdentity(easyWritableQueryable.Context,typeof(TEntity), [entityEntry]); + } } } continue; @@ -910,9 +914,9 @@ await ActivityChangeLogLogic.ChangeLogAsync(getResult.Result.Selec #region Add - void FixUniqueIdentity(IContext context, IEntityEntry[] entityEntries) + void FixUniqueIdentity(IContext context, Type entityType, IEntityEntry[] entityEntries) { - if (!typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity))) + if (!typeof(IUniqueIdentitySchema).IsAssignableFrom(entityType)) return; var find = entityEntries.Select(x => x.Entity).Where(x => x is IUniqueIdentitySchema).Cast().FirstOrDefault(x => x.UniqueIdentity.HasValue()); if (find == null) @@ -926,7 +930,6 @@ void FixUniqueIdentity(IContext context, IEntityEntry[] entityEntries) uniqueIdentity.UniqueIdentity += "-" + DefaultUniqueIdentityManager.GenerateUniqueIdentity((long)primaryKeys.First()); } } - return; } /// @@ -960,7 +963,7 @@ public async Task> Add(IEasyWritableQueryableA var uniqueIdentityManager = await GetIUniqueIdentityManager(); if (uniqueIdentityManager.UpdateUniqueIdentity(currentUserUniqueIdentity, easyWritableQueryable.Context, result.Entity)) { - FixUniqueIdentity(easyWritableQueryable.Context, allItems); + FixUniqueIdentity(easyWritableQueryable.Context, typeof(TEntity), allItems); await InternalUpdate(easyWritableQueryable, result.Entity, false, true, true, true, cancellationToken) .AsCheckedResult(); await easyWritableQueryable.SaveChangesAsync(); @@ -1007,7 +1010,7 @@ public async Task> AddBulk(IEasyWritableQu anyUpdate = true; } } - FixUniqueIdentity(easyWritableQueryable.Context, allItems); + FixUniqueIdentity(easyWritableQueryable.Context, typeof(TEntity), allItems); } if (anyUpdate) { diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs index b35bafd..ca9745a 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs @@ -28,13 +28,12 @@ public DefaultUniqueIdentityManager(WhiteLabelInfo whiteLabelInfo) /// /// /// - /// /// /// /// /// /// - public bool UpdateUniqueIdentity(string currentUserUniqueIdentity, IContext context, TEntity entity) + public bool UpdateUniqueIdentity(string currentUserUniqueIdentity, IContext context, object entity) { if (entity is IUniqueIdentitySchema uniqueIdentitySchema) { @@ -43,7 +42,7 @@ public bool UpdateUniqueIdentity(string currentUserUniqueIdentity, ICon if (uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty()) uniqueIdentitySchema.UniqueIdentity = _whiteLabelInfo.StartUniqueIdentity; var ids = uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty() ? null : DecodeUniqueIdentity(uniqueIdentitySchema.UniqueIdentity); - if (TableIds.TryGetValue(GetContextTableName(context.ContextType, _whiteLabelInfo.MicroserviceId), out long tableId)) + if (TableIds.TryGetValue(GetContextTableName(context.ContextType, entity.GetType(), _whiteLabelInfo.MicroserviceId), out long tableId)) { if (entity is IIdSchema longIdSchema) { @@ -170,6 +169,15 @@ public string GetContextTableName(Type contextType, long microserviceId return GetContextTableName(microserviceId, GetContextName(contextType), GetTableName(typeof(TEntity))); } + /// + /// + /// + /// + public string GetContextTableName(Type contextType, Type tableType, long microserviceId) + { + return GetContextTableName(microserviceId, GetContextName(contextType), GetTableName(tableType)); + } + /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index fcb3fff..3a1b414 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.98 + 0.0.0.99 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 ba09605..bfd5981 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.98 + 0.0.0.99 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 e019bdc..9c8dc88 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.98 + 0.0.0.99 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational