From c0618a5b252c8d7dc404596181af092cf9d3298c Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 6 Jun 2026 00:21:48 +0330 Subject: [PATCH] last ... --- Interfaces/IXCategoryProvider.cs | 33 ++++++- Providers/Dtos/XCategoryResourceDto.cs | 16 +++ Providers/XCategoryProvider.cs | 130 ++++++++++++++++++------- 3 files changed, 142 insertions(+), 37 deletions(-) create mode 100644 Providers/Dtos/XCategoryResourceDto.cs diff --git a/Interfaces/IXCategoryProvider.cs b/Interfaces/IXCategoryProvider.cs index 3dde505..b27044c 100644 --- a/Interfaces/IXCategoryProvider.cs +++ b/Interfaces/IXCategoryProvider.cs @@ -1,10 +1,41 @@ +using System.Threading; +using System.Threading.Tasks; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; +using xIdentityModels.Models; using xPushService.Interfaces; namespace xCategoryService.Interfaces { public interface IXCategoryProvider : IXBaseProvided - { } + { + /// + /// Load an Item by all of it's Related Translations ... + /// + /// + /// + /// + Task GetResource( + int id, + CancellationToken cancellationToken = default + ); + + /// + /// Add Category Item for Specified Language ... + /// + /// + /// + /// + /// + /// + /// + Task Add( + XCategoryDto item, + string langauge = null, + string connectionId = null, + XUserClaimsInfoDto userInfo = null, + CancellationToken cancellationToken = default + ); + } } \ No newline at end of file diff --git a/Providers/Dtos/XCategoryResourceDto.cs b/Providers/Dtos/XCategoryResourceDto.cs new file mode 100644 index 0000000..cd664f3 --- /dev/null +++ b/Providers/Dtos/XCategoryResourceDto.cs @@ -0,0 +1,16 @@ +using xCategoryService.Models.Dtos; +using xModels.Base; +using xModels.Dtos; + +namespace xCategoryService.Providers.Dtos +{ + /// + /// Represent a Category by all of it's Resources ... + /// + public class XCategoryResourceDto : XBaseDto + { + public XCategoryDto Item { get; set; } + public XResourceDto Titles { get; set; } + public XResourceDto Descriptions { get; set; } + } +} \ No newline at end of file diff --git a/Providers/XCategoryProvider.cs b/Providers/XCategoryProvider.cs index 295d375..1d23280 100644 --- a/Providers/XCategoryProvider.cs +++ b/Providers/XCategoryProvider.cs @@ -1,6 +1,3 @@ -using System; -using System.ComponentModel; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using xCategoryService.Interfaces; @@ -56,35 +53,54 @@ namespace xCategoryService.Providers return !item.IsNullOrDefault(); } - // public async Task<(string, string)> LoadResources( - // int id, - // string language = null - // ) - // { - // // - // // Normalize Language ... - // language = - // !language.IsNullOrEmpty() - // ? language - // : appConfiguration.DefaultLanguage; + /// + /// Load an Item by all of it's Related Translations ... + /// + /// + /// + /// + public async Task GetResource( + int id, + CancellationToken cancellationToken = default + ) + { + // + var category = await Get( + id: id, + includeBuilder: null, + cancellationToken: cancellationToken + ); + var titleResource = await titleResourceProvider.GetResource( + identifier: id, + cancellationToken: cancellationToken + ); + var descriptionResource = await titleResourceProvider.GetResource( + identifier: id, + cancellationToken: cancellationToken + ); - // // - // // Validate Args ... - // var isValid = - // id.IsValidIntId() && - // !language.IsNullOrEmpty(); - // if (!isValid) - // { - // XException.InvalidArgs.Throw(); - // } + // + var result = new XCategoryResourceDto + { + Item = category, + Titles = titleResource, + Descriptions = descriptionResource + }; - // // - // // Reading Resources ... - // // var title = await titleResourceProvider.GetResourceLocales() - // XException.InvalidArgs.Throw(); - // } + // + return result; + } - public async Task Add( + /// + /// Add Category Item for Specified Language ... + /// + /// + /// + /// + /// + /// + /// + public async Task Add( XCategoryDto item, string langauge = null, string connectionId = null, @@ -108,6 +124,7 @@ namespace xCategoryService.Providers } // + var id = -1; try { // @@ -117,7 +134,7 @@ namespace xCategoryService.Providers // // Add Item Pure for ID Generating ... item = await base.Add( - item: item, + item: item, userInfo: userInfo, connectionId: null, // Since here We dont want notification ... cancellationToken: cancellationToken @@ -129,7 +146,7 @@ namespace xCategoryService.Providers } // - var id = item.Id; + id = item.Id; var titleResourceTitle = await titleResourceProvider.AddOrUpdateItemResourcer( identifier: id, language: langauge, @@ -158,18 +175,59 @@ namespace xCategoryService.Providers connectionId: connectionId, cancellationToken: cancellationToken ); - var result = XCategoryTitleResourceProvider; - - // - return result; + } catch { XException.InvalidArgs.Throw(); } + // + // Validate Id ... + isValid = id.IsValidIntId(); + if (!isValid) + { + XException.ActionFailed.Throw(); + } + // - throw new NotImplementedException(); + // Retrieve Category Resourv=ce ... + var result = await GetResource( + id: id, + cancellationToken: cancellationToken + ); + + // + return result; + } + + public async Task RemoveResaource( + int id, + CancellationToken cancellationToken + ) + { + // + // Validate ... + var isValid = id.IsValidIntId(); + if (!isValid) + { + XException.InvalidArgs.Throw(); + } + + // + // Retrieve Resource ... + var resource = await GetResource( + id: id, + cancellationToken: cancellationToken + ); + isValid = !resource.IsNullOrDefault(); + if (!isValid) + { + XException.NotFound.Throw(); + } + + // + await titleResourceProvider.RemoveResource(); } } } \ No newline at end of file