From 82f45d421ce253ed4d52de1d21b14ec66c008787 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 27 Sep 2023 13:49:56 +0330 Subject: [PATCH] Support for easy add and update to content --- ...rvices.ContentsMicroservice.Clients.csproj | 2 +- .../Helpers/ContentLanguageHelper.cs | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/EasyMicroservices.ContentsMicroservice.Clients.csproj b/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/EasyMicroservices.ContentsMicroservice.Clients.csproj index 5938933..3e66a19 100644 --- a/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/EasyMicroservices.ContentsMicroservice.Clients.csproj +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/EasyMicroservices.ContentsMicroservice.Clients.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.10 + 0.0.0.11 client generated code. EasyMicroservices@gmail.com microservice,Content,Contents,client diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/Helpers/ContentLanguageHelper.cs b/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/Helpers/ContentLanguageHelper.cs index 464e374..329e571 100644 --- a/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/Helpers/ContentLanguageHelper.cs +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Clients/Helpers/ContentLanguageHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -84,5 +85,73 @@ bool IsClass(Type type) { return type.GetTypeInfo().IsClass && typeof(string) != type && typeof(char[]) != type; } + + /// + /// + /// + /// + /// + /// + /// + public async Task AddToContent(string uniqueRecordId, string name, IEnumerable languages) + { + var addNames = await _contentClient.AddContentWithKeyAsync(new Contents.GeneratedServices.AddContentWithKeyRequestContract + { + Key = $"{uniqueRecordId}-{name}", + LanguageData = languages.ToList(), + }); + return addNames; + } + + /// + /// + /// + /// + /// + public async Task AddToContent(params (string UniqueRecordId, string Name, IEnumerable Languages)[] items) + { + CategoryContractMessageContract result = default; + foreach (var item in items) + { + result = await AddToContent(item.UniqueRecordId, item.Name, item.Languages); + if (!result.IsSuccess) + return result; + } + return result; + } + + /// + /// + /// + /// + /// + /// + /// + public async Task UpdateToContent(string uniqueRecordId, string name, IEnumerable languages) + { + var addNames = await _contentClient.AddContentWithKeyAsync(new Contents.GeneratedServices.AddContentWithKeyRequestContract + { + Key = $"{uniqueRecordId}-{name}", + LanguageData = languages.ToList(), + }); + return addNames; + } + + /// + /// + /// + /// + /// + public async Task UpdateToContent(params (string UniqueRecordId, string Name, IEnumerable Languages)[] items) + { + CategoryContractMessageContract result = default; + foreach (var item in items) + { + result = await UpdateToContent(item.UniqueRecordId, item.Name, item.Languages); + if (!result.IsSuccess) + return result; + } + return result; + } } }