### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Configurations\XCategoryServiceConfiguration.cs using xCategoryService.Models.Dtos; namespace xCategoryService.Configurations { /// /// a Configuration Class for Providing Data to Configure XCategoryService ... /// public class XCategoryServiceConfiguration { /// /// a List of Categories for Seeding ... /// public XCategoryResourceDto[] Categories { get; set; } = []; /// /// a List of SubCategories for Seeding ... /// public XSubCategoryResourceDto[] SubCategories { get; set; } = []; } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Configurations\Entities\XCategoryEntityConfiguration.cs using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using xCategoryService.Constants; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Configurations.Entities { public class XCategoryEntityConfiguration : XBaseEntityTypeConfiguration { public override void Configure(EntityTypeBuilder builder) { builder.ToTable(XCategoryServiceConstants.XCategoryTable); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Configurations\Entities\XSubCategoryEntityConfiguration.cs using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using xCategoryService.Constants; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Configurations.Entities { public class XSubCategoryEntityConfiguration : XBaseEntityTypeConfiguration { public override void Configure(EntityTypeBuilder builder) { builder.ToTable(XCategoryServiceConstants.XSubCategoryTable); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Constants\ConfigurationNodeNames.cs namespace xCategoryService.Constants { public partial struct ConfigurationNodeNames { public const string CATEGORY_SERVICE_NODE = "CategoryServiceConfiguration"; } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Constants\XCategoryServiceConstants.cs namespace xCategoryService.Constants { public struct XCategoryServiceConstants { // // Service Extensions Log Tag ... public const string XCategoryServiceDILogTag = "XCategoryService"; // // Table Mapping Identifiers ... public const string XCategoryTable = "Categories"; public const string XSubCategoryTable = "SubCategories"; // // GraphQL Collection Mappings ... public const string XCategorySingleName = "category"; public const string XCategoryCollectionName = "categories"; public const string XSubCategorySingleName = "subCategory"; public const string XSubCategoryCollectionName = "subCategories"; // // Hubs ... public const string XCategoryDtoHub = "categoryDto"; public const string XCategoryEntityHub = "categoryEntity"; public const string XSubCategoryDtoHub = "subCategoryDto"; public const string XSubCategoryEntityHub = "subCategoryEntity"; // // Custome Constants ... public const string SubCategoryReference = "SubCat"; public const string CategoryTitleResourceIdentifier = "CatT"; public const string CategoryDescriptionResourceIdentifier = "CatD"; public const string SubCategoryTitleResourceIdentifier = "SubCatT"; public const string SubCategoryDescriptionResourceIdentifier = "SubCatD"; // // EF Repositories Helper Extensions ... public const string GetXCategoryEFRepositoryDescriptor = "GetXCategoryEFRepositoryDescriptor"; public const string GetXSubCategoryEFRepositoryDescriptor = "GetXSubCategoryEFRepositoryDescriptor"; } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XCategoryProviderControllerBase.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; using xExceptions.Constants; using xIdentityService.Interfaces; using xModels.Dtos; using xPushService.Controllers; namespace xCategoryService.Controllers { public abstract class XCategoryProviderControllerBase : XBaseProvidedController, IXCategoryProviderController { private readonly IXCategoryProvider provider; protected XCategoryProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXCategoryProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { this.provider = provider; } // #region Overrides ... [NonAction] [HttpGet("{id}")] public override async Task> Get( [FromRoute] int id, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.Get( id: id, useDefaultIncludes: useDefaultIncludes, cancellationToken: cancellationToken ); } [NonAction] [HttpGet("")] public override async Task>> GetAll( [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.GetAll( useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Find/One")] public override async Task> FindOne( [FromRoute] string query, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.FindOne( query: query, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Find/Many")] public override async Task>> FindMany( [FromRoute] string query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.FindMany( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Query")] public override async Task>> Query( [FromQuery] XQuery query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.Query( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Query/Owned")] public override async Task>> QueryOwned( [FromQuery] XQuery query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.QueryOwned( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpPost("")] public override async Task> Add( [FromBody] XCategoryDto item, CancellationToken cancellationToken = default ) { // return await base.Add( item: item, cancellationToken: cancellationToken ); } [NonAction] [HttpPut("{id}")] public override async Task> Update( [FromRoute] int id, [FromBody] XCategoryDto item, CancellationToken cancellationToken = default ) { // return await base.Update( id: id, item: item, cancellationToken: cancellationToken ); } [NonAction] [HttpDelete("{id}")] public override async Task> Remove( [FromRoute] int id, CancellationToken cancellationToken = default ) { // return await base.Remove( id: id, cancellationToken: cancellationToken ); } #endregion // #region Actions ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// [HttpGet("Resources/{id}/HasLocale")] public virtual async Task> HasLocale( [FromRoute] int id, [FromQuery] string language, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } ValidationProvider.NotEmpty(language); // var result = await provider.HasLocale( id: id, language: language, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// [HttpGet("Resources/{id}")] public virtual async Task> GetResource( [FromRoute] int id, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } // var result = await provider.GetResource( id: id, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Category Item for Specified Language ... /// /// /// /// /// [HttpPost("Resources")] public virtual async Task> Add( [FromBody] XCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotEmpty(language) .AddNotEmpty(item.Title) .AddNotEmpty(item.Description) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Add( item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Category Item for by It's Locales ... /// /// /// /// [HttpPost("Resources/AddResource")] public virtual async Task> AddResource( [FromBody] XCategoryResourceDto item, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotNull(item.Titles) .AddNotZeroChilds(item.Titles.Locales) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.AddResource( item: item, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// [HttpDelete("Resources/{id}")] public virtual async Task> Remove( [FromRoute] int id, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Remove( id: id, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Update a Category Item for Specified Language ... /// /// /// /// /// /// [HttpPut("Resources/{id}")] public virtual async Task> Update( [FromRoute] int id, [FromBody] XCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotEmpty(language) .AddNotEmpty(item.Title) .AddNotEmpty(item.Description) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Update( id: id, item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Refresh a Resource ... /// /// /// /// [HttpPost("Resources/Refresh")] public virtual async Task> Refresh( [FromBody] XCategoryResourceDto resource, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(resource) .AddNotNull(resource.Item) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Get All Resources ... /// /// /// [HttpGet("Resources/All")] public virtual async Task>> GetAllResources( CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } // var result = await provider.GetAllResources( cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Find One Resource ... /// /// /// /// [HttpGet("Resources/Find/One")] public virtual async Task> FindOneResource( [FromQuery] string query, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotEmpty(query) .ValidateGroupAsync(); // var result = await provider.FindOneResource( cancellationToken: cancellationToken, predicate: x => x.PropValuesContains(query) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Find Many Resource ... /// /// /// /// [HttpGet("Resources/Find/Many")] public virtual async Task>> FindManyResource( [FromQuery] string query, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotEmpty(query) .ValidateGroupAsync(); // var result = await provider.FindManyResource( cancellationToken: cancellationToken, predicate: x => x.PropValuesContains(query), orderBuilder: x => x.OrderBy(y => y.Item.Id) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// [HttpGet("Resources/Query")] public virtual async Task>> QueryResources( [FromQuery] XQuery query = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(query) .ValidateGroupAsync(); // var result = await provider.QueryResources( query: query, predicate: null, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Item.Id) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XCategoryRepositoryControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; namespace xCategoryService.Controllers { public abstract class XCategoryRepositoryControllerBase : XBaseRepositoryController, IXBaseRepositoryController { protected XCategoryRepositoryControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXCategoryRepository repository, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repository, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XCategoryRepositoryProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xCategoryService.Providers.Entities; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; namespace xCategoryService.Controllers { public abstract class XCategoryRepositoryProviderControllerBase : XBaseRepositoryProviderController, IXBaseRepositoryProviderController { protected XCategoryRepositoryProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXCategoryRepositoryProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XCategoryServiceControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; namespace xCategoryService.Controllers { public abstract class XCategoryServiceControllerBase : XBaseServiceController, IXBaseServiceController { protected XCategoryServiceControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXCategoryRepositoryService repositoryService, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repositoryService, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XCategoryServiceProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; namespace xCategoryService.Controllers { public abstract class XCategoryServiceProviderControllerBase : XBaseServiceProviderController, IXBaseServiceProviderController { protected XCategoryServiceProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXCategoryServiceProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XSubCategoryProviderControllerBase.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; using xExceptions.Constants; using xIdentityService.Interfaces; using xModels.Dtos; using xPushService.Controllers; namespace xCategoryService.Controllers { public abstract class XSubCategoryProviderControllerBase : XBaseProvidedController, IXSubCategoryProviderController { private readonly IXSubCategoryProvider provider; protected XSubCategoryProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXSubCategoryProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { this.provider = provider; } // #region Overrides ... [NonAction] [HttpGet("{id}")] public override async Task> Get( [FromRoute] int id, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.Get( id: id, useDefaultIncludes: useDefaultIncludes, cancellationToken: cancellationToken ); } [NonAction] [HttpGet("")] public override async Task>> GetAll( [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.GetAll( useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Find/One")] public override async Task> FindOne( [FromRoute] string query, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.FindOne( query: query, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Find/Many")] public override async Task>> FindMany( [FromRoute] string query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.FindMany( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Query")] public override async Task>> Query( [FromQuery] XQuery query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.Query( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpGet("Query/Owned")] public override async Task>> QueryOwned( [FromQuery] XQuery query, [FromQuery] bool useDefaultOrders = false, [FromQuery] bool useDefaultIncludes = false, CancellationToken cancellationToken = default ) { // return await base.QueryOwned( query: query, useDefaultOrders: useDefaultOrders, cancellationToken: cancellationToken, useDefaultIncludes: useDefaultIncludes ); } [NonAction] [HttpPost("")] public override async Task> Add( [FromBody] XSubCategoryDto item, CancellationToken cancellationToken = default ) { // return await base.Add( item: item, cancellationToken: cancellationToken ); } [NonAction] [HttpPut("{id}")] public override async Task> Update( [FromRoute] int id, [FromBody] XSubCategoryDto item, CancellationToken cancellationToken = default ) { // return await base.Update( id: id, item: item, cancellationToken: cancellationToken ); } [NonAction] [HttpDelete("{id}")] public override async Task> Remove( [FromRoute] int id, CancellationToken cancellationToken = default ) { // return await base.Remove( id: id, cancellationToken: cancellationToken ); } #endregion // #region Actions ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// [HttpGet("Resources/{id}/HasLocale")] public virtual async Task> HasLocale( [FromRoute] int id, [FromQuery] string language, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } ValidationProvider.NotEmpty(language); // var result = await provider.HasLocale( id: id, language: language, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// [HttpGet("Resources/{id}")] public virtual async Task> GetResource( [FromRoute] int id, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } // var result = await provider.GetResource( id: id, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Category Item for Specified Language ... /// /// /// /// /// [HttpPost("Resources")] public virtual async Task> Add( [FromBody] XSubCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotEmpty(language) .AddNotEmpty(item.Title) .AddNotEmpty(item.Description) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Add( item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Item by it's Locales and Reference ... /// /// /// /// [HttpPost("Resources/AddResource")] public virtual async Task> AddResource( [FromBody] XSubCategoryResourceDto item, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotNull(item.Titles) .AddNotZeroChilds(item.Titles.Locales) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.AddResource( item: item, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// [HttpDelete("Resources/{id}")] public virtual async Task> Remove( [FromRoute] int id, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Remove( id: id, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Update a Category Item for Specified Language ... /// /// /// /// /// /// [HttpPut("Resources/{id}")] public virtual async Task> Update( [FromRoute] int id, [FromBody] XSubCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid || !id.IsValidIntId()) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotEmpty(language) .AddNotEmpty(item.Title) .AddNotEmpty(item.Description) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Update( id: id, item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Refresh a Resource ... /// /// /// /// [HttpPost("Resources/Refresh")] public virtual async Task> Refresh( [FromBody] XSubCategoryResourceDto resource, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(resource) .AddNotNull(resource.Item) .ValidateGroupAsync(); // // Reading Requirements ... var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider.Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Get All Resources ... /// /// /// [HttpGet("Resources/All")] public virtual async Task>> GetAllResources( CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } // var result = await provider.GetAllResources( cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Find One Resource ... /// /// /// /// [HttpGet("Resources/Find/One")] public virtual async Task> FindOneResource( [FromQuery] string query, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotEmpty(query) .ValidateGroupAsync(); // var result = await provider.FindOneResource( cancellationToken: cancellationToken, predicate: x => x.PropValuesContains(query) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Find Many Resource ... /// /// /// /// [HttpGet("Resources/Find/Many")] public virtual async Task>> FindManyResource( [FromQuery] string query, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotEmpty(query) .ValidateGroupAsync(); // var result = await provider.FindManyResource( cancellationToken: cancellationToken, predicate: x => x.PropValuesContains(query), orderBuilder: x => x.OrderBy(y => y.Item.Id) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// [HttpGet("Resources/Query")] public virtual async Task>> QueryResources( [FromQuery] XQuery query = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(query) .ValidateGroupAsync(); // var result = await provider.QueryResources( query: query, predicate: null, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Item.Id) ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XSubCategoryRepositoryControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; namespace xCategoryService.Controllers { public abstract class XSubCategoryRepositoryControllerBase : XBaseRepositoryController, IXBaseRepositoryController { protected XSubCategoryRepositoryControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXSubCategoryRepository repository, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repository, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XSubCategoryRepositoryProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xCategoryService.Providers.Entities; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; namespace xCategoryService.Controllers { public abstract class XSubCategoryRepositoryProviderControllerBase : XBaseRepositoryProviderController, IXBaseRepositoryProviderController { protected XSubCategoryRepositoryProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXSubCategoryRepositoryProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XSubCategoryServiceControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; namespace xCategoryService.Controllers { public abstract class XSubCategoryServiceControllerBase : XBaseServiceController, IXBaseServiceController { protected XSubCategoryServiceControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXSubCategoryRepositoryService repositoryService, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repositoryService, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Controllers\XSubCategoryServiceProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; namespace xCategoryService.Controllers { public abstract class XSubCategoryServiceProviderControllerBase : XBaseServiceProviderController, IXBaseServiceProviderController { protected XSubCategoryServiceProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXSubCategoryServiceProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\DI\XDIHelperExtension.cs using System; using System.Linq; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using xCategoryService.Configurations; using xCategoryService.Constants; using xCategoryService.Helpers; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Dtos; using xCategoryService.Interfaces.Entities; using xCategoryService.Providers; using xCategoryService.Providers.Dtos; using xCategoryService.Providers.Entities; using xCommons.Extensions; using xCommons.Helpers; using xDataService.Constants; using xDataService.Db; using xDataService.DI; using xDataService.Models; using xExceptions.Constants; using xPushService.DI; using xPushService.Helpers; namespace xCategoryService.DI { public static class XDIHelperExtension { /// /// Extract Service Configurations ... /// /// /// public static XCategoryServiceConfiguration GetXCategoryServiceConfigurations( this IConfiguration source ) { // XCategoryServiceConfiguration result = null; // var section = source.GetSection(Constants.ConfigurationNodeNames.CATEGORY_SERVICE_NODE); var sectionJson = source.GetSectionAsJson(Constants.ConfigurationNodeNames.CATEGORY_SERVICE_NODE); if (!section.IsNull()) { result = sectionJson.FromJSON(); } // return result; } /// /// Register Service Configuration ... /// /// /// public static void AddXCategoryServiceConfiguration( this IServiceCollection source, IConfiguration configuration ) { // // Extract Configuration Class ... var config = configuration.GetXCategoryServiceConfigurations(); // // Register Class as Service ... source.AddXCategoryServiceConfiguration(config); } /// /// Register Service Configuration ... /// /// /// public static void AddXCategoryServiceConfiguration( this IServiceCollection source, XCategoryServiceConfiguration configuration ) { // // Normalize Configuration Class ... if (configuration.IsNull()) { configuration = new XCategoryServiceConfiguration(); } // // Register ... source.AddSingleton(configuration); } /// /// Register Service ... /// /// /// /// public static void AddXCategoryService( this IServiceCollection services, XRepositoryType repositoryType, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) { AddCategoryService( contextType: null, services: services, lifeTime: lifeTime, repositoryType: repositoryType ); } /// /// Register Service ... /// /// /// /// /// public static void AddXCategoryService( this IServiceCollection services, XRepositoryType repositoryType, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) where TContext : XDbContext { AddCategoryService( services: services, lifeTime: lifeTime, contextType: typeof(TContext), repositoryType: repositoryType ); } /// /// Use XSubCategoryService Middleware ... /// /// /// public static void UseXCategoryService( this IApplicationBuilder app, bool isDevelopmentEnvironment = false ) { // #region Using Hubs ... // var pushHelper = new XPushServiceHelper(); // // Category ... pushHelper.AddHub(XCategoryServiceConstants.XCategoryDtoHub); pushHelper.AddHub(XCategoryServiceConstants.XCategoryEntityHub); // // SubCategory ... pushHelper.AddHub(XCategoryServiceConstants.XSubCategoryDtoHub); pushHelper.AddHub(XCategoryServiceConstants.XSubCategoryEntityHub); // app.UseXPushService(pushHelper); #endregion // // Using XCategory Repository Descriptor ... if (!categoryDescriptor.IsNull()) { // app.UseXRepository( descriptor: categoryDescriptor, isDevelopmentEnvironment: isDevelopmentEnvironment ); } // // Using XSubCategory Repository Descriptor ... if (!subCategoryDescriptor.IsNull()) { // app.UseXRepository( descriptor: subCategoryDescriptor, isDevelopmentEnvironment: isDevelopmentEnvironment ); } // // Create an Scope for Services Acces ... // Handle Seeding Category/SubCategory Resources ... using (var scope = app.ApplicationServices.CreateScope()) { // // Retrieve Configuratuions ... var categoryProvider = scope.ServiceProvider.GetService(); var subCategoryProvider = scope.ServiceProvider.GetService(); var configuration = scope.ServiceProvider.GetService(); if (!configuration.IsNullOrDefault() && !categoryProvider.IsNullOrDefault() && !subCategoryDescriptor.IsNullOrDefault() ) { // // Logging ... Log("Start Seeding ..."); // // Count Data in Category ... var hasCategory = categoryProvider.Count().GetAwaiter().GetResult() > 0; var hasSubCategory = subCategoryProvider.Count().GetAwaiter().GetResult() > 0; // // Seed Category Resources ... var canSeed = !hasCategory && configuration.Categories.HasChild(); if (canSeed) { // // Loop through Provided items ... foreach (var cat in configuration.Categories) { // try { // Log($"Start Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} ..."); // categoryProvider.Refresh( resource: cat, userInfo: null, connectionId: null, cancellationToken: default ) .GetAwaiter() .GetResult(); // Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Finished Successfully ..."); } catch (Exception ex) { Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ..."); } } } // // Seed SubCategory Resources ... canSeed = !hasSubCategory && configuration.SubCategories.HasChild(); if (canSeed) { // // Loop through Provided items ... foreach (var subcat in configuration.SubCategories) { // try { // Log($"Start Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} ..."); // subCategoryProvider.Refresh( userInfo: null, resource: subcat, connectionId: null, cancellationToken: default ) .GetAwaiter() .GetResult(); // Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Finished Successfully ..."); } catch (Exception ex) { Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ..."); } } } // Log("Finish Seeding ..."); } } } // #region Private ... private static XRepositoryDescriptor categoryDescriptor = null; private static XRepositoryDescriptor subCategoryDescriptor = null; /// /// a LogTag for Service ... /// private static string XLogTag = XCategoryServiceConstants.XCategoryServiceDILogTag; /// /// print a log in Console ... /// /// private static void Log(string message) { Console.WriteLine($"{XLogTag} => {message}"); } /// /// Register Service ... /// /// /// /// /// private static void AddCategoryService( IServiceCollection services, XRepositoryType repositoryType, Type contextType = null, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) { // var exception = XException.InvalidArgs.ToException(); ; // // Services ... var isServicesExists = !services.IsNull(); if (!isServicesExists) { // Log("Service Registration failed, services not provided ..."); throw exception; } // // Lifetime ... var isLifetimeExists = !lifeTime.IsNull(); if (!isLifetimeExists) { // Log("Service Registration failed, lifetime not provided ..."); throw exception; } // // Validate Repository Type ... var isRepositoryTypeValid = (repositoryType == XRepositoryType.EF && !contextType.IsNull()) || ((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull()); if (!isRepositoryTypeValid) { // Log("Service Registration failed, Invalid Repository Type and Context Type ..."); throw exception; } // // Maske Instance of Repository Descriptor // Based on Provided Type ... switch (repositoryType) { // case XRepositoryType.EF: // // Category ... categoryDescriptor = typeof(XCategoryServiceHelper) .InvokeGenericMethod( args: null, runtimeType: contextType, methodName: XCategoryServiceConstants.GetXCategoryEFRepositoryDescriptor ); // // SubCategory ... subCategoryDescriptor = typeof(XCategoryServiceHelper) .InvokeGenericMethod( args: null, runtimeType: contextType, methodName: XCategoryServiceConstants.GetXSubCategoryEFRepositoryDescriptor ); break; // case XRepositoryType.Mongo: // // Category ... categoryDescriptor = XCategoryServiceHelper.GetXCategoryMongoRepositoryDescriptor(); // // SubCategory ... subCategoryDescriptor = XCategoryServiceHelper.GetXSubCategoryMongoRepositoryDescriptor(); break; // case XRepositoryType.InMemory: // // Category ... categoryDescriptor = XCategoryServiceHelper.GetXCategoryInMemoryRepositoryDescriptor(); // // SubCategory ... subCategoryDescriptor = XCategoryServiceHelper.GetXSubCategoryInMemoryRepositoryDescriptor(); break; } // // Register Category Repository Descriptor ... if (!categoryDescriptor.IsNull()) { // services.AddXRepository( lifeTime: lifeTime, descriptor: categoryDescriptor ); } // // Register SubCategory Repository Descriptor ... if (!subCategoryDescriptor.IsNull()) { // services.AddXRepository( lifeTime: lifeTime, descriptor: subCategoryDescriptor ); } // #region Register Services ... // #region Category ... // // Models ... services.Add( new ServiceDescriptor(typeof(IXCategoryServiceProvider), typeof(XCategoryServiceProvider), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXCategoryRepositoryService), typeof(XCategoryRepositoryService), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXCategoryRepositoryProvider), typeof(XCategoryRepositoryProvider), lifeTime) ); // // Resource Providers ... services.Add( new ServiceDescriptor(typeof(IXCategoryTitleResourceProvider), typeof(XCategoryTitleResourceProvider), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXCategoryDescriptionResourceProvider), typeof(XCategoryDescriptionResourceProvider), lifeTime) ); // // Reference Providers ... services.Add( new ServiceDescriptor(typeof(IXCategorySubCategoryReferenceProvider), typeof(XCategorySubCategoryReferenceProvider), lifeTime) ); // // Provider ... services.Add( new ServiceDescriptor(typeof(IXCategoryProvider), typeof(XCategoryProvider), lifeTime) ); #endregion // #region SubCategory ... // // Models ... services.Add( new ServiceDescriptor(typeof(IXSubCategoryServiceProvider), typeof(XSubCategoryServiceProvider), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXSubCategoryRepositoryService), typeof(XSubCategoryRepositoryService), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXSubCategoryRepositoryProvider), typeof(XSubCategoryRepositoryProvider), lifeTime) ); // // Resource Providers ... services.Add( new ServiceDescriptor(typeof(IXSubCategoryTitleResourceProvider), typeof(XSubCategoryTitleResourceProvider), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXSubCategoryDescriptionResourceProvider), typeof(XSubCategoryDescriptionResourceProvider), lifeTime) ); // // Provider ... services.Add( new ServiceDescriptor(typeof(IXSubCategoryProvider), typeof(XSubCategoryProvider), lifeTime) ); #endregion #endregion // // Register Service Main Provider ... services.Add( new ServiceDescriptor(typeof(IXCategoryService), typeof(XCategoryService), lifeTime) ); // Log("Service Regitration Succeed ..."); } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Extensions\XCategoryResourceExtensions.cs using System.Linq; using xCategoryService.Models.Dtos; using xCategoryService.Providers.Dtos; using xCommons.Extensions; namespace xCategoryService.Extensions { /// /// Extensions Method Related to XCategoryResourceDto ... /// public static class XCategoryResourceExtensions { /// /// Extract Available Languages ... /// /// /// public static string[] ExtractLanguages( this XCategoryResourceDto source ) { // var result = new string[] { }; // // Validate ... if (!source.IsNullOrDefault()) { return result; } // result = source.Titles.Locales.Select(x => x.Language) .Union(source.Descriptions.Locales.Select(x => x.Language)) .Distinct() .ToArray(); // return result; } /// /// Check Has Locale or not ... /// /// /// /// public static bool HasLocale( this XCategoryResourceDto source, string language ) { // var result = !language.IsNullOrEmpty() && !source.IsNullOrDefault() && source.Titles.Locales .Any(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // return result; } /// /// Get Item Translation ... /// /// /// /// public static XCategoryDto GetTranslate( this XCategoryResourceDto source, string language ) { // XCategoryDto result = null; // var isValid = source .HasLocale(language); if (!isValid) { return result; } // var titleLocale = source.Titles.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); var descriptionLocale = source.Descriptions.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // isValid = !titleLocale.IsNullOrDefault(); if (!isValid) { return result; } // result = source.Item; result.Title = titleLocale.Value; result.Description = descriptionLocale.IsNullOrDefault() ? string.Empty : descriptionLocale.Value; // return result; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Extensions\XModelExtensions.cs using System.Collections.Generic; using System.Linq; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCommons.Extensions; using xDataService.Extensions; using xDataService.Models; namespace xCategoryService.Extensions { public static class XModelExtensions { /// /// Extract References of a Model ... /// /// /// public static IList> GetReferences( this XCategory source ) { // var result = new List>(); // if ( !source.IsNullOrDefault() && !source.References.IsNullOrEmpty() ) { // result = source.References .ParseXReferenceList() .ToList(); } // return result; } /// /// Extract References of a Model ... /// /// /// public static IList> GetReferences( this XCategoryDto source ) { // var result = new List>(); // if ( !source.IsNullOrDefault() && !source.References.IsNullOrEmpty() ) { // result = source.References .ParseXReferenceList() .ToList(); } // return result; } /// /// Update a Model's References by Providing References List ... /// /// /// /// /// public static XCategory UpdateReferences( this XCategory source, IList> references, bool forceClean = true ) { // XCategory result = source; // if (!source.IsNullOrDefault()) { // result = source; // if (forceClean) { result.References = string.Empty; } // if (!references.IsNull() && references.HasChild()) { result.References = references.ToXReferenceString(); } } // return result; } /// /// Update a Model's References by Providing References List ... /// /// /// /// /// public static XCategoryDto UpdateReferences( this XCategoryDto source, IList> references, bool forceClean = true ) { // XCategoryDto result = source; // if (!source.IsNullOrDefault()) { // result = source; // if (forceClean) { result.References = string.Empty; } // if (!references.IsNull() && references.HasChild()) { result.References = references.ToXReferenceString(); } } // return result; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Extensions\XSubCategoryResourceExtensions.cs using System.Linq; using xCategoryService.Models.Dtos; using xCategoryService.Providers.Dtos; using xCommons.Extensions; namespace xCategoryService.Extensions { /// /// Extensions Method Related to XSubCategoryResourceDto ... /// public static class XSubCategoryResourceExtensions { /// /// Extract Available Languages ... /// /// /// public static string[] ExtractLanguages( this XSubCategoryResourceDto source ) { // var result = new string[] { }; // // Validate ... if (!source.IsNullOrDefault()) { return result; } // result = source.Titles.Locales.Select(x => x.Language) .Union(source.Descriptions.Locales.Select(x => x.Language)) .Distinct() .ToArray(); // return result; } /// /// Check Has Locale or not ... /// /// /// /// public static bool HasLocale( this XSubCategoryResourceDto source, string language ) { // var result = !language.IsNullOrEmpty() && !source.IsNullOrDefault() && source.Titles.Locales .Any(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // return result; } /// /// Get Item Translation ... /// /// /// /// public static XSubCategoryDto GetTranslate( this XSubCategoryResourceDto source, string language ) { // XSubCategoryDto result = null; // var isValid = source .HasLocale(language); if (!isValid) { return result; } // var titleLocale = source.Titles.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); var descriptionLocale = source.Descriptions.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // isValid = !titleLocale.IsNullOrDefault(); if (!isValid) { return result; } // result = source.Item; result.Title = titleLocale.Value; result.Description = descriptionLocale.IsNullOrDefault() ? string.Empty : descriptionLocale.Value; // return result; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Helpers\XCategoryServiceHelper.cs using GraphQL.Types; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xCategoryService.Providers.Entities; using xCategoryService.Providers.GraphQL; using xDataService.Db; using xDataService.Models; using xDataService.Providers; namespace xCategoryService.Helpers { public static class XCategoryServiceHelper { // #region EF Repository Descriptor Provider(s) ... // #region Category public static XEFRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryEFRepository, TContext > GetXCategoryEFRepositoryDescriptor() where TContext : XDbContext { // var result = new XEFRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryEFRepository, TContext >(); // return result; } public static XEFRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryEFRepository, TContext, IXCategorySeeder, TSeederImplementation > GetXCategoryEFRepositoryDescriptor() where TContext : XDbContext where TSeederImplementation : XBaseDbSeeder { // var result = new XEFRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryEFRepository, TContext, IXCategorySeeder, TSeederImplementation >(); // return result; } #endregion // #region SubCategory public static XEFRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryEFRepository, TContext > GetXSubCategoryEFRepositoryDescriptor() where TContext : XDbContext { // var result = new XEFRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryEFRepository, TContext >(); // return result; } public static XEFRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryEFRepository, TContext, IXSubCategorySeeder, TSeederImplementation > GetXSubCategoryEFRepositoryDescriptor() where TContext : XDbContext where TSeederImplementation : XBaseDbSeeder { // var result = new XEFRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryEFRepository, TContext, IXSubCategorySeeder, TSeederImplementation >(); // return result; } #endregion #endregion // #region Mongo Repository Descriptor Provider(s) ... // #region Category public static XMongoRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryMongoRepository > GetXCategoryMongoRepositoryDescriptor() { // var result = new XMongoRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryMongoRepository >(); // return result; } public static XMongoRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryMongoRepository, IXCategorySeeder, TSeederImplementation > GetXCategoryMongoRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XMongoRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryMongoRepository, IXCategorySeeder, TSeederImplementation >(); // return result; } #endregion // #region SubCategory public static XMongoRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryMongoRepository > GetXSubCategoryMongoRepositoryDescriptor() { // var result = new XMongoRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryMongoRepository >(); // return result; } public static XMongoRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryMongoRepository, IXSubCategorySeeder, TSeederImplementation > GetXSubCategoryMongoRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XMongoRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryMongoRepository, IXSubCategorySeeder, TSeederImplementation >(); // return result; } #endregion #endregion // #region InMemory Repository Descriptor Provider(s) ... // #region Category public static XInMemoryRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryInMemoryRepository > GetXCategoryInMemoryRepositoryDescriptor() { // var result = new XInMemoryRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryInMemoryRepository >(); // return result; } public static XInMemoryRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryInMemoryRepository, IXCategorySeeder, TSeederImplementation > GetXCategoryInMemoryRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XInMemoryRepositoryDescriptor< XCategory, int, IXCategoryKeyGenerator, XCategoryKeyGenerator, IXCategoryRepositoryEvents, XCategoryRepositoryEvents, XCategoryGraphType, IntGraphType, XCategoryGraphQuery, IXCategoryGraphQLTypeHelper, XCategoryGraphQLTypeHelper, XCategoryGraphSchema, IXCategoryRepository, XCategoryInMemoryRepository, IXCategorySeeder, TSeederImplementation >(); // return result; } #endregion // #region SubCategory public static XInMemoryRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryInMemoryRepository > GetXSubCategoryInMemoryRepositoryDescriptor() { // var result = new XInMemoryRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryInMemoryRepository >(); // return result; } public static XInMemoryRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryInMemoryRepository, IXSubCategorySeeder, TSeederImplementation > GetXSubCategoryInMemoryRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XInMemoryRepositoryDescriptor< XSubCategory, int, IXSubCategoryKeyGenerator, XSubCategoryKeyGenerator, IXSubCategoryRepositoryEvents, XSubCategoryRepositoryEvents, XSubCategoryGraphType, IntGraphType, XSubCategoryGraphQuery, IXSubCategoryGraphQLTypeHelper, XSubCategoryGraphQLTypeHelper, XSubCategoryGraphSchema, IXSubCategoryRepository, XSubCategoryInMemoryRepository, IXSubCategorySeeder, TSeederImplementation >(); // return result; } #endregion #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXBaseCategoryProvider.cs using xCategoryService.Models.Dtos; using xDataService.Interfaces; namespace xCategoryService.Interfaces { public interface IXBaseCategoryProvider : IXBaseReferencedProvider {} } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategoryDescriptionResourceProvider.cs using xStringService.Interfaces; namespace xCategoryService.Interfaces { public interface IXCategoryDescriptionResourceProvider : IXItemResourceProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategoryProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xIdentityModels.Models; using xModels.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces { public interface IXCategoryProvider : IXBaseProvided, IXCategorySubCategoryReferenceProvider { /// /// Check Has Specified Locale or not ... /// /// /// /// /// Task HasLocale( int id, string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// Task GetResource( int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// Task Add( XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Add Item by It's Locales ... /// /// /// /// /// /// Task AddResource( XCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// Task Remove( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// Task Update( int id, XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// /// /// Task Refresh( XCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// Task> GetAllResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// Task FindOneResource( Expression> predicate = null, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// /// Task> FindManyResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// Task> QueryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Get All Resources as Async Enumerable ... /// /// /// IAsyncEnumerable GetAllResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategoryProviderController.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xModels.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces { public interface IXCategoryProviderController : IXBaseProvidedController { /// /// Check Has Specified Locale or not ... /// /// /// /// /// [HttpGet("Resources/{id}/HasLocale")] Task> HasLocale( [FromRoute] int id, [FromQuery] string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// [HttpGet("Resources/{id}")] Task> GetResource( [FromRoute] int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// [HttpPost("Resources")] Task> Add( [FromBody] XCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Add Item by It's Locales ... /// /// /// /// [HttpPost("Resources/AddResource")] Task> AddResource( [FromBody] XCategoryResourceDto item, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// [HttpDelete("Resources/{id}")] Task> Remove( [FromRoute] int id, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// [HttpPut("Resources/{id}")] Task> Update( [FromRoute] int id, [FromBody] XCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// [HttpPost("Resources/Refresh")] Task> Refresh( [FromBody] XCategoryResourceDto resource, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// [HttpGet("Resources/All")] Task>> GetAllResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// [HttpGet("Resources/Find/One")] Task> FindOneResource( [FromQuery] string query, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// [HttpGet("Resources/Find/Many")] Task>> FindManyResource( [FromQuery] string query, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// [HttpGet("Resources/Query")] Task>> QueryResources( [FromQuery] XQuery query = null, CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategoryService.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using xCategoryService.Models.Dtos; using xIdentityModels.Models; using xModels.Dtos; namespace xCategoryService.Interfaces { /// /// Completely Exported Service ... /// public interface IXCategoryService { // #region Category Provider ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// Task CategoryHasLocale( int id, string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// Task GetCategoryResource( int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// Task AddCategory( XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Add Item by It's Locales ... /// /// /// /// /// /// Task AddCategoryResource( XCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// Task RemoveCategory( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// Task UpdateCategory( int id, XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// /// /// Task RefreshCategory( XCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// Task> GetAllCategoryResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// Task FindOneCategoryResource( Expression> predicate = null, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// /// Task> FindManyCategoryResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// Task> QueryCategoryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Get All Resources as Async Enumerable ... /// /// /// IAsyncEnumerable GetAllCategoryResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ); #endregion // #region SubCategory Provider ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// Task SubCategoryHasLocale( int id, string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// Task GetSubCategoryResource( int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// Task AddSubCategory( XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Add Item by it's Locales and Reference ... /// /// /// /// /// /// Task AddSubCategoryResource( XSubCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// Task RemoveSubCategory( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// Task UpdateSubCategory( int id, XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// /// /// Task RefreshSubCategory( XSubCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// Task> GetAllSubCategoryResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// Task FindOneSubCategoryResource( Expression> predicate = null, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// /// Task> FindManySubCategoryResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// Task> QuerySubCategoryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Get All Resources as Async Enumerable ... /// /// /// IAsyncEnumerable GetAllSubCategoryResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ); #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategorySubCategoryReferenceProvider.cs namespace xCategoryService.Interfaces { /// /// a Service for SubCategory Referencing on Category ... /// public interface IXCategorySubCategoryReferenceProvider : IXBaseCategoryProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategoryTitleResourceProvider.cs using xStringService.Interfaces; namespace xCategoryService.Interfaces { public interface IXCategoryTitleResourceProvider : IXItemResourceProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXSubCategoryDescriptionResourceProvider.cs using xStringService.Interfaces; namespace xCategoryService.Interfaces { public interface IXSubCategoryDescriptionResourceProvider : IXItemResourceProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXSubCategoryProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xIdentityModels.Models; using xModels.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces { public interface IXSubCategoryProvider : IXBaseProvided { /// /// Check Has Specified Locale or not ... /// /// /// /// /// Task HasLocale( int id, string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// Task GetResource( int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// Task Add( XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Add Item by it's Locales and Reference ... /// /// /// /// /// /// Task AddResource( XSubCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// Task Remove( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// Task Update( int id, XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// /// /// Task Refresh( XSubCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// Task> GetAllResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// Task FindOneResource( Expression> predicate = null, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// /// Task> FindManyResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// Task> QueryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ); /// /// Get All Resources as Async Enumerable ... /// /// /// IAsyncEnumerable GetAllResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXSubCategoryProviderController.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xModels.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces { public interface IXSubCategoryProviderController : IXBaseProvidedController { /// /// Check Has Specified Locale or not ... /// /// /// /// /// [HttpGet("Resources/{id}/HasLocale")] Task> HasLocale( [FromRoute] int id, [FromQuery] string language, CancellationToken cancellationToken = default ); /// /// Load an Item by all of it's Related Translations ... /// /// /// /// [HttpGet("Resources/{id}")] Task> GetResource( [FromRoute] int id, CancellationToken cancellationToken = default ); /// /// Add Item for Specified Language ... /// /// /// /// /// [HttpPost("Resources")] Task> Add( [FromBody] XSubCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Add Item by it's Locales and Reference ... /// /// /// /// [HttpPost("Resources/AddResource")] Task> AddResource( [FromBody] XSubCategoryResourceDto item, CancellationToken cancellationToken = default ); /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// [HttpDelete("Resources/{id}")] Task> Remove( [FromRoute] int id, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Update an Item for Specified Language ... /// /// /// /// /// /// [HttpPut("Resources/{id}")] Task> Update( [FromRoute] int id, [FromBody] XSubCategoryDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Refresh a Resource ... /// /// /// /// [HttpPost("Resources/Refresh")] Task> Refresh( [FromBody] XSubCategoryResourceDto resource, CancellationToken cancellationToken = default ); /// /// Get All Resources ... /// /// /// [HttpGet("Resources/All")] Task>> GetAllResources( CancellationToken cancellationToken = default ); /// /// Find One Resource ... /// /// /// /// [HttpGet("Resources/Find/One")] Task> FindOneResource( [FromQuery] string query, CancellationToken cancellationToken = default ); /// /// Find Many Resource ... /// /// /// /// [HttpGet("Resources/Find/Many")] Task>> FindManyResource( [FromQuery] string query, CancellationToken cancellationToken = default ); /// /// Retrieve Resources by Query Pattern ... /// /// /// /// [HttpGet("Resources/Query")] Task>> QueryResources( [FromQuery] XQuery query = null, CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXSubCategoryTitleResourceProvider.cs using xStringService.Interfaces; namespace xCategoryService.Interfaces { public interface IXSubCategoryTitleResourceProvider : IXItemResourceProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXCategoryDtoHub.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXCategoryDtoHub : IXBaseDtoHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXCategoryRepositoryService.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXCategoryRepositoryService : IXBaseRepositoryService { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXCategoryServiceProvider.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXCategoryServiceProvider : IXBaseDtoProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXSubCategoryDtoHub.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXSubCategoryDtoHub : IXBaseDtoHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXSubCategoryRepositoryService.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXSubCategoryRepositoryService : IXBaseRepositoryService { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Dtos\IXSubCategoryServiceProvider.cs using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Dtos { public interface IXSubCategoryServiceProvider : IXBaseDtoProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryEntityHub.cs using xCategoryService.Models.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryEntityHub : IXBaseEntityHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryGraphQLTypeHelper.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryGraphQLTypeHelper : IXBaseGraphQLTypeHelper { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryKeyGenerator.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryKeyGenerator : IXKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryRepository.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryRepository : IXBaseRepository { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryRepositoryEvents.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryRepositoryEvents : IXBaseRepositoryEvents { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategoryRepositoryProvider.cs using xCategoryService.Models.Entities; using xCategoryService.Providers.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategoryRepositoryProvider : IXBaseEntityProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXCategorySeeder.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXCategorySeeder : IXBaseDbSeeder { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryEntityHub.cs using xCategoryService.Models.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryEntityHub : IXBaseEntityHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryGraphQLTypeHelper.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryGraphQLTypeHelper : IXBaseGraphQLTypeHelper { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryKeyGenerator.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryKeyGenerator : IXKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryRepository.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryRepository : IXBaseRepository { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryRepositoryEvents.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryRepositoryEvents : IXBaseRepositoryEvents { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategoryRepositoryProvider.cs using xCategoryService.Models.Entities; using xCategoryService.Providers.Entities; using xPushService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategoryRepositoryProvider : IXBaseEntityProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\Entities\IXSubCategorySeeder.cs using xCategoryService.Models.Entities; using xDataService.Interfaces; namespace xCategoryService.Interfaces.Entities { public interface IXSubCategorySeeder : IXBaseDbSeeder { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Dtos\XCategoryDto.cs using xModels.Base; namespace xCategoryService.Models.Dtos { public class XCategoryDto : XBaseIntIDEntityDto { /// /// Title of SubCategory ... /// this is a Resource Title ... /// /// public string Title { get; set; } /// /// Description of SubCategory ... /// this is a Resource Title ... /// /// public string Description { get; set; } /// /// References List String Representation ... /// each SubCategory Referenced to Category ID which List here ... /// /// public string References { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Dtos\XCategoryResourceDto.cs using xModels.Base; using xModels.Dtos; namespace xCategoryService.Models.Dtos { /// /// Represent a Category by all of it's Resources ... /// public class XCategoryResourceDto : XBaseDto { /// /// Category Dto Item for Add or Update ... /// public XCategoryDto Item { get; set; } /// /// Exists Category Titles ... /// public XResourceDto Titles { get; set; } /// /// Exists Category Description ... /// public XResourceDto Descriptions { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Dtos\XSubCategoryDto.cs using xModels.Base; namespace xCategoryService.Models.Dtos { public class XSubCategoryDto : XBaseIntIDEntityDto { /// /// Title of SubCategory ... /// this is a Resource Title ... /// /// public string Title { get; set; } /// /// Description of SubCategory ... /// this is a Resource Title ... /// /// public string Description { get; set; } /// /// References List String Representation ... /// each SubCategory Referenced to Category ID which List here ... /// /// public string References { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Dtos\XSubCategoryResourceDto.cs using xModels.Base; using xModels.Dtos; namespace xCategoryService.Models.Dtos { public class XSubCategoryResourceDto : XBaseDto { /// /// SubCategory Dto Item for Add or Update ... /// public XSubCategoryDto Item { get; set; } /// /// Exists SubCategory Titles ... /// public XResourceDto Titles { get; set; } /// /// Exists SubCategory Description ... /// public XResourceDto Descriptions { get; set; } /// /// Exists Category Resource Dto for Add or Update Category or /// Related Categopry ... /// public XCategoryResourceDto Category { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Entities\XCategory.cs using xModels.Base; namespace xCategoryService.Models.Entities { public class XCategory : XBaseIntIDEntity { /// /// Title of SubCategory ... /// this is a Resource Title ... /// /// public string Title { get; set; } /// /// Description of SubCategory ... /// this is a Resource Title ... /// /// public string Description { get; set; } /// /// References List String Representation ... /// each SubCategory Referenced to Category ID which List here ... /// /// public string References { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Entities\XSubCategory.cs using xModels.Base; namespace xCategoryService.Models.Entities { public class XSubCategory : XBaseIntIDEntity { /// /// Title of SubCategory ... /// this is a Resource Title ... /// /// public string Title { get; set; } /// /// Description of SubCategory ... /// this is a Resource Title ... /// /// public string Description { get; set; } /// /// References List String Representation ... /// each SubCategory Referenced to Category ID which List here ... /// /// public string References { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XBaseCategoryProvider.cs using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using xCategoryService.Extensions; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCommons.Extensions; using xDataService.Extensions; using xDataService.Models; using xExceptions.Constants; using xModels.Dtos; namespace xCategoryService.Providers { public abstract class XBaseCategoryProvider : IXBaseCategoryProvider { // #region Props ... /// /// Provider Identifier ... /// public string Provider { get; } /// /// Tag Provider for Maipulating Tags ... /// public IXCategoryServiceProvider CategoryProvider { get; } #endregion // #region Constructor ... public XBaseCategoryProvider( string providedFor, IXCategoryServiceProvider categoryProvider ) { // Provider = providedFor; CategoryProvider = categoryProvider; } #endregion // #region Referenced Actions ... /// /// Get Specified Indexed Reference for Specific Provided ID ... /// /// /// /// /// public async Task GetReference( TKey providedForId, int forIndex = 0, CancellationToken cancellationToken = default ) { // // Validate ... if (providedForId.IsNull()) { XException.InvalidArgs.Throw(); } // // Normalize ... if (forIndex < 0) { forIndex = 0; } // // Retrieve Last Index ... var indexes = await GetReferencingIndexes( providedForId: providedForId, cancellationToken: cancellationToken ); var maxIndex = indexes.HasChild() ? indexes.Max() : -1; if (forIndex > maxIndex) { XException.NotFound.Throw(); } // var indexedIdentifier = GetIndexedProvidedID( forIndex: forIndex, providedForId: providedForId ); var result = await CategoryProvider.FindOneAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: x => x.References.Contains(indexedIdentifier) ); if (result.IsNullOrDefault()) { XException.NotFound.Throw(); } // return result; } /// /// Retrieve all Exists References of Specific Provided ID ... /// /// /// /// public async Task> GetAllReferences( TKey providedForId, CancellationToken cancellationToken = default ) { // // Validate ... if (providedForId.IsNull()) { XException.InvalidArgs.Throw(); } // var identifier = GetProvidedID(providedForId); var result = await CategoryProvider.FindManyAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: x => x.References.Contains(identifier) ); // return result; } /// /// Extract all Referencing Models for Specified Key ... /// /// /// /// public async Task>> GetAllReferencings( TKey providedForId, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !providedForId.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // var identifier = GetProvidedID(providedForId); // var result = (await CategoryProvider.FindManyAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: x => x.References.Contains(identifier) )) .Select(x => x.References) .ToList() .SelectMany(x => x.ParseXReferenceList()) .Where(x => x.ProvidedFor == Provider && $"{x.ReferencedTo}" == $"{providedForId}") .OrderBy(x => x.Index) .AsEnumerable(); // return result; } /// /// Count References ... /// /// /// /// public async Task CountReferences( TKey providedForId, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !providedForId.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // var identifier = GetProvidedID(providedForId); var result = (await CategoryProvider.FindManyAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: x => x.References.Contains(identifier) )) .Count(); // return result; } /// /// Retrieve References of Specific Provided ID as Query ... /// /// /// /// /// public async Task> QueryReferences( XQuery query, TKey providedForId, CancellationToken cancellationToken = default ) { // // Validate ... if (query.IsNull() || providedForId.IsNull()) { XException.InvalidArgs.Throw(); } // var identifier = GetProvidedID(providedForId); var result = await CategoryProvider.QueryAsync( query: query, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Id), predicate: x => x.References.Contains(identifier) ); // return result; } /// /// Add Reference a Model to Specific Provided ID ... /// /// /// /// /// /// public async Task AddReference( XCategoryDto model, TKey providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = false; // // Validate ... result = !model.IsNullOrDefault() && model.Id.IsValidIntId() && !providedForId.IsNull(); if (!result) { XException.InvalidArgs.Throw(); } // // Check Model Exists ... result = await CategoryProvider.IsExistsAsync(model.Id); if (!result) { XException.NotFound.Throw(); } // // Update Model by Retrieving ... model = await CategoryProvider.GetAsync( id: model.Id, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken ); // // Retrieve all References ... var references = await GetAllReferences( providedForId: providedForId, cancellationToken: cancellationToken ); // // Check isReferenced or not ... result = references .Any(r => r.Id == model.Id && r.GetReferences() .Any(rf => rf.ProvidedFor == Provider && rf.ReferencedTo == $"{providedForId}")); if (result) { return result; } // // Here means there is not any reference to ProvidedForId ... int forIndex = await CountReferences( providedForId: providedForId, cancellationToken: cancellationToken ); var modelReferences = model.GetReferences(); modelReferences.Add(new XReference { Index = forIndex, ProvidedFor = Provider, ReferencedTo = $"{providedForId}" }); modelReferences = modelReferences .OrderBy(r => r.Index) .ToList(); model = model.UpdateReferences(modelReferences); // // Update Data Base ... model = await CategoryProvider.UpdateAsync( id: model.Id, item: model, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); result = !model.IsNullOrDefault(); // return result; } /// /// Add Reference a Model to Specific XRefence ... /// /// /// /// /// /// public async Task AddReference( XCategoryDto model, XReference reference, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... // Since other Validations Handled in Calling, we Ignore them here ... var result = !model.IsNull() && !reference.IsNullOrDefault() && reference.ProvidedFor == Provider && !reference.ReferencedTo.IsNull(); if (!result) { XException.InvalidArgs.Throw(); } // result = await AddReference( model: model, connectionId: connectionId, cancellationToken: cancellationToken, providedForId: reference.ReferencedTo ); // return result; } /// /// Remove Reference a Model for Specific Provided ID ... /// /// /// /// /// /// public async Task RemoveReference( XCategoryDto model, TKey providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... var result = !providedForId.IsNull() && !model.IsNullOrDefault() && model.Id.IsValidIntId(); if (!result) { XException.InvalidArgs.Throw(); } // // Retrieve Model ... model = await CategoryProvider.GetAsync( id: model.Id, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken ); result = !model.IsNullOrDefault(); if (!result) { XException.NotFound.Throw(); } // // Reading Referencing Indexes ... var indexes = await GetReferencingIndexes( providedForId: providedForId, cancellationToken: cancellationToken ); // // Check Model Reference to ID ... var referencesCount = await CountReferences( providedForId: providedForId, cancellationToken: cancellationToken ); result = referencesCount == 0; if (result) { // // There is not any Reference to Remove ... return result; } // // Check Model is Trully Referenced to ProvidedForId or not ... var reference = model .GetReferences() .FirstOrDefault(r => r.ProvidedFor == Provider && r.ReferencedTo == $"{providedForId}"); result = !reference.IsNullOrDefault(); if (!result) { XException.ActionFailed.Throw(); } // // Remove Referenced Item from Model ... var modelReferences = model .GetReferences() .Where(r => !(r.ProvidedFor == Provider && r.ReferencedTo == $"{providedForId}")) .ToList(); model = model.UpdateReferences(modelReferences); // // Update DataBase ... model = await CategoryProvider.UpdateAsync( item: model, id: model.Id, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); // result = !model.IsNullOrDefault(); if (!result) { XException.ActionFailed.Throw(); } // // Get Max Exists Indexes ... var maxIndex = indexes.Max(); // // Here We Have to Re Arrange Indexed ... if (reference.Index < maxIndex) { // var startIndex = reference.Index + 1; for (int i = startIndex; i <= maxIndex; i++) { // var dto = await GetReference( forIndex: i, providedForId: providedForId, cancellationToken: cancellationToken ); if (!dto.IsNullOrDefault()) { // var dtoReferences = dto.GetReferences(); dtoReferences .ToList() .ForEach(iref => { // if ( iref.Index == i && iref.ProvidedFor == Provider && iref.ReferencedTo == reference.ReferencedTo ) { iref.Index = i - 1; } }); dto = dto.UpdateReferences(dtoReferences); // dto = await CategoryProvider.UpdateAsync( item: dto, id: dto.Id, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } } } // return result; } /// /// Remove Reference a Model for Specific XRefence ... /// /// /// /// /// /// public async Task RemoveReference( XCategoryDto model, XReference reference, string connectionId = null, CancellationToken cancellationToken = default ) { // if (model.IsNullOrDefault() || reference.IsNullOrDefault() || reference.ReferencedTo.IsNull() || reference.ProvidedFor != Provider) { XException.InvalidArgs.Throw(); } // var result = await RemoveReference( model: model, connectionId: connectionId, cancellationToken: cancellationToken, providedForId: reference.ReferencedTo ); // return result; } /// /// Remove All References to Specified Key ... /// /// /// /// /// public async Task RemoveReferences( TKey providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... if (providedForId.IsNull()) { XException.InvalidArgs.Throw(); } // var result = false; var references = await GetAllReferences( providedForId: providedForId, cancellationToken: cancellationToken ); if (!references.IsNull() && references.HasChild()) { // foreach (var reference in references) { // // Remove Reference ... var itemReferences = reference.GetReferences() .Where(r => r.ProvidedFor != Provider || (r.ProvidedFor == Provider && r.ReferencedTo != $"{providedForId}")) .ToList(); var updatedModel = reference.UpdateReferences(itemReferences); updatedModel = await CategoryProvider.UpdateAsync( saveChanges: true, item: updatedModel, id: updatedModel.Id, connectionId: connectionId, cancellationToken: cancellationToken ); if (!updatedModel.IsNullOrDefault()) { result = true; } } } // return result; } #endregion // #region Private ... private string GetProvidedID( TKey providedForId, char splitter = '_' ) { // // Validate ... if (providedForId.IsNull()) { XException.InvalidArgs.Throw(); } // var result = $"{Provider}{splitter}{providedForId}"; return result; } private string GetIndexedProvidedID( TKey providedForId, int forIndex, char splitter = '_' ) { // var result = $"{GetProvidedID(providedForId, splitter)}{splitter}{forIndex}"; // return result; } private async Task> GetReferencingIndexes( TKey providedForId, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !providedForId.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // var result = new List(); var referencings = await GetAllReferencings( providedForId: providedForId, cancellationToken: cancellationToken ); isValid = !referencings.IsNull() && referencings.HasChild(); if (!isValid) { return result; } // result = referencings .OrderBy(r => r.Index) .Select(r => r.Index) .ToList(); // return result; } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategoryDescriptionResourceProvider.cs using xCategoryService.Constants; using xCategoryService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Providers; namespace xCategoryService.Providers { public class XCategoryDescriptionResourceProvider : XBaseItemResourceProvider, IXCategoryDescriptionResourceProvider { public XCategoryDescriptionResourceProvider( IXStringServiceProvider stringProvider ) : base( stringProvider: stringProvider, item: XCategoryServiceConstants.CategoryDescriptionResourceIdentifier ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategoryEntityRegisterar.cs using Microsoft.EntityFrameworkCore; using xCategoryService.Configurations.Entities; using xCategoryService.Models.Entities; using xDataService.Interfaces; using xDataService.Providers; namespace xCategoryService.Providers { public class XCategoryEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar { public XCategoryEntityRegisterar() : base(nameof(XCategoryEntityRegisterar)) { // // Add XCategory Entity ... AddEntity(); } /// /// Configure Entities ... /// /// public override void ConfigureEntities(ModelBuilder modelBuilder) { // // Configure Entity Using Provided ... modelBuilder .ApplyConfigurationsFromAssembly(typeof(XCategoryEntityConfiguration).Assembly); // base.ConfigureEntities(modelBuilder); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategoryProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Extensions; using xExceptions.Constants; using xIdentityModels.Models; using xModels.Dtos; using xDataService.Extensions; using xPushService.Constants; using xPushService.Providers; using xDataService.Configuration; using xDataService.Models; namespace xCategoryService.Providers { public class XCategoryProvider : XBaseProvided, IXCategoryProvider { private readonly IXCategoryServiceProvider provider; private readonly XAppConfiguration appConfiguration; private readonly XDataServiceConfiguration dataServiceConfiguration; private readonly IXCategoryTitleResourceProvider titleResourceProvider; private readonly IXCategoryDescriptionResourceProvider descriptionResourceProvider; private readonly IXCategorySubCategoryReferenceProvider categorySubCategoryReferenceProvider; public string Provider => categorySubCategoryReferenceProvider.Provider; public XCategoryProvider( XAppConfiguration appConfiguration, IXCategoryServiceProvider provider, XDataServiceConfiguration dataServiceConfiguration, IXCategoryTitleResourceProvider titleResourceProvider, IXCategoryDescriptionResourceProvider descriptionResourceProvider, IXCategorySubCategoryReferenceProvider categorySubCategoryReferenceProvider ) : base( provider, permittedRoles: new string[] { } ) { // this.provider = provider; this.appConfiguration = appConfiguration; this.titleResourceProvider = titleResourceProvider; this.dataServiceConfiguration = dataServiceConfiguration; this.descriptionResourceProvider = descriptionResourceProvider; this.categorySubCategoryReferenceProvider = categorySubCategoryReferenceProvider; } // #region Overrides ... public override bool IsOwned( XCategoryDto item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } public override bool IsOwned( XCategory item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } #endregion // #region Actions ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// public async Task HasLocale( int id, string language, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId() && !language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Retrieve Resource ... var resource = await GetResource( id: id, cancellationToken: cancellationToken ); // // Check Result ... var result = !resource.IsNullOrDefault() && resource.Titles.Locales .Any(x => x.Language .Equals(language, System.StringComparison.InvariantCultureIgnoreCase)); // return result; } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// public async Task GetResource( int id, CancellationToken cancellationToken = default ) { // var item = await Get( id: id, includeBuilder: null, cancellationToken: cancellationToken ); var titleResource = await titleResourceProvider.GetResource( identifier: id, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider.GetResource( identifier: id, cancellationToken: cancellationToken ); // var result = new XCategoryResourceDto { Item = item, Titles = titleResource, Descriptions = descriptionResource }; // return result; } /// /// Add an Item for Specified Language ... /// /// /// /// /// /// /// public async Task Add( XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Normalize ... language = !language.IsNullOrEmpty() ? language : appConfiguration.DefaultLanguage; // // Validate ... var isValid = !item.IsNullOrDefault(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; try { // var title = item.Title; var description = item.Description; // // Add Item Pure for ID Generating ... item = await base.Add( item: item, userInfo: userInfo, connectionId: null, // Since here We dont want notification ... cancellationToken: cancellationToken ); isValid = !item.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } // id = item.Id; var titleResource = await titleResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = title, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = description, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); // // Update Category Dto ... item.Title = titleResource.Resource; item.Description = descriptionResource.Resource; item = await base.Update( id: id, item: item, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } catch { XException.InvalidArgs.Throw(); } // // Validate Id ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Retrieve Category Resourv=ce ... var result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Sending Push Notification ... isValid = isValid && !result.IsNullOrDefault(); if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: XBaseEntityHubAction.Add.GetStringValue() ); } // return result; } /// /// Add Category by It's Locales ... /// /// /// /// /// /// public async Task AddResource( XCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !item.IsNullOrDefault() && !item.Titles.IsNullOrDefault() && item.Titles.Locales.HasChild() && !item.Titles.Locales.Any(il => il.Language.IsNullOrEmpty() || il.Value.IsNullOrEmpty()); if (!isValid) { XException.InvalidArgs.Throw(); } // // Normalize ... if (item.Item.IsNullOrDefault()) { item.Item = new XCategoryDto(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; try { // // Add Category for ID Generation ... item.Item = await base.Add( item: item.Item, userInfo: userInfo, connectionId: null, // Since here We dont want notification ... cancellationToken: cancellationToken ); isValid = !item.Item.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } id = item.Item.Id; // foreach (var il in item.Titles.Locales) { // var title = il.Value; var language = il.Language; // var descriptionItem = item.Descriptions.IsNullOrDefault() || !item.Descriptions.Locales.HasChild() ? null : item.Descriptions.Locales .FirstOrDefault(ides => ides.Language .Equals( language, StringComparison.InvariantCultureIgnoreCase)); var description = descriptionItem.IsNullOrDefault() ? string.Empty : descriptionItem.Value; // // Try to Add Resources ... var titleResource = await titleResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = title, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = description, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); // // Update Category Dto if not ... if (item.Item.Title.IsNullOrEmpty() || !item.Item.Title .Equals( titleResource.Resource, StringComparison.InvariantCultureIgnoreCase) ) { // item.Item.Title = titleResource.Resource; item.Item.Description = descriptionResource.Resource; item.Item = await base.Update( id: id, item: item.Item, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } } } catch { XException.InvalidArgs.Throw(); } // // Validate Id ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Retrieve Category Resourv=ce ... var result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Sending Push Notification ... isValid = isValid && !result.IsNullOrDefault(); if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: XBaseEntityHubAction.Add.GetStringValue() ); } // return result; } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// public async Task Remove( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Item Exists ... isValid = await IsExists( id: id, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Validate Locale if Provided ... isValid = language.IsNullOrEmpty() || await HasLocale( id: id, language: language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // var result = await GetResource( id: id, cancellationToken: cancellationToken ); if (language.IsNullOrEmpty()) { // // Remove All ... // // Titles ... await titleResourceProvider.RemoveLocales( identifier: id, connectionId: null, cancellationToken: cancellationToken ); // // Descriptions ... await descriptionResourceProvider.RemoveLocales( identifier: id, connectionId: null, cancellationToken: cancellationToken ); // // Remove Entity ... await provider.RemoveAsync( id: id, softDelete: false, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // isValid = true; result.Titles.Locales = []; result.Descriptions.Locales = []; } else { // // Remove Only One Locale, and if there is one, Remove all ... // // Remove Title if Exists ... isValid = await titleResourceProvider.HasLocale( identifier: id, language: language, cancellationToken: cancellationToken ); if (isValid) { // await titleResourceProvider.RemoveLocale( identifier: id, language: language, connectionId: null, cancellationToken: cancellationToken ); } // // Remove Description if Exists ... isValid = await descriptionResourceProvider.HasLocale( identifier: id, language: language, cancellationToken: cancellationToken ); if (isValid) { // await descriptionResourceProvider.RemoveLocale( identifier: id, language: language, connectionId: null, cancellationToken: cancellationToken ); } // // Retrieve Resource ... result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Check Has Locales ... isValid = result.Titles.Locales.HasChild(); if (!isValid) { // // Remove Item ... await provider.RemoveAsync( id: id, softDelete: false, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // result.Titles.Locales = []; result.Descriptions.Locales = []; } // isValid = true; } // if (isValid) { // // Send Push ... await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: result.Titles.Locales.HasChild() ? "DeleteLocale" : XBaseEntityHubAction.Delete.GetStringValue() ); } // return result; } /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// public async Task Update( int id, XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId() && !item.IsNullOrDefault() && !language.IsNullOrEmpty() && !item.Title.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Category Exists ... isValid = await IsExists( id: id, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Check Locale Exists ... isValid = await HasLocale( id: id, language: language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Retrieve Category Dto for Validate Owining ... var dto = await Get( id: id, includeBuilder: null, cancellationToken: cancellationToken ); // // Check Permission ... isValid = !dto.IsNullOrDefault() && !userInfo.IsNullOrDefault() && (IsOwned( item: dto, userInfo: userInfo ) || HasPermision(userInfo)); if (!isValid) { XException.NotAllowed.Throw(); } // // Retrieve Exists Item Resource ... var resource = await GetResource( id: id, cancellationToken: cancellationToken ); // var titleUpdated = false; var descriptionUpdated = false; // // Update Title ... resource.Titles.Locales .ToList() .ForEach(tl => { // if (tl.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { // titleUpdated = true; tl.Value = item.Title; } }); // // Update Description ... resource.Descriptions.Locales .ToList() .ForEach(dl => { // if (dl.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { // descriptionUpdated = true; dl.Value = item.Description; } }); // // Validate Title and Description Updated ... isValid = titleUpdated && descriptionUpdated; if (!isValid) { XException.ActionFailed.Throw(); } // resource = await Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return resource; } /// /// Refresh a Resource ... /// /// /// /// /// /// public async Task Refresh( XCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate Args ... var isValid = !resource.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; var isDelete = false; XCategoryResourceDto result = null; // // Check Item Exists ... XCategoryDto dto = (resource.Item.IsNullOrDefault() || !resource.Item.Id.IsValidIntId()) ? null : await Get( id: resource.Item.Id, includeBuilder: null, cancellationToken: cancellationToken ); var isExists = !dto.IsNullOrDefault(); // // Do Referesh Based on Existance ... var isNew = !isExists && (resource.Item.IsNullOrDefault() || !resource.Item.Id.IsValidIntId()); if (isNew) { // // Add ... // In this Senario, for Add a Category by Providing Resource // the item must clean, either Title and Description, and tge Locales Provided by Resource // ust Contains Values ... // the Add Starts by Titles and only Items Add Which has Titles, since Title is Mandatory // and Description is Optional ... isValid = // // Resource ... (resource.Item.IsNullOrDefault() || (!resource.Item.Id.IsValidIntId() && resource.Item.Title.IsNullOrEmpty() && resource.Item.Description.IsNullOrEmpty())) && // // Titles ... !resource.Titles.IsNullOrDefault() && resource.Titles.Locales.HasChild(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Add Temp Category ... var unique = Guid.NewGuid(); var temp = new XCategoryDto { Title = $"TmpT_{unique}", Description = $"TmpD_{unique}", }; temp = await provider.AddAsync( item: temp, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); isValid = !temp.IsNullOrDefault() && temp.Id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } id = temp.Id; // // Update Title and Description ... var titleResource = titleResourceProvider.GetResourceTitle(id); var descriptionResource = descriptionResourceProvider.GetResourceTitle(id); temp.Title = titleResource; temp.Description = descriptionResource; temp = await provider.UpdateAsync( id: id, item: temp, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // // Loop through Titles ... foreach (var locale in resource.Titles.Locales) { // // Add Or Update Locale ... await titleResourceProvider.AddOrUpdateLocale( locale: locale, identifier: id, connectionId: null, cancellationToken: cancellationToken ); var desLocale = resource.Descriptions.Locales.FirstOrDefault( dl => dl.Language == locale.Language); if (!desLocale.IsNullOrDefault()) { // // Add Descriptions ... await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: desLocale, connectionId: null, cancellationToken: cancellationToken ); } } } else if (isExists) { // // Re State ... id = resource.Item.Id; // // Try to Refresh Resource State ... // // Check Delete ... isDelete = !resource.Titles.Locales.HasChild(); if (isDelete) { // // Handle Delete ... await Remove( id: id, language: null, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } else { // // Handle Update ... result = await GetResource( id: id, cancellationToken: cancellationToken ); // #region Remove ... // // Titles ... var removeTitles = result.Titles.Locales.Where( l => !resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in removeTitles) { // await titleResourceProvider.RemoveLocale( identifier: id, connectionId: null, language: locale.Language, cancellationToken: cancellationToken ); } // // Descriptions ... var removeDescriptions = result.Descriptions.Locales.Where( l => !resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in removeDescriptions) { // await descriptionResourceProvider.RemoveLocale( identifier: id, connectionId: null, language: locale.Language, cancellationToken: cancellationToken ); } #endregion // #region Update ... // // Titles ... var updateTitles = result.Titles.Locales.Where( l => resource.Titles.Locales.Any(r => r.Value .Equals(l.Value, StringComparison.InvariantCultureIgnoreCase) && r.Language .Equals(l.Language, StringComparison.InvariantCultureIgnoreCase) ) ); foreach (var locale in updateTitles) { // await titleResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } // // Descriptions ... var updateDescriptions = result.Descriptions.Locales.Where( l => resource.Descriptions.Locales.Any(r => r.Value .Equals(l.Value, StringComparison.InvariantCultureIgnoreCase) && r.Language .Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in updateDescriptions) { // await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } #endregion // #region New ... // // Titles ... var newTitles = resource.Titles.Locales.Where( l => !result.Titles.Locales.Any(r => r.Language.Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in newTitles) { // await titleResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } // // Descriptions ... var newDescriptions = resource.Descriptions.Locales.Where( l => !result.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in newDescriptions) { // await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } #endregion } } // // Validate Action ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Get Result ... result = isDelete ? resource : await GetResource( id: id, cancellationToken: cancellationToken ); isValid = !result.IsNullOrDefault(); // // Send Notification ... if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: isNew ? XBaseEntityHubAction.Add.GetStringValue() : isDelete ? XBaseEntityHubAction.Delete.GetStringValue() : XBaseEntityHubAction.Update.GetStringValue() ); } // return result; } /// /// Get All Resources as Async Enumerable ... /// /// /// public async IAsyncEnumerable GetAllResourcesAsAsyncEnumerable( [EnumeratorCancellation] CancellationToken cancellationToken = default ) { // var enumerable = provider.GetAllAsAsyncEnumerable( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Id) ); // await foreach (var dto in enumerable) { // if (cancellationToken.IsCancellationRequested) { yield break; } // var resource = await GetResource( id: dto.Id, cancellationToken: cancellationToken ); yield return resource; } } /// /// Get All Resources ... /// /// /// public async Task> GetAllResources( CancellationToken cancellationToken = default ) { // var result = new List(); // var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // if (cancellationToken.IsCancellationRequested) { break; } // result.Add(item); } // return result; } /// /// Find One Resource ... /// /// /// /// public async Task FindOneResource( Expression> predicate = null, CancellationToken cancellationToken = default ) { // var isApproved = false; XCategoryResourceDto result = null; var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // // Check Cancellation Token ... if (cancellationToken.IsCancellationRequested) { break; } // // Detect Predicate Condition ... isApproved = predicate.Compile()(item); if (isApproved) { // result = item; break; } } // return result; } /// /// Find Many Resource ... /// /// /// /// /// public async Task> FindManyResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // var isApproved = false; var result = new List(); var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // // Check Cancellation Token ... if (cancellationToken.IsCancellationRequested) { break; } // // Detect Predicate Condition ... isApproved = predicate.Compile()(item); if (isApproved) { result.Add(item); } } // // Apply Order ... if (!orderBuilder.IsNull()) { // result = orderBuilder(result.AsQueryable()) .ToList(); } // return result; } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// public async Task> QueryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // // Normalize Query ... query = query.NormalizeQuery(dataServiceConfiguration); // var items = await FindManyResource( predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); var totalItemsCount = items.Count(); // // Apply Filter ... if (!query.Filter.IsNullOrEmpty()) { // items = items .ApplyFilter(query.Filter); } int filteredItemsCount = items.Count(); // // Count Pages ... var totalPagesCount = query.CountPages(totalItemsCount); var filteredPagesCount = query.CountPages(filteredItemsCount); // // Apply Paging and Sorting ... if (totalItemsCount > 0 && filteredItemsCount > 0) { // // Apply Sorting ... items = items .ToList() .ApplySorting( query.SortBy, query.IsAscending ); // // Apply Paging ... items = items .ToList() .ApplyPaging( query.Page, query.PageSize ); } // // Prepare Result ... var result = new XQueryResult { Page = query.Page, Items = [.. items], PageSize = query.PageSize, TotalPages = totalPagesCount, TotalItems = totalItemsCount, TotalFilteredPages = filteredPagesCount, TotalFilteredItems = filteredItemsCount }; // return result; } #endregion // #region SubCategory References ... /// /// Get Specified Indexed Reference for Specific Provided ID ... /// /// /// /// /// public async Task GetReference( int providedForId, int forIndex = 0, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .GetReference( forIndex: forIndex, providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Retrieve all Exists References of Specific Provided ID ... /// /// /// /// public async Task> GetAllReferences( int providedForId, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .GetAllReferences( providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Extract all Referencing Models for Specified Key ... /// /// /// /// public async Task>> GetAllReferencings( int providedForId, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .GetAllReferencings( providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Count References ... /// /// /// /// public async Task CountReferences( int providedForId, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .CountReferences( providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Retrieve References of Specific Provided ID as Query ... /// /// /// /// /// public async Task> QueryReferences( XQuery query, int providedForId, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .QueryReferences( query: query, providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Add Reference a Model to Specific Provided ID ... /// /// /// /// /// /// public async Task AddReference( XCategoryDto model, int providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .AddReference( model: model, connectionId: connectionId, providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Add Reference a Model to Specific XRefence ... /// /// /// /// /// /// public async Task AddReference( XCategoryDto model, XReference reference, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .AddReference( model: model, reference: reference, connectionId: connectionId, cancellationToken: cancellationToken ); // return result; } /// /// Remove Reference a Model for Specific Provided ID ... /// /// /// /// /// /// public async Task RemoveReference( XCategoryDto model, int providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .RemoveReference( model: model, connectionId: connectionId, providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } /// /// Remove Reference a Model for Specific XRefence ... /// /// /// /// /// /// public async Task RemoveReference( XCategoryDto model, XReference reference, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .RemoveReference( model: model, reference: reference, connectionId: connectionId, cancellationToken: cancellationToken ); // return result; } /// /// Remove All References to Specified Key ... /// /// /// /// /// public async Task RemoveReferences( int providedForId, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = await categorySubCategoryReferenceProvider .RemoveReferences( connectionId: connectionId, providedForId: providedForId, cancellationToken: cancellationToken ); // return result; } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategoryService.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using xCategoryService.Interfaces; using xCategoryService.Models.Dtos; using xIdentityModels.Models; using xModels.Dtos; namespace xCategoryService.Providers { /// /// Completely Exported Service ... /// public class XCategoryService : IXCategoryService { private readonly IXCategoryProvider categoryProvider; private readonly IXSubCategoryProvider subCategoryProvider; public XCategoryService( IXCategoryProvider categoryProvider, IXSubCategoryProvider subCategoryProvider ) { this.categoryProvider = categoryProvider; this.subCategoryProvider = subCategoryProvider; } // #region Category Provider ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// public virtual async Task CategoryHasLocale( int id, string language, CancellationToken cancellationToken = default ) { // return await categoryProvider .HasLocale( id: id, language: language, cancellationToken: cancellationToken ); } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// public virtual async Task GetCategoryResource( int id, CancellationToken cancellationToken = default ) { // return await categoryProvider .GetResource( id: id, cancellationToken: cancellationToken ); } /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// public virtual async Task AddCategory( XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .Add( item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Add Item by It's Locales ... /// /// /// /// /// /// public virtual async Task AddCategoryResource( XCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .AddResource( item: item, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// public virtual async Task RemoveCategory( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .Remove( id: id, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// public virtual async Task UpdateCategory( int id, XCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .Update( id: id, item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Refresh a Resource ... /// /// /// /// /// /// public virtual async Task RefreshCategory( XCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Get All Resources ... /// /// /// public virtual async Task> GetAllCategoryResources( CancellationToken cancellationToken = default ) { // return await categoryProvider .GetAllResources( cancellationToken: cancellationToken ); } /// /// Find One Resource ... /// /// /// /// public virtual async Task FindOneCategoryResource( Expression> predicate = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .FindOneResource( predicate: predicate, cancellationToken: cancellationToken ); } /// /// Find Many Resource ... /// /// /// /// /// public virtual async Task> FindManyCategoryResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .FindManyResource( predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// public virtual async Task> QueryCategoryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // return await categoryProvider .QueryResources( query: query, predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); } /// /// Get All Resources as Async Enumerable ... /// /// /// public virtual IAsyncEnumerable GetAllCategoryResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ) { // return categoryProvider .GetAllResourcesAsAsyncEnumerable( cancellationToken: cancellationToken ); } #endregion // #region SubCategory Provider ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// public virtual async Task SubCategoryHasLocale( int id, string language, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .HasLocale( id: id, language: language, cancellationToken: cancellationToken ); } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// public virtual async Task GetSubCategoryResource( int id, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .GetResource( id: id, cancellationToken: cancellationToken ); } /// /// Add Item for Specified Language ... /// /// /// /// /// /// /// public virtual async Task AddSubCategory( XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .Add( item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Add Item by it's Locales and Reference ... /// /// /// /// /// /// public virtual async Task AddSubCategoryResource( XSubCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .AddResource( item: item, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// public virtual async Task RemoveSubCategory( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .Remove( id: id, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// public virtual async Task UpdateSubCategory( int id, XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .Update( id: id, item: item, language: language, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Refresh a Resource ... /// /// /// /// /// /// public virtual async Task RefreshSubCategory( XSubCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } /// /// Get All Resources ... /// /// /// public virtual async Task> GetAllSubCategoryResources( CancellationToken cancellationToken = default ) { // return await subCategoryProvider .GetAllResources( cancellationToken: cancellationToken ); } /// /// Find One Resource ... /// /// /// /// public virtual async Task FindOneSubCategoryResource( Expression> predicate = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .FindOneResource( predicate: predicate, cancellationToken: cancellationToken ); } /// /// Find Many Resource ... /// /// /// /// /// public virtual async Task> FindManySubCategoryResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .FindManyResource( predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// public virtual async Task> QuerySubCategoryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // return await subCategoryProvider .QueryResources( query: query, predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); } /// /// Get All Resources as Async Enumerable ... /// /// /// public virtual IAsyncEnumerable GetAllSubCategoryResourcesAsAsyncEnumerable( CancellationToken cancellationToken = default ) { // return subCategoryProvider .GetAllResourcesAsAsyncEnumerable( cancellationToken: cancellationToken ); } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategorySubCategoryReferenceProvider.cs using xCategoryService.Constants; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Dtos; namespace xCategoryService.Providers { public class XCategorySubCategoryReferenceProvider : XBaseCategoryProvider, IXCategorySubCategoryReferenceProvider { public XCategorySubCategoryReferenceProvider( IXCategoryServiceProvider categoryProvider ) : base( categoryProvider: categoryProvider, providedFor: XCategoryServiceConstants.SubCategoryReference ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XCategoryTitleResourceProvider.cs using xCategoryService.Constants; using xCategoryService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Providers; namespace xCategoryService.Providers { public class XCategoryTitleResourceProvider : XBaseItemResourceProvider, IXCategoryTitleResourceProvider { public XCategoryTitleResourceProvider( IXStringServiceProvider stringProvider ) : base( stringProvider: stringProvider, item: XCategoryServiceConstants.CategoryTitleResourceIdentifier ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XSubCategoryDescriptionResourceProvider.cs using xCategoryService.Constants; using xCategoryService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Providers; namespace xCategoryService.Providers { public class XSubCategoryDescriptionResourceProvider : XBaseItemResourceProvider, IXSubCategoryDescriptionResourceProvider { public XSubCategoryDescriptionResourceProvider( IXStringServiceProvider stringProvider ) : base( stringProvider: stringProvider, item: XCategoryServiceConstants.SubCategoryDescriptionResourceIdentifier ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XSubCategoryEntityRegisterar.cs using Microsoft.EntityFrameworkCore; using xCategoryService.Configurations.Entities; using xCategoryService.Models.Entities; using xDataService.Interfaces; using xDataService.Providers; namespace xCategoryService.Providers { public class XSubCategoryEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar { public XSubCategoryEntityRegisterar() : base(nameof(XSubCategoryEntityRegisterar)) { // // Add Entity ... AddEntity(); } /// /// Configure Entities ... /// /// public override void ConfigureEntities(ModelBuilder modelBuilder) { // // Configure Entity Using Provided ... modelBuilder .ApplyConfigurationsFromAssembly(typeof(XSubCategoryEntityConfiguration).Assembly); // base.ConfigureEntities(modelBuilder); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XSubCategoryProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using xCategoryService.Interfaces; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xCategoryService.Providers.Dtos; using xCommons.Configurations; using xCommons.Extensions; using xDataService.Configuration; using xExceptions.Constants; using xIdentityModels.Models; using xModels.Dtos; using xDataService.Extensions; using xPushService.Constants; using xPushService.Providers; namespace xCategoryService.Providers { public class XSubCategoryProvider : XBaseProvided, IXSubCategoryProvider { private readonly XAppConfiguration appConfiguration; private readonly IXCategoryProvider categoryProvider; private readonly IXSubCategoryServiceProvider provider; private readonly XDataServiceConfiguration dataServiceConfiguration; private readonly IXSubCategoryTitleResourceProvider titleResourceProvider; private readonly IXSubCategoryDescriptionResourceProvider descriptionResourceProvider; public XSubCategoryProvider( XAppConfiguration appConfiguration, IXCategoryProvider categoryProvider, IXSubCategoryServiceProvider provider, XDataServiceConfiguration dataServiceConfiguration, IXSubCategoryTitleResourceProvider titleResourceProvider, IXSubCategoryDescriptionResourceProvider descriptionResourceProvider ) : base( provider, permittedRoles: new string[] { } ) { this.provider = provider; this.appConfiguration = appConfiguration; this.categoryProvider = categoryProvider; this.titleResourceProvider = titleResourceProvider; this.dataServiceConfiguration = dataServiceConfiguration; this.descriptionResourceProvider = descriptionResourceProvider; } // #region Overrides ... public override bool IsOwned( XSubCategoryDto item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } public override bool IsOwned( XSubCategory item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } #endregion // #region Actions ... /// /// Check Has Specified Locale or not ... /// /// /// /// /// public async Task HasLocale( int id, string language, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId() && !language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Retrieve Resource ... var resource = await GetResource( id: id, cancellationToken: cancellationToken ); // // Check Result ... var result = !resource.IsNullOrDefault() && resource.Titles.Locales .Any(x => x.Language .Equals(language, System.StringComparison.InvariantCultureIgnoreCase)); // return result; } /// /// Load an Item by all of it's Related Translations ... /// /// /// /// public async Task GetResource( int id, CancellationToken cancellationToken = default ) { // var item = await Get( id: id, includeBuilder: null, cancellationToken: cancellationToken ); var titleResource = await titleResourceProvider.GetResource( identifier: id, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider.GetResource( identifier: id, cancellationToken: cancellationToken ); // // Reading Category Resource ... XCategoryResourceDto categoryResourceDto = null; try { var categoryDto = await categoryProvider.GetReference( providedForId: id, cancellationToken: cancellationToken ); if (!categoryDto.IsNullOrDefault()) { categoryResourceDto = await categoryProvider.GetResource( id: categoryDto.Id, cancellationToken: cancellationToken ); } } catch { } // var result = new XSubCategoryResourceDto { Item = item, Titles = titleResource, Category = categoryResourceDto, Descriptions = descriptionResource }; // return result; } /// /// Add an Item for Specified Language ... /// /// /// /// /// /// /// public async Task Add( XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Normalize ... language = !language.IsNullOrEmpty() ? language : appConfiguration.DefaultLanguage; // // Validate ... var isValid = !item.IsNullOrDefault(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; try { // var title = item.Title; var description = item.Description; // // Add Item Pure for ID Generating ... item = await base.Add( item: item, userInfo: userInfo, connectionId: null, // Since here We dont want notification ... cancellationToken: cancellationToken ); isValid = !item.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } // id = item.Id; var titleResource = await titleResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = title, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = description, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); // // Update Category Dto ... item.Title = titleResource.Resource; item.Description = descriptionResource.Resource; item = await base.Update( id: id, item: item, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } catch { XException.InvalidArgs.Throw(); } // // Validate Id ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Retrieve Category Resourv=ce ... var result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Sending Push Notification ... isValid = isValid && !result.IsNullOrDefault(); if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: XBaseEntityHubAction.Add.GetStringValue() ); } // return result; } /// /// Add Item by it's Locales and Reference ... /// /// /// /// /// /// public async Task AddResource( XSubCategoryResourceDto item, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !item.IsNullOrDefault() && !item.Titles.IsNullOrDefault() && item.Titles.Locales.HasChild() && !item.Titles.Locales.Any(tl => tl.Value.IsNullOrEmpty() || tl.Language.IsNullOrEmpty()); if (!isValid) { XException.InvalidArgs.Throw(); } // // Normalize ... if (item.Item.IsNullOrDefault()) { item.Item = new XSubCategoryDto(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; try { // // Handle Category Generation ... if (!item.Category.IsNullOrDefault()) { // // Handle Category ... try { // Try to Add Category ... item.Category = await categoryProvider.Refresh( resource: item.Category, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } catch { } } // // Add SubCategory for ID Generation ... item.Item = await base.Add( item: item.Item, userInfo: userInfo, connectionId: null, // Since here We dont want notification ... cancellationToken: cancellationToken ); isValid = !item.Item.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } id = item.Item.Id; // foreach (var il in item.Titles.Locales) { // var title = il.Value; var language = il.Language; // var descriptionItem = item.Descriptions.IsNullOrDefault() || !item.Descriptions.Locales.HasChild() ? null : item.Descriptions.Locales .FirstOrDefault(ides => ides.Language .Equals( language, StringComparison.InvariantCultureIgnoreCase)); var description = descriptionItem.IsNullOrDefault() ? string.Empty : descriptionItem.Value; // // Try to Add Resources ... var titleResource = await titleResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = title, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); var descriptionResource = await descriptionResourceProvider .AddOrUpdateLocale( identifier: id, locale: new XLocaleResourceDto { Value = description, Language = language }, connectionId: connectionId, cancellationToken: cancellationToken ); // // Update Category Dto if not ... if (item.Item.Title.IsNullOrEmpty() || !item.Item.Title .Equals( titleResource.Resource, StringComparison.InvariantCultureIgnoreCase) ) { // item.Item.Title = titleResource.Resource; item.Item.Description = descriptionResource.Resource; item.Item = await base.Update( id: id, item: item.Item, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } } } catch { XException.InvalidArgs.Throw(); } // // Validate Id ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Add Resource Reference to Category ... isValid = await categoryProvider.AddReference( providedForId: id, connectionId: null, model: item.Category.Item, cancellationToken: cancellationToken ); // // Retrieve Category Resourv=ce ... var result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Sending Push Notification ... isValid = isValid && !result.IsNullOrDefault(); if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: XBaseEntityHubAction.Add.GetStringValue() ); } // return result; } /// /// Remove Item for Specified Language ... /// /// /// if null, Remove All /// /// /// /// public async Task Remove( int id, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Item Exists ... isValid = await IsExists( id: id, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Validate Locale if Provided ... isValid = language.IsNullOrEmpty() || await HasLocale( id: id, language: language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // var result = await GetResource( id: id, cancellationToken: cancellationToken ); if (language.IsNullOrEmpty()) { // // Remove All ... // // Titles ... await titleResourceProvider.RemoveLocales( identifier: id, connectionId: null, cancellationToken: cancellationToken ); // // Descriptions ... await descriptionResourceProvider.RemoveLocales( identifier: id, connectionId: null, cancellationToken: cancellationToken ); // // Remove Entity ... await provider.RemoveAsync( id: id, softDelete: false, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // isValid = true; result.Titles.Locales = []; result.Descriptions.Locales = []; } else { // // Remove Only One Locale, and if there is one, Remove all ... // // Remove Title if Exists ... isValid = await titleResourceProvider.HasLocale( identifier: id, language: language, cancellationToken: cancellationToken ); if (isValid) { // await titleResourceProvider.RemoveLocale( identifier: id, language: language, connectionId: null, cancellationToken: cancellationToken ); } // // Remove Description if Exists ... isValid = await descriptionResourceProvider.HasLocale( identifier: id, language: language, cancellationToken: cancellationToken ); if (isValid) { // await descriptionResourceProvider.RemoveLocale( identifier: id, language: language, connectionId: null, cancellationToken: cancellationToken ); } // // Retrieve Resource ... result = await GetResource( id: id, cancellationToken: cancellationToken ); // // Check Has Locales ... isValid = result.Titles.Locales.HasChild(); if (!isValid) { // // Remove Item ... await provider.RemoveAsync( id: id, softDelete: false, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // result.Titles.Locales = []; result.Descriptions.Locales = []; } // isValid = true; } // // Remove all Referencings ... if (isValid) { await categoryProvider.RemoveReferences( providedForId: id, connectionId: connectionId, cancellationToken: cancellationToken ); } // if (isValid) { // // Send Push ... await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: result.Titles.Locales.HasChild() ? "DeleteLocale" : XBaseEntityHubAction.Delete.GetStringValue() ); } // return result; } /// /// Update an Item for Specified Language ... /// /// /// /// /// /// /// /// public async Task Update( int id, XSubCategoryDto item, string language = null, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = id.IsValidIntId() && !item.IsNullOrDefault() && !language.IsNullOrEmpty() && !item.Title.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Category Exists ... isValid = await IsExists( id: id, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Check Locale Exists ... isValid = await HasLocale( id: id, language: language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // // Retrieve Category Dto for Validate Owining ... var dto = await Get( id: id, includeBuilder: null, cancellationToken: cancellationToken ); // // Check Permission ... isValid = !dto.IsNullOrDefault() && !userInfo.IsNullOrDefault() && (IsOwned( item: dto, userInfo: userInfo ) || HasPermision(userInfo)); if (!isValid) { XException.NotAllowed.Throw(); } // // Retrieve Exists Item Resource ... var resource = await GetResource( id: id, cancellationToken: cancellationToken ); // var titleUpdated = false; var descriptionUpdated = false; // // Update Title ... resource.Titles.Locales .ToList() .ForEach(tl => { // if (tl.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { // titleUpdated = true; tl.Value = item.Title; } }); // // Update Description ... resource.Descriptions.Locales .ToList() .ForEach(dl => { // if (dl.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { // descriptionUpdated = true; dl.Value = item.Description; } }); // // Validate Title and Description Updated ... isValid = titleUpdated && descriptionUpdated; if (!isValid) { XException.ActionFailed.Throw(); } // resource = await Refresh( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return resource; } /// /// Refresh a Resource ... /// /// /// /// /// /// public async Task Refresh( XSubCategoryResourceDto resource, string connectionId = null, XUserClaimsInfoDto userInfo = null, CancellationToken cancellationToken = default ) { // // Validate Args ... var isValid = !resource.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Permission ... isValid = HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // var id = -1; var isDelete = false; XSubCategoryResourceDto result = null; // // Check Item Exists ... XSubCategoryDto dto = (resource.Item.IsNullOrDefault() || !resource.Item.Id.IsValidIntId()) ? null : await Get( id: resource.Item.Id, includeBuilder: null, cancellationToken: cancellationToken ); var isExists = !dto.IsNullOrDefault(); // // Do Referesh Based on Existance ... var isNew = !isExists && (resource.Item.IsNullOrDefault() || !resource.Item.Id.IsValidIntId()); if (isNew) { // // Add ... // In this Senario, for Add a Category by Providing Resource // the item must clean, either Title and Description, and tge Locales Provided by Resource // ust Contains Values ... // the Add Starts by Titles and only Items Add Which has Titles, since Title is Mandatory // and Description is Optional ... isValid = // // Resource ... (resource.Item.IsNullOrDefault() || (!resource.Item.Id.IsValidIntId() && resource.Item.Title.IsNullOrEmpty() && resource.Item.Description.IsNullOrEmpty())) && // // Titles ... !resource.Titles.IsNullOrDefault() && resource.Titles.Locales.HasChild(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Add Temp Category ... var unique = Guid.NewGuid(); var temp = new XSubCategoryDto { Title = $"TmpT_{unique}", Description = $"TmpD_{unique}", }; temp = await provider.AddAsync( item: temp, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); isValid = !temp.IsNullOrDefault() && temp.Id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } id = temp.Id; // // Update Title and Description ... var titleResource = titleResourceProvider.GetResourceTitle(id); var descriptionResource = descriptionResourceProvider.GetResourceTitle(id); temp.Title = titleResource; temp.Description = descriptionResource; temp = await provider.UpdateAsync( id: id, item: temp, saveChanges: true, connectionId: null, cancellationToken: cancellationToken ); // // Loop through Titles ... foreach (var locale in resource.Titles.Locales) { // // Add Or Update Locale ... await titleResourceProvider.AddOrUpdateLocale( locale: locale, identifier: id, connectionId: null, cancellationToken: cancellationToken ); var desLocale = resource.Descriptions.Locales.FirstOrDefault( dl => dl.Language == locale.Language); if (!desLocale.IsNullOrDefault()) { // // Add Descriptions ... await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: desLocale, connectionId: null, cancellationToken: cancellationToken ); } } } else if (isExists) { // // Re State ... id = resource.Item.Id; // // Try to Refresh Resource State ... // // Check Delete ... isDelete = !resource.Titles.Locales.HasChild(); if (isDelete) { // // Handle Delete ... await Remove( id: id, language: null, userInfo: userInfo, connectionId: null, cancellationToken: cancellationToken ); } else { // // Handle Update ... result = await GetResource( id: id, cancellationToken: cancellationToken ); // #region Remove ... // // Titles ... var removeTitles = result.Titles.Locales.Where( l => !resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in removeTitles) { // await titleResourceProvider.RemoveLocale( identifier: id, connectionId: null, language: locale.Language, cancellationToken: cancellationToken ); } // // Descriptions ... var removeDescriptions = result.Descriptions.Locales.Where( l => !resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in removeDescriptions) { // await descriptionResourceProvider.RemoveLocale( identifier: id, connectionId: null, language: locale.Language, cancellationToken: cancellationToken ); } #endregion // #region Update ... // // Titles ... var updateTitles = result.Titles.Locales.Where( l => resource.Titles.Locales.Any(r => r.Value .Equals(l.Value, StringComparison.InvariantCultureIgnoreCase) && r.Language .Equals(l.Language, StringComparison.InvariantCultureIgnoreCase) ) ); foreach (var locale in updateTitles) { // await titleResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } // // Descriptions ... var updateDescriptions = result.Descriptions.Locales.Where( l => resource.Descriptions.Locales.Any(r => r.Value .Equals(l.Value, StringComparison.InvariantCultureIgnoreCase) && r.Language .Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in updateDescriptions) { // await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } #endregion // #region New ... // // Titles ... var newTitles = resource.Titles.Locales.Where( l => !result.Titles.Locales.Any(r => r.Language.Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in newTitles) { // await titleResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } // // Descriptions ... var newDescriptions = resource.Descriptions.Locales.Where( l => !result.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, StringComparison.InvariantCultureIgnoreCase)) ); foreach (var locale in newDescriptions) { // await descriptionResourceProvider.AddOrUpdateLocale( identifier: id, locale: locale, connectionId: null, cancellationToken: cancellationToken ); } #endregion } } // // Handle Category ... if ( !isDelete && (isNew || isExists) && !resource.Category.IsNullOrDefault()) { // // Refresh Category ... var category = await categoryProvider.Refresh( userInfo: userInfo, resource: resource.Category, connectionId: connectionId, cancellationToken: cancellationToken ); // // Handle SubCategory Referencings ... var references = await categoryProvider.GetAllReferences( providedForId: id, cancellationToken: cancellationToken ); var hasReference = references.HasChild() && references.Any(r => r.Id == category.Item.Id); if (!hasReference) { await categoryProvider.AddReference( providedForId: id, model: category.Item, connectionId: connectionId, cancellationToken: cancellationToken ); } } // // Validate Action ... isValid = id.IsValidIntId(); if (!isValid) { XException.ActionFailed.Throw(); } // // Get Result ... result = isDelete ? resource : await GetResource( id: id, cancellationToken: cancellationToken ); isValid = !result.IsNullOrDefault(); // // Send Notification ... if (isValid) { // await provider.SendPush( connectionId: connectionId, cancellationToken: cancellationToken, payLoad: result.ToJSON(camelCase: true), action: isNew ? XBaseEntityHubAction.Add.GetStringValue() : isDelete ? XBaseEntityHubAction.Delete.GetStringValue() : XBaseEntityHubAction.Update.GetStringValue() ); } // return result; } /// /// Get All Resources as Async Enumerable ... /// /// /// public async IAsyncEnumerable GetAllResourcesAsAsyncEnumerable( [EnumeratorCancellation] CancellationToken cancellationToken = default ) { // var enumerable = provider.GetAllAsAsyncEnumerable( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Id) ); // await foreach (var dto in enumerable) { // if (cancellationToken.IsCancellationRequested) { yield break; } // var resource = await GetResource( id: dto.Id, cancellationToken: cancellationToken ); yield return resource; } } /// /// Get All Resources ... /// /// /// public async Task> GetAllResources( CancellationToken cancellationToken = default ) { // var result = new List(); // var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // if (cancellationToken.IsCancellationRequested) { break; } // result.Add(item); } // return result; } /// /// Find One Resource ... /// /// /// /// public async Task FindOneResource( Expression> predicate = null, CancellationToken cancellationToken = default ) { // var isApproved = false; XSubCategoryResourceDto result = null; var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // // Check Cancellation Token ... if (cancellationToken.IsCancellationRequested) { break; } // // Detect Predicate Condition ... isApproved = predicate.Compile()(item); if (isApproved) { // result = item; break; } } // return result; } /// /// Find Many Resource ... /// /// /// /// /// public async Task> FindManyResource( Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // var isApproved = false; var result = new List(); var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken); await foreach (var item in enumerable) { // // Check Cancellation Token ... if (cancellationToken.IsCancellationRequested) { break; } // // Detect Predicate Condition ... isApproved = predicate.Compile()(item); if (isApproved) { result.Add(item); } } // // Apply Order ... if (!orderBuilder.IsNull()) { // result = orderBuilder(result.AsQueryable()) .ToList(); } // return result; } /// /// Retrieve Resources by Query Pattern ... /// /// /// /// /// /// public async Task> QueryResources( XQuery query = null, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, CancellationToken cancellationToken = default ) { // // Normalize Query ... query = query.NormalizeQuery(dataServiceConfiguration); // var items = await FindManyResource( predicate: predicate, orderBuilder: orderBuilder, cancellationToken: cancellationToken ); var totalItemsCount = items.Count(); // // Apply Filter ... if (!query.Filter.IsNullOrEmpty()) { // items = items .ApplyFilter(query.Filter); } int filteredItemsCount = items.Count(); // // Count Pages ... var totalPagesCount = query.CountPages(totalItemsCount); var filteredPagesCount = query.CountPages(filteredItemsCount); // // Apply Paging and Sorting ... if (totalItemsCount > 0 && filteredItemsCount > 0) { // // Apply Sorting ... items = items .ToList() .ApplySorting( query.SortBy, query.IsAscending ); // // Apply Paging ... items = items .ToList() .ApplyPaging( query.Page, query.PageSize ); } // // Prepare Result ... var result = new XQueryResult { Page = query.Page, Items = [.. items], PageSize = query.PageSize, TotalPages = totalPagesCount, TotalItems = totalItemsCount, TotalFilteredPages = filteredPagesCount, TotalFilteredItems = filteredItemsCount }; // return result; } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\XSubCategoryTitleResourceProvider.cs using xCategoryService.Constants; using xCategoryService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Providers; namespace xCategoryService.Providers { public class XSubCategoryTitleResourceProvider : XBaseItemResourceProvider, IXSubCategoryTitleResourceProvider { public XSubCategoryTitleResourceProvider( IXStringServiceProvider stringProvider ) : base( stringProvider: stringProvider, item: XCategoryServiceConstants.SubCategoryTitleResourceIdentifier ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XCategoryDtoHub.cs using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xPushService.Base; namespace xCategoryService.Providers.Dtos { public class XCategoryDtoHub : XBaseDtoHub, IXCategoryDtoHub { public XCategoryDtoHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XCategoryRepositoryService.cs using System.Collections.Generic; using AutoMapper; using xCategoryService.Interfaces.Dtos; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Dtos { public class XCategoryRepositoryService : XBaseRepositoryService, IXCategoryRepositoryService { public XCategoryRepositoryService( IXCategoryRepository repository, IEnumerable mapperProfiles = null ) : base( repository, mapperProfiles ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XCategoryServiceProvider.cs using Microsoft.AspNetCore.SignalR; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Configuration; using xIdentityService.Interfaces; using xPushService.Base; namespace xCategoryService.Providers.Dtos { public class XCategoryServiceProvider : XBaseDtoProvider, IXCategoryServiceProvider { public XCategoryServiceProvider( IHubContext hub, XDataServiceConfiguration dataConfiguration, IXCategoryRepositoryService service, IXIdentityProvider identityProvider = null ) : base( hub, dataConfiguration, service, identityProvider ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XSubCategoryDtoHub.cs using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xPushService.Base; namespace xCategoryService.Providers.Dtos { public class XSubCategoryDtoHub : XBaseDtoHub, IXSubCategoryDtoHub { public XSubCategoryDtoHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XSubCategoryRepositoryService.cs using System.Collections.Generic; using AutoMapper; using xCategoryService.Interfaces.Dtos; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Dtos { public class XSubCategoryRepositoryService : XBaseRepositoryService, IXSubCategoryRepositoryService { public XSubCategoryRepositoryService( IXSubCategoryRepository repository, IEnumerable mapperProfiles = null ) : base( repository, mapperProfiles ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Dtos\XSubCategoryServiceProvider.cs using Microsoft.AspNetCore.SignalR; using xCategoryService.Interfaces.Dtos; using xCategoryService.Models.Dtos; using xCategoryService.Models.Entities; using xDataService.Configuration; using xIdentityService.Interfaces; using xPushService.Base; namespace xCategoryService.Providers.Dtos { public class XSubCategoryServiceProvider : XBaseDtoProvider, IXSubCategoryServiceProvider { public XSubCategoryServiceProvider( IHubContext hub, XDataServiceConfiguration dataConfiguration, IXSubCategoryRepositoryService service, IXIdentityProvider identityProvider = null ) : base( hub, dataConfiguration, service, identityProvider ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryEFRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Db; using xDataService.Interfaces; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XCategoryEFRepository : XBaseEFRepository, IXCategoryRepository where TContext : XDbContext { public XCategoryEFRepository( IXUnitOfWorks unitOfWorks, XDataServiceConfiguration configuration, IXCategoryKeyGenerator keyGenerator = null, IXCategoryRepositoryEvents baseRepositoryEvents = null ) : base( unitOfWorks, configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryEntityHub.cs using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xPushService.Base; namespace xCategoryService.Providers.Entities { public class XCategoryEntityHub : XBaseEntityHub, IXCategoryEntityHub { public XCategoryEntityHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryInMemoryRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XCategoryInMemoryRepository : XBaseInMemoryRepository, IXCategoryRepository { public XCategoryInMemoryRepository( XDataServiceConfiguration configuration, IXCategoryKeyGenerator keyGenerator = null, IXCategoryRepositoryEvents baseRepositoryEvents = null ) : base( configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryKeyGenerator.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XCategoryKeyGenerator : XIntKeyGenerator, IXCategoryKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryMongoRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XCategoryMongoRepository : XBaseMongoRepository, IXCategoryRepository { public XCategoryMongoRepository( XDataBaseConfiguration dbConfiguration, XDataServiceConfiguration configuration, string collectionName = null, IXCategoryKeyGenerator keyGenerator = null, IXCategoryRepositoryEvents baseRepositoryEvents = null ) : base( dbConfiguration, configuration, collectionName, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryRepositoryEvents.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XCategoryRepositoryEvents : XBaseRepositoryEvents, IXCategoryRepositoryEvents { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategoryRepositoryProvider.cs using Microsoft.AspNetCore.SignalR; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xIdentityService.Interfaces; using xPushService.Base; namespace xCategoryService.Providers.Entities { public class XCategoryRepositoryProvider : XBaseEntityProvider, IXCategoryRepositoryProvider { public XCategoryRepositoryProvider( IHubContext hub, IXCategoryRepository repository, XDataServiceConfiguration dataConfiguration, IXIdentityProvider identityProvider = null ) : base( hub, repository, dataConfiguration, identityProvider ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XCategorySeederBase.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public abstract class XCategorySeederBase : XBaseDbSeeder, IXCategorySeeder { protected XCategorySeederBase( string entity, string database, IXCategoryRepository repository, XDataServiceConfiguration dataServiceConfiguration ) : base( entity, database, repository, dataServiceConfiguration ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryEFRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Db; using xDataService.Interfaces; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XSubCategoryEFRepository : XBaseEFRepository, IXSubCategoryRepository where TContext : XDbContext { public XSubCategoryEFRepository( IXUnitOfWorks unitOfWorks, XDataServiceConfiguration configuration, IXSubCategoryKeyGenerator keyGenerator = null, IXSubCategoryRepositoryEvents baseRepositoryEvents = null ) : base( unitOfWorks, configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryEntityHub.cs using Microsoft.Extensions.Logging; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xPushService.Base; namespace xCategoryService.Providers.Entities { public class XSubCategoryEntityHub : XBaseEntityHub, IXSubCategoryEntityHub { public XSubCategoryEntityHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryInMemoryRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XSubCategoryInMemoryRepository : XBaseInMemoryRepository, IXSubCategoryRepository { public XSubCategoryInMemoryRepository( XDataServiceConfiguration configuration, IXSubCategoryKeyGenerator keyGenerator = null, IXSubCategoryRepositoryEvents baseRepositoryEvents = null ) : base( configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryKeyGenerator.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XSubCategoryKeyGenerator : XIntKeyGenerator, IXSubCategoryKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryMongoRepository.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XSubCategoryMongoRepository : XBaseMongoRepository, IXSubCategoryRepository { public XSubCategoryMongoRepository( XDataBaseConfiguration dbConfiguration, XDataServiceConfiguration configuration, string collectionName = null, IXSubCategoryKeyGenerator keyGenerator = null, IXSubCategoryRepositoryEvents baseRepositoryEvents = null ) : base( dbConfiguration, configuration, collectionName, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryRepositoryEvents.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public class XSubCategoryRepositoryEvents : XBaseRepositoryEvents, IXSubCategoryRepositoryEvents { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategoryRepositoryProvider.cs using Microsoft.AspNetCore.SignalR; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xIdentityService.Interfaces; using xPushService.Base; namespace xCategoryService.Providers.Entities { public class XSubCategoryRepositoryProvider : XBaseEntityProvider, IXSubCategoryRepositoryProvider { public XSubCategoryRepositoryProvider( IHubContext hub, IXSubCategoryRepository repository, XDataServiceConfiguration dataConfiguration, IXIdentityProvider identityProvider = null ) : base( hub, repository, dataConfiguration, identityProvider ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\Entities\XSubCategorySeederBase.cs using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.Providers; namespace xCategoryService.Providers.Entities { public abstract class XSubCategorySeederBase : XBaseDbSeeder, IXSubCategorySeeder { protected XSubCategorySeederBase( string entity, string database, IXSubCategoryRepository repository, XDataServiceConfiguration dataServiceConfiguration ) : base( entity, database, repository, dataServiceConfiguration ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XCategoryGraphQLTypeHelper.cs using xCategoryService.Constants; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XCategoryGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXCategoryGraphQLTypeHelper { public XCategoryGraphQLTypeHelper( XDataServiceConfiguration configuration ) : base(configuration) { } public override string GetInQueryCollectionName() { return XCategoryServiceConstants.XCategoryCollectionName; } public override string GetInQuerySingleName() { return XCategoryServiceConstants.XCategorySingleName; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XCategoryGraphQuery.cs using GraphQL.Types; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XCategoryGraphQuery : XBaseGraphQLQuery { public XCategoryGraphQuery( XDataServiceConfiguration configuration, IXCategoryRepository repository, IXCategoryGraphQLTypeHelper helper ) : base( configuration, repository, helper ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XCategoryGraphSchema.cs using System; using GraphQL.Types; namespace xCategoryService.Providers.GraphQL { public class XCategoryGraphSchema : Schema { public XCategoryGraphSchema(IServiceProvider services) : base(services) { Query = (XCategoryGraphQuery)services.GetService(typeof(XCategoryGraphQuery)); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XCategoryGraphType.cs using xCategoryService.Models.Entities; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XCategoryGraphType : XBaseGraphObjectType { public XCategoryGraphType() : base() { Field(x => x.Title); Field(x => x.Description); Field(x => x.References); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XSubCategoryGraphQLTypeHelper.cs using xCategoryService.Constants; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XSubCategoryGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXSubCategoryGraphQLTypeHelper { public XSubCategoryGraphQLTypeHelper( XDataServiceConfiguration configuration ) : base(configuration) { } public override string GetInQueryCollectionName() { return XCategoryServiceConstants.XSubCategoryCollectionName; } public override string GetInQuerySingleName() { return XCategoryServiceConstants.XSubCategorySingleName; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XSubCategoryGraphQuery.cs using GraphQL.Types; using xCategoryService.Interfaces.Entities; using xCategoryService.Models.Entities; using xDataService.Configuration; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XSubCategoryGraphQuery : XBaseGraphQLQuery { public XSubCategoryGraphQuery( XDataServiceConfiguration configuration, IXSubCategoryRepository repository, IXSubCategoryGraphQLTypeHelper helper ) : base( configuration, repository, helper ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XSubCategoryGraphSchema.cs using System; using GraphQL.Types; namespace xCategoryService.Providers.GraphQL { public class XSubCategoryGraphSchema : Schema { public XSubCategoryGraphSchema(IServiceProvider services) : base(services) { Query = (XSubCategoryGraphQuery)services.GetService(typeof(XSubCategoryGraphQuery)); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Providers\GraphQL\XSubCategoryGraphType.cs using xCategoryService.Models.Entities; using xDataService.GraphQL; namespace xCategoryService.Providers.GraphQL { public class XSubCategoryGraphType : XBaseGraphObjectType { public XSubCategoryGraphType() : base() { Field(x => x.Title); Field(x => x.Description); Field(x => x.References); } } }