diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index b21819f..ed3534f 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.64 + 0.0.0.65 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IReadableQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IReadableQueryServiceController.cs new file mode 100644 index 0000000..e745813 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IReadableQueryServiceController.cs @@ -0,0 +1,87 @@ +using EasyMicroservices.Cores.Contracts.Requests; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.Cores.Interfaces; +using EasyMicroservices.ServiceContracts; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + + +namespace EasyMicroservices.Cores.AspCoreApi.Interfaces; +/// +/// +/// +/// +/// +/// +/// +/// +/// +public interface IReadableQueryServiceController + where TResponseContract : class + where TEntity : class + where TFilterContract : FilterRequestContract +{ + /// + /// + /// + protected IContractReadableLogic ContractLogic { get; set; } + + /// + /// + /// + protected IBaseUnitOfWork UnitOfWork { get; } + + /// + /// + /// + /// + /// + /// + public Task> GetById(TIdRequestContract request, CancellationToken cancellationToken = default); + + /// + /// + /// + /// + /// + /// + public Task> GetByUniqueIdentity(TUniqueIdentityRequestContract request, CancellationToken cancellationToken = default); + + /// + /// + /// + /// + /// + /// + public Task> Filter(TFilterContract filterRequest, CancellationToken cancellationToken = default); + + /// + /// + /// + /// + /// + public Task> GetAll(CancellationToken cancellationToken = default); + + /// + /// + /// + /// + /// + /// + public Task> GetAllByUniqueIdentity(TUniqueIdentityRequestContract request, CancellationToken cancellationToken = default); + + /// + /// + /// + /// + protected Func, IQueryable> OnGetQuery(); + + /// + /// + /// + /// + protected Func, IQueryable> OnGetAllQuery(); +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualReadableQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualReadableQueryServiceController.cs new file mode 100644 index 0000000..07753b1 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualReadableQueryServiceController.cs @@ -0,0 +1,244 @@ +using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.Contracts.Requests; +using EasyMicroservices.Cores.Contracts.Requests.Multilingual; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.Cores.Interfaces; +using EasyMicroservices.ServiceContracts; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + + +namespace EasyMicroservices.Cores.AspCoreApi; +/// +/// +/// +/// +/// +/// +/// +/// +[ApiController] +[Route("api/[controller]/[action]")] +public class MultilingualReadableQueryServiceController : + ControllerBase, IReadableQueryServiceController, UniqueIdentityLanguageRequestContract> + where TResponseContract : class + where TLanguageResponseContract : class + where TEntity : class + where TFilterContract : FilterRequestContract +{ + /// + /// + /// + public virtual IContractReadableLogic ContractLogic { get; set; } + + /// + /// + /// + public virtual IBaseUnitOfWork UnitOfWork { get; } + + /// + /// + /// + /// + public MultilingualReadableQueryServiceController(IContractReadableLogic contractReadable) + { + ContractLogic = contractReadable; + } + + /// + /// + /// + /// + /// + public MultilingualReadableQueryServiceController(IBaseUnitOfWork unitOfWork, IContractReadableLogic contractReadable) + { + ContractLogic = contractReadable; + UnitOfWork = unitOfWork; + } + /// + /// + /// + /// + /// + public MultilingualReadableQueryServiceController(IBaseUnitOfWork unitOfWork) + { + ContractLogic = unitOfWork.GetReadableContractLogic(); + } + + async Task> ResolveContentLanguage(MessageContract result, string languageShortName) + { + if (!result) + return result; + var contentResolver = UnitOfWork.GetContentResolver(); + await contentResolver.ResolveContentLanguage(result.Result, languageShortName); + return result; + } + + async Task> ResolveContentLanguage(ListMessageContract result, string languageShortName) + { + if (!result) + return result; + var contentResolver = UnitOfWork.GetContentResolver(); + await contentResolver.ResolveContentLanguage(result.Result, languageShortName); + return result; + } + + async Task> ResolveContentAllLanguage(MessageContract result) + { + if (!result) + return result.ToContract(); + var contentResolver = UnitOfWork.GetContentResolver(); + var mapper = UnitOfWork.GetMapper(); + var mapped = mapper.Map(result.Result); + await contentResolver.ResolveContentAllLanguage(mapped); + return mapped; + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task> GetById(IdLanguageRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetById(request, OnGetQuery(), cancellationToken); + return await ResolveContentLanguage(result, request.LanguageShortName); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public async Task> GetByIdAllLanguage(IdRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetById(request, OnGetQuery(), cancellationToken); + return await ResolveContentAllLanguage(result); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task> GetByUniqueIdentity(UniqueIdentityLanguageRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetByUniqueIdentity(request, request.Type, OnGetQuery(), cancellationToken); + return await ResolveContentLanguage(result, request.LanguageShortName); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public async Task> GetByUniqueIdentityAllLanguage(UniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetByUniqueIdentity(request, request.Type, OnGetQuery(), cancellationToken); + return await ResolveContentAllLanguage(result); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task> Filter(TFilterContract filterRequest, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.Filter(filterRequest, OnGetAllQuery(), cancellationToken); + return await ResolveContentLanguage(result, filterRequest.LanguageShortName); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public async Task> FilterAllLanguage(TFilterContract filterRequest, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.Filter(filterRequest, OnGetAllQuery(), cancellationToken); + return await ResolveContentAllLanguage(result); + } + + /// + /// + /// + /// + /// + [HttpGet] + public virtual async Task> GetAll(CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetAll(OnGetAllQuery(), cancellationToken); + return await ResolveContentLanguage(result, default); + } + + /// + /// + /// + /// + /// + [HttpPost] + public async Task> GetAllWithAllLanguage(CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetAll(OnGetAllQuery(), cancellationToken); + return await ResolveContentAllLanguage(result); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task> GetAllByUniqueIdentity(UniqueIdentityLanguageRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetAllByUniqueIdentity(request, request.Type, OnGetAllQuery(), cancellationToken); + return await ResolveContentLanguage(result, request.LanguageShortName); + } + /// + /// + /// + /// + /// + /// + [HttpPost] + public async Task> GetAllByUniqueIdentityAllLanguage(UniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + { + var result = await ContractLogic.GetAllByUniqueIdentity(request, request.Type, OnGetAllQuery(), cancellationToken); + return await ResolveContentAllLanguage(result); + } + + /// + /// + /// + /// + public virtual Func, IQueryable> OnGetQuery() + { + return null; + } + + /// + /// + /// + /// + public virtual Func, IQueryable> OnGetAllQuery() + { + return null; + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualSimpleQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualSimpleQueryServiceController.cs new file mode 100644 index 0000000..e152a46 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/MultilingualSimpleQueryServiceController.cs @@ -0,0 +1,291 @@ +using EasyMicroservices.Cores.Contracts.Requests; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.Cores.Interfaces; +using EasyMicroservices.ServiceContracts; +using Microsoft.AspNetCore.Mvc; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace EasyMicroservices.Cores.AspCoreApi; +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +[ApiController] +[Route("api/[controller]/[action]")] +public class MultilingualSimpleQueryServiceController : MultilingualReadableQueryServiceController + where TResponseContract : class + where TLanguageResponseContract : class + where TEntity : class + where TFilterRequestContract : FilterRequestContract +{ + /// + /// + /// + /// + /// + public MultilingualSimpleQueryServiceController(IContractLogic contractLogic) : base(contractLogic) + { + } + + /// + /// + /// + /// + /// + public MultilingualSimpleQueryServiceController(IBaseUnitOfWork unitOfWork) : base(unitOfWork, unitOfWork.GetContractLogic()) + { + } + + /// + /// + /// + protected virtual IContractLogic WritableContractLogic + { + get + { + return ContractLogic as IContractLogic; + } + } + + string GetUniqueIdentity(T item) + { + if (item is IUniqueIdentitySchema uniqueIdentitySchema) + return uniqueIdentitySchema.UniqueIdentity; + return (string)item.GetType() + .GetProperty(nameof(IUniqueIdentitySchema.UniqueIdentity), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance) + ?.GetValue(item, null); + } + + void SetUniqueIdentity(T item, string value) + { + if (item is IUniqueIdentitySchema uniqueIdentitySchema) + uniqueIdentitySchema.UniqueIdentity = value; + else + item.GetType() + .GetProperty(nameof(IUniqueIdentitySchema.UniqueIdentity), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance) + ?.SetValue(item, value); + } + + async Task> AddToContentLanguage(MessageContract messageContract, params object[] requests) + { + if (!messageContract) + return messageContract; + var contentResolver = UnitOfWork.GetContentResolver(); + var addedItem = await GetById(new Contracts.Requests.Multilingual.IdLanguageRequestContract { Id = messageContract }) + .AsCheckedResult(); + foreach (var request in requests) + { + SetUniqueIdentity(request, GetUniqueIdentity(addedItem)); + } + await contentResolver.AddToContentLanguage(requests); + return messageContract; + } + + async Task> AddToContentLanguage(ListMessageContract messageContract, params object[] requests) + { + if (!messageContract) + return messageContract; + var contentResolver = UnitOfWork.GetContentResolver(); + foreach (var item in messageContract.Result) + { + var addedItem = await GetById(new Contracts.Requests.Multilingual.IdLanguageRequestContract { Id = item }) + .AsCheckedResult(); + foreach (var request in requests) + { + SetUniqueIdentity(request, GetUniqueIdentity(addedItem)); + } + } + await contentResolver.AddToContentLanguage(requests); + return messageContract; + } + + async Task> UpdateToContentLanguage(MessageContract messageContract, params object[] requests) + { + if (!messageContract) + return messageContract; + var contentResolver = UnitOfWork.GetContentResolver(); + foreach (var request in requests) + { + SetUniqueIdentity(request, GetUniqueIdentity(messageContract.Result)); + } + await contentResolver.UpdateToContentLanguage(requests); + return messageContract; + } + + async Task UpdateToContentLanguage(MessageContract messageContract, params object[] requests) + { + if (!messageContract) + return messageContract; + var contentResolver = UnitOfWork.GetContentResolver(); + await contentResolver.UpdateToContentLanguage(requests.Where(x=> GetUniqueIdentity(x).HasValue())); + return messageContract; + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task> Add(TCreateRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.Add(request, cancellationToken); + return await AddToContentLanguage(result, request); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual async Task AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.AddBulk(request, cancellationToken); + return await AddToContentLanguage(result, request); + } + + /// + /// + /// + /// + /// + /// + [HttpPut] + public virtual async Task> Update(TUpdateRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.Update(request, cancellationToken); + return await UpdateToContentLanguage(result, request); + } + + /// + /// + /// + /// + /// + /// + [HttpPut] + public virtual async Task> UpdateChangedValuesOnly(TUpdateRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.UpdateChangedValuesOnly(request, cancellationToken); + return await UpdateToContentLanguage(result, request); + } + + /// + /// + /// + /// + /// + /// + [HttpPut] + public virtual async Task UpdateBulk(UpdateBulkRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.UpdateBulk(request, cancellationToken); + return await UpdateToContentLanguage(result, request.Items); + } + + /// + /// + /// + /// + /// + /// + [HttpPut] + public virtual async Task UpdateBulkChangedValuesOnly(UpdateBulkRequestContract request, CancellationToken cancellationToken = default) + { + var result = await WritableContractLogic.UpdateBulk(request, cancellationToken); + return await UpdateToContentLanguage(result, request.Items); + } + + /// + /// + /// + /// + /// + /// + [HttpDelete] + public virtual Task HardDeleteById(DeleteRequestContract request, CancellationToken cancellationToken = default) + { + return WritableContractLogic.HardDeleteById(request, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + [HttpDelete] + public virtual Task HardDeleteBulkByIds(DeleteBulkRequestContract request, CancellationToken cancellationToken = default) + { + return WritableContractLogic.HardDeleteBulkByIds(request, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + [HttpDelete] + public virtual Task SoftDeleteById(SoftDeleteRequestContract request, CancellationToken cancellationToken = default) + { + return WritableContractLogic.SoftDeleteById(request, cancellationToken); + } + /// + /// + /// + /// + /// + /// + [HttpDelete] + public virtual Task SoftDeleteBulkByIds(SoftDeleteBulkRequestContract request, CancellationToken cancellationToken = default) + { + return WritableContractLogic.SoftDeleteBulkByIds(request, cancellationToken); + } +} + +/// +/// +/// +/// +/// +/// +/// +/// +/// +[ApiController] +[Route("api/[controller]/[action]")] +public class MultilingualSimpleQueryServiceController : MultilingualSimpleQueryServiceController + where TResponseContract : class + where TLanguageResponseContract : class + where TEntity : class +{ + /// + /// + /// + /// + public MultilingualSimpleQueryServiceController(IContractLogic contractLogic) : base(contractLogic) + { + } + + /// + /// + /// + /// + /// + public MultilingualSimpleQueryServiceController(IBaseUnitOfWork unitOfWork) : base(unitOfWork) + { + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs index f507a85..15ff1d9 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs @@ -1,4 +1,5 @@ -using EasyMicroservices.Cores.Contracts.Requests; +using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.Contracts.Requests; using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.Cores.Interfaces; using EasyMicroservices.ServiceContracts; @@ -19,20 +20,22 @@ namespace EasyMicroservices.Cores.AspCoreApi /// [ApiController] [Route("api/[controller]/[action]")] - public class ReadableQueryServiceController : ControllerBase - where TResponseContract : class - where TEntity : class - where TFilterContract : FilterRequestContract + public class ReadableQueryServiceController : + ControllerBase, IReadableQueryServiceController, UniqueIdentityRequestContract> + where TResponseContract : class + where TEntity : class + where TFilterContract : FilterRequestContract { /// /// /// - protected virtual IContractReadableLogic ContractLogic { get; private set; } + public virtual IContractReadableLogic ContractLogic { get; set; } /// /// /// - protected virtual IBaseUnitOfWork UnitOfWork { get; } + public virtual IBaseUnitOfWork UnitOfWork { get; } + /// /// /// @@ -68,7 +71,7 @@ public ReadableQueryServiceController(IBaseUnitOfWork unitOfWork) /// /// [HttpPost] - public virtual Task> GetById(GetIdRequestContract request, CancellationToken cancellationToken = default) + public virtual Task> GetById(IdRequestContract request, CancellationToken cancellationToken = default) { return ContractLogic.GetById(request, OnGetQuery(), cancellationToken); } @@ -80,7 +83,7 @@ public virtual Task> GetById(GetIdRequestCont /// /// [HttpPost] - public virtual Task> GetByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + public virtual Task> GetByUniqueIdentity(UniqueIdentityRequestContract request, CancellationToken cancellationToken = default) { return ContractLogic.GetByUniqueIdentity(request, request.Type, OnGetQuery(), cancellationToken); } @@ -115,7 +118,7 @@ public virtual Task> GetAll(CancellationT /// /// [HttpPost] - public virtual Task> GetAllByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + public virtual Task> GetAllByUniqueIdentity(UniqueIdentityRequestContract request, CancellationToken cancellationToken = default) { return ContractLogic.GetAllByUniqueIdentity(request, request.Type, OnGetAllQuery(), cancellationToken); } @@ -124,7 +127,7 @@ public virtual Task> GetAllByUniqueIdenti /// /// /// - protected virtual Func, IQueryable> OnGetQuery() + public virtual Func, IQueryable> OnGetQuery() { return null; } @@ -133,7 +136,7 @@ protected virtual Func, IQueryable> OnGetQuery() /// /// /// - protected virtual Func, IQueryable> OnGetAllQuery() + public virtual Func, IQueryable> OnGetAllQuery() { return null; } diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs index 520edfc..726f3d0 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs @@ -74,7 +74,7 @@ public virtual Task> Add(TCreateRequestContract request, Ca [HttpPost] public virtual Task AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) { - return WritableContractLogic.AddBulk(request, cancellationToken); + return WritableContractLogic.AddBulk(request, cancellationToken).ToContract(); } /// diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index 6d4c7a6..2786b6b 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.64 + 0.0.0.65 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore @@ -20,8 +20,9 @@ - + + diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/InternalContentResolver.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/InternalContentResolver.cs new file mode 100644 index 0000000..c13925c --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/InternalContentResolver.cs @@ -0,0 +1,37 @@ +using EasyMicroservices.ContentsMicroservice.Clients.Helpers; +using EasyMicroservices.Cores.Interfaces; +using EasyMicroservices.ServiceContracts; +using System; +using System.Collections; +using System.Threading.Tasks; + +namespace EasyMicroservices.Cores.AspEntityFrameworkCoreApi; +internal class InternalContentResolver : IContentResolver +{ + readonly ContentLanguageHelper _contentLanguageHelper; + public InternalContentResolver(ContentLanguageHelper contentLanguageHelper) + { + _contentLanguageHelper = contentLanguageHelper; + } + + public Task AddToContentLanguage(params object[] item) + { + return _contentLanguageHelper.AddToContentLanguage(item) + .AsCheckedResult(); + } + + public Task ResolveContentAllLanguage(object contract) + { + return _contentLanguageHelper.ResolveContentAllLanguage(contract); + } + + public Task ResolveContentLanguage(object contract, string language) + { + return _contentLanguageHelper.ResolveContentLanguage(contract, language); + } + + public Task UpdateToContentLanguage(params object[] item) + { + return _contentLanguageHelper.UpdateToContentLanguage(item); + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs index c01569c..690d683 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs @@ -1,4 +1,5 @@ -using EasyMicroservices.Cores.AspCoreApi.Authorizations; +using EasyMicroservices.ContentsMicroservice.Clients.Helpers; +using EasyMicroservices.Cores.AspCoreApi.Authorizations; using EasyMicroservices.Cores.AspCoreApi.Interfaces; using EasyMicroservices.Cores.AspCoreApi.Managers; using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; @@ -20,6 +21,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -79,6 +81,9 @@ public static IServiceCollection Builder(this IServiceCollection servi { option.ExceptionHandler = AppAuthorizationMiddleware.ExceptionHandler; }); + services.AddSingleton(service => new Contents.GeneratedServices.ContentClient(service.GetService().GetValue("RootAddresses:Content"), new HttpClient())); + services.AddSingleton(); + services.AddSingleton(); return services; } diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs index 619cc30..a9c3306 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs @@ -3,6 +3,7 @@ using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.Cores.Database.Logics; +using EasyMicroservices.Cores.Interfaces; using EasyMicroservices.Cores.Models; using EasyMicroservices.Cores.Relational.EntityFrameworkCore; using EasyMicroservices.Database.EntityFrameworkCore.Providers; @@ -66,6 +67,16 @@ public virtual IDatabase GetDatabase() return AddDisposable(new EntityFrameworkCoreDatabaseProvider(context)); } + /// + /// + /// + /// + /// + public IContentResolver GetContentResolver() + { + return ServiceProvider.GetService(); + } + /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index b2324a6..083250b 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.64 + 0.0.0.65 core of database. EasyMicroservices@gmail.com core,cores,base,client,clients diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs index f07f006..30a8765 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs @@ -67,6 +67,6 @@ public class FilterRequestContract /// /// en-US, fa-IR /// - public string Language { get; set; } + public string LanguageShortName { get; set; } } } diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetIdRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/IdRequestContract.cs similarity index 72% rename from src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetIdRequestContract.cs rename to src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/IdRequestContract.cs index d582d13..a8dabf0 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetIdRequestContract.cs +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/IdRequestContract.cs @@ -6,7 +6,7 @@ namespace EasyMicroservices.Cores.Contracts.Requests /// /// /// - public class GetIdRequestContract : IIdSchema + public class IdRequestContract : IIdSchema { /// /// @@ -16,9 +16,9 @@ public class GetIdRequestContract : IIdSchema /// /// /// - public static implicit operator GetIdRequestContract(T id) + public static implicit operator IdRequestContract(T id) { - return new GetIdRequestContract() + return new IdRequestContract() { Id = id }; diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/IdLanguageRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/IdLanguageRequestContract.cs new file mode 100644 index 0000000..9c1ee14 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/IdLanguageRequestContract.cs @@ -0,0 +1,36 @@ +namespace EasyMicroservices.Cores.Contracts.Requests.Multilingual; +/// +/// +/// +/// +public class IdLanguageRequestContract : IdRequestContract +{ + /// + /// + /// + public string LanguageShortName { get; set; } + /// + /// + /// + /// + public static implicit operator IdLanguageRequestContract(T id) + { + return new IdLanguageRequestContract() + { + Id = id + }; + } + + /// + /// + /// + /// + public static implicit operator IdLanguageRequestContract((T Id, string LanguageShortName) input) + { + return new IdLanguageRequestContract() + { + Id = input.Id, + LanguageShortName = input.LanguageShortName + }; + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/UniqueIdentityLanguageRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/UniqueIdentityLanguageRequestContract.cs new file mode 100644 index 0000000..d2338c5 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/Multilingual/UniqueIdentityLanguageRequestContract.cs @@ -0,0 +1,36 @@ +namespace EasyMicroservices.Cores.Contracts.Requests.Multilingual; +/// +/// +/// +public class UniqueIdentityLanguageRequestContract : UniqueIdentityRequestContract +{ + /// + /// + /// + public string LanguageShortName { get; set; } + + /// + /// + /// + /// + public static implicit operator UniqueIdentityLanguageRequestContract(string uniqueIdentity) + { + return new UniqueIdentityLanguageRequestContract() + { + UniqueIdentity = uniqueIdentity + }; + } + + /// + /// + /// + /// + public static implicit operator UniqueIdentityLanguageRequestContract((string UniqueIdentity, string LanguageShortName) input) + { + return new UniqueIdentityLanguageRequestContract() + { + UniqueIdentity = input.UniqueIdentity, + LanguageShortName = input.LanguageShortName + }; + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetUniqueIdentityRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/UniqueIdentityRequestContract.cs similarity index 77% rename from src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetUniqueIdentityRequestContract.cs rename to src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/UniqueIdentityRequestContract.cs index d7cab7b..1467a11 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/GetUniqueIdentityRequestContract.cs +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/UniqueIdentityRequestContract.cs @@ -6,7 +6,7 @@ namespace EasyMicroservices.Cores.Contracts.Requests /// /// /// - public class GetUniqueIdentityRequestContract : IUniqueIdentitySchema + public class UniqueIdentityRequestContract : IUniqueIdentitySchema { /// /// @@ -21,9 +21,9 @@ public class GetUniqueIdentityRequestContract : IUniqueIdentitySchema /// /// /// - public static implicit operator GetUniqueIdentityRequestContract(string uniqueIdentity) + public static implicit operator UniqueIdentityRequestContract(string uniqueIdentity) { - return new GetUniqueIdentityRequestContract() + return new UniqueIdentityRequestContract() { UniqueIdentity = uniqueIdentity }; diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 744386d..4f96b19 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.64 + 0.0.0.65 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs index 86d1605..9efb84a 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs @@ -24,7 +24,7 @@ public interface IReadableLogic /// /// /// - Task> GetById(GetIdRequestContract idRequest, CancellationToken cancellationToken = default); + Task> GetById(IdRequestContract idRequest, CancellationToken cancellationToken = default); /// /// /// @@ -64,7 +64,7 @@ public interface IContractReadableLogic : IReadableLogi /// /// /// - Task> GetById(GetIdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default); + Task> GetById(IdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default); /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IWritableLogic.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IWritableLogic.cs index a9476f6..e9dde22 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IWritableLogic.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IWritableLogic.cs @@ -94,7 +94,7 @@ public interface IContractWritableLogic /// /// - Task AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default); + Task> AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default); /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs index abb284b..e0a604e 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs @@ -61,7 +61,7 @@ public DatabaseLogicBase(IEasyReadableQueryableAsync easyReadableQuerya /// /// /// - public async Task> GetById(GetIdRequestContract idRequest, CancellationToken cancellationToken = default) + public async Task> GetById(IdRequestContract idRequest, CancellationToken cancellationToken = default) { return await GetById(_easyReadableQueryable, idRequest, null, cancellationToken); } @@ -73,7 +73,7 @@ public async Task> GetById(GetIdRequestContract id /// /// /// - public async Task> GetById(GetIdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default) + public async Task> GetById(IdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index da6d24f..6531863 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -103,7 +103,7 @@ private async Task> UniqueIdentityQueryMake /// /// /// - protected async Task> GetById(IEasyReadableQueryableAsync easyReadableQueryable, GetIdRequestContract idRequest, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + protected async Task> GetById(IEasyReadableQueryableAsync easyReadableQueryable, IdRequestContract idRequest, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) where TEntity : class { IEasyReadableQueryableAsync queryable = easyReadableQueryable; @@ -230,7 +230,7 @@ public async Task> GetBy(IEasyRea /// /// /// - protected async Task> GetById(IEasyReadableQueryableAsync easyReadableQueryable, GetIdRequestContract idRequest, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + protected async Task> GetById(IEasyReadableQueryableAsync easyReadableQueryable, IdRequestContract idRequest, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) where TEntity : class where TContract : class { @@ -762,7 +762,7 @@ public async Task> Add(IEasyWritableQueryableA /// /// /// - public async Task AddBulk(IEasyWritableQueryableAsync easyWritableQueryable, IEnumerable entities, CancellationToken cancellationToken = default) + public async Task> AddBulk(IEasyWritableQueryableAsync easyWritableQueryable, IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class { var result = await easyWritableQueryable.AddBulkAsync(entities, cancellationToken); @@ -793,7 +793,7 @@ public async Task AddBulk(IEasyWritableQueryableAsync< await InternalUpdateBulk(easyWritableQueryable, result.Select(x => x.Entity).ToList(), false, true, true, cancellationToken); await easyWritableQueryable.SaveChangesAsync(); } - return true; + return result.Select(x => x.Entity).ToList(); } /// @@ -822,7 +822,7 @@ public async Task> Add(IEasyWritabl /// /// /// - public async Task AddBulk(IEasyWritableQueryableAsync easyWritableQueryable, CreateBulkRequestContract request, CancellationToken cancellationToken = default) + public async Task> AddBulk(IEasyWritableQueryableAsync easyWritableQueryable, CreateBulkRequestContract request, CancellationToken cancellationToken = default) where TEntity : class { var entities = await MapToListAsync(request.Items); diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs index 8c9a808..d756339 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs @@ -3,9 +3,9 @@ using EasyMicroservices.Cores.DataTypes; using EasyMicroservices.Cores.Interfaces; using EasyMicroservices.Database.Interfaces; -using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -76,7 +76,7 @@ public async Task> GetAll(CancellationTok /// /// /// - public virtual Task> GetById(GetIdRequestContract contract, Func, IQueryable> query = default, CancellationToken cancellationToken = default) + public virtual Task> GetById(IdRequestContract contract, Func, IQueryable> query = default, CancellationToken cancellationToken = default) { throw new Exception("GetById is not supported in DatabaseMappedLogicBase, you can use IdSchemaDatabaseMappedLogicBase or override this GetById method"); } @@ -119,10 +119,14 @@ public async Task> Add(TCreateRequestContract /// /// /// - public async Task AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) + public async Task> AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) { - var result = await Add(_easyWriteableQueryable, request, cancellationToken); - return result; + var result = await AddBulk(_easyWriteableQueryable, request, cancellationToken); + if (!result) + return result.ToListContract(); + var mapped = await MapAsync, List>(result.Result); + ValidateMappedResult(ref mapped); + return mapped; } /// @@ -186,7 +190,7 @@ public async Task> GetAll(Func /// /// - public Task> GetById(GetIdRequestContract contract, CancellationToken cancellationToken = default) + public Task> GetById(IdRequestContract contract, CancellationToken cancellationToken = default) { throw new Exception("GetById is not supported in DatabaseMappedLogicBase, you can use IdSchemaDatabaseMappedLogicBase or override this GetById method"); } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs index 3a04e71..baddd71 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs @@ -3,9 +3,9 @@ using EasyMicroservices.Cores.DataTypes; using EasyMicroservices.Cores.Interfaces; using EasyMicroservices.Database.Interfaces; -using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -77,7 +77,7 @@ public async Task> GetAll(CancellationTok /// /// /// - public async Task> GetById(GetIdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default) + public async Task> GetById(IdRequestContract idRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = UpdateFunctionQuery(query); return await GetById(_easyReadableQueryable, idRequest, func, cancellationToken); @@ -122,9 +122,22 @@ public async Task> Add(TCreateRequestContract contract, Can /// /// /// - public Task AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) + public async Task> AddBulk(CreateBulkRequestContract request, CancellationToken cancellationToken = default) { - return AddBulk(_easyWriteableQueryable, request, cancellationToken); + var result = await AddBulk(_easyWriteableQueryable, request, cancellationToken); + if (result) + { + List items = new List(); + foreach (var item in result.Result) + { + if (item is IIdSchema schema) + items.Add(schema.Id); + else + items.Add(MapperProvider.Map(item)); + } + return items; + } + return result.ToListContract(); } /// @@ -182,7 +195,7 @@ public Task> Filter(FilterRequestContract /// /// /// - public Task> GetById(GetIdRequestContract idRequest, CancellationToken cancellationToken = default) + public Task> GetById(IdRequestContract idRequest, CancellationToken cancellationToken = default) { return GetById(_easyReadableQueryable, idRequest, null, cancellationToken); } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 930783b..dbfc2ac 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.64 + 0.0.0.65 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IBaseUnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IBaseUnitOfWork.cs index c3c22d3..0526f2a 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IBaseUnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IBaseUnitOfWork.cs @@ -38,6 +38,11 @@ public interface IBaseUnitOfWork : IDisposable /// /// /// + /// + IContentResolver GetContentResolver(); + /// + /// + /// /// /// IContractLogic GetLongLogic() diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IContentResolver.cs b/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IContentResolver.cs new file mode 100644 index 0000000..1351726 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.Database/Interfaces/IContentResolver.cs @@ -0,0 +1,36 @@ +using EasyMicroservices.ServiceContracts; +using System.Collections; +using System.Threading.Tasks; + +namespace EasyMicroservices.Cores.Interfaces; +/// +/// +/// +public interface IContentResolver +{ + /// + /// + /// + /// + /// + /// + Task ResolveContentLanguage(object contract, string language); + /// + /// + /// + /// + /// + Task AddToContentLanguage(params object[] item); + /// + /// + /// + /// + /// + Task UpdateToContentLanguage(params object[] item); + /// + /// + /// + /// + /// + Task ResolveContentAllLanguage(object contract); +} diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 12f9da2..9665918 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.64 + 0.0.0.65 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 0363db4..254aefc 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.64 + 0.0.0.65 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs index 1a8f723..bd95403 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs @@ -113,7 +113,7 @@ public async Task AddAsync(string userName) var user = await logic.Add(addUser); Assert.True(user.IsSuccess); Assert.True(user.Result > 0); - var foundUser = await logic.GetById(new GetIdRequestContract() + var foundUser = await logic.GetById(new IdRequestContract() { Id = user.Result }); @@ -253,7 +253,7 @@ public async Task UpdateAsync(string userName, string toUserName) Assert.Equal(updateResult.Result.CreationDateTime, added.CreationDateTime); Assert.True(updateResult.Result.CreationDateTime > DateTime.Now.AddMinutes(-5)); Assert.True(updateResult.Result.ModificationDateTime > DateTime.Now.AddMinutes(-5)); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -283,7 +283,7 @@ public async Task UpdateChangedValuesOnlyAsync(string userName) Assert.Equal(updateResult.Result.CreationDateTime, added.CreationDateTime); Assert.True(updateResult.Result.CreationDateTime > DateTime.Now.AddMinutes(-5)); Assert.True(updateResult.Result.ModificationDateTime > DateTime.Now.AddMinutes(-5)); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -389,14 +389,14 @@ public async Task UniqueIdentityAsync(string userName) { await using var logic = GetContractLogic(); var added = await AddAsync(userName); - var found = await logic.GetByUniqueIdentity(new GetUniqueIdentityRequestContract() + var found = await logic.GetByUniqueIdentity(new UniqueIdentityRequestContract() { UniqueIdentity = added.UniqueIdentity }); Assert.Equal(found.Result.UserName, userName); CheckUniqueIdentity(found.Result.UniqueIdentity); - var foundAll = await logic.GetAllByUniqueIdentity(new GetUniqueIdentityRequestContract() + var foundAll = await logic.GetAllByUniqueIdentity(new UniqueIdentityRequestContract() { UniqueIdentity = DefaultUniqueIdentityManager.CutUniqueIdentityFromEnd(added.UniqueIdentity, 2) }); @@ -407,7 +407,7 @@ public async Task UniqueIdentityAsync(string userName) var addedProfile = await AddProfileAsync(added.Id, $"Ali{i}"); } await using var profileLogic = GetProfileContractLogic(); - var foundAllProfiles = await profileLogic.GetAllByUniqueIdentity(new GetUniqueIdentityRequestContract() + var foundAllProfiles = await profileLogic.GetAllByUniqueIdentity(new UniqueIdentityRequestContract() { UniqueIdentity = added.UniqueIdentity }); @@ -415,7 +415,7 @@ public async Task UniqueIdentityAsync(string userName) Assert.Contains(foundAllProfiles.Result, x => x.FirstName.StartsWith("Ali")); Assert.Equal(foundAllProfiles.Result.Count, 10); - var onlyUniqueIdentity = await profileLogic.GetByUniqueIdentity(new GetUniqueIdentityRequestContract() + var onlyUniqueIdentity = await profileLogic.GetByUniqueIdentity(new UniqueIdentityRequestContract() { UniqueIdentity = added.UniqueIdentity }, default, q => q.Where(x => x.FirstName == "Ali5")); @@ -432,7 +432,7 @@ public async Task HardDeleteAsync(string userName) { await using var logic = GetContractLogic(); var added = await AddAsync(userName); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -442,7 +442,7 @@ public async Task HardDeleteAsync(string userName) Id = found.Result.Id }); Assert.True(deleted); - found = await logic.GetById(new GetIdRequestContract() + found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -458,7 +458,7 @@ public async Task HardDeleteBulkAsync(string name, string[] userNames) foreach (var item in userNames) { UserEntity added = await AddAsync(item); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -472,7 +472,7 @@ public async Task HardDeleteBulkAsync(string name, string[] userNames) Assert.True(deleted); foreach (var item in ids) { - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = item }); @@ -487,7 +487,7 @@ public async Task SoftDeleteAsync(string userName) { await using var logic = GetContractLogic(); var added = await AddAsync(userName); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -498,7 +498,7 @@ public async Task SoftDeleteAsync(string userName) IsDelete = true }); Assert.True(deleted); - found = await logic.GetById(new GetIdRequestContract() + found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -560,7 +560,7 @@ public async Task SoftDeleteBulkByIdsAsync(string name, string[] userNames) foreach (var userName in userNames) { var added = await AddAsync(userName); - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = added.Id }); @@ -576,7 +576,7 @@ public async Task SoftDeleteBulkByIdsAsync(string name, string[] userNames) Assert.True(deleted); foreach (var item in ids) { - var found = await logic.GetById(new GetIdRequestContract() + var found = await logic.GetById(new IdRequestContract() { Id = item }); @@ -598,7 +598,7 @@ public async Task SelfChildTestAsync(string parentName, string[] chilren) var user = await logic.Add(addUser); Assert.True(user.IsSuccess); Assert.True(user.Result > 0); - var foundUser = await logic.GetById(new GetIdRequestContract() + var foundUser = await logic.GetById(new IdRequestContract() { Id = user.Result }); @@ -647,7 +647,7 @@ public async Task ChildTestAsync(string parentName, string[] chilren) var user = await logic.Add(addUser); Assert.True(user.IsSuccess); Assert.True(user.Result > 0); - var foundUser = await logic.GetById(new GetIdRequestContract() + var foundUser = await logic.GetById(new IdRequestContract() { Id = user.Result });