10099 lines
331 KiB
Plaintext
10099 lines
331 KiB
Plaintext
|
|
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Configurations\XCategoryServiceConfiguration.cs
|
|
|
|
using xCategoryService.Models.Dtos;
|
|
|
|
namespace xCategoryService.Configurations
|
|
{
|
|
/// <summary>
|
|
/// a Configuration Class for Providing Data to Configure XCategoryService ...
|
|
/// </summary>
|
|
public class XCategoryServiceConfiguration
|
|
{
|
|
/// <summary>
|
|
/// a List of Categories for Seeding ...
|
|
/// </summary>
|
|
public XCategoryResourceDto[] Categories { get; set; } = [];
|
|
|
|
/// <summary>
|
|
/// a List of SubCategories for Seeding ...
|
|
/// </summary>
|
|
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<XCategory, int>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<XCategory> 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<XSubCategory, int>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<XSubCategory> 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<XCategory, XCategoryDto, int, XCategoryDtoHub>, IXCategoryProviderController
|
|
{
|
|
private readonly IXCategoryProvider provider;
|
|
|
|
protected XCategoryProviderControllerBase(
|
|
ILogger<XCategoryProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXCategoryProvider provider,
|
|
Func<IQueryable<XCategory>, IOrderedQueryable<XCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XCategory>, IIncludableQueryable<XCategory, object>> defaultIncludeBuilder = null
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider,
|
|
provider,
|
|
defaultOrderBuilder,
|
|
defaultIncludeBuilder
|
|
)
|
|
{
|
|
this.provider = provider;
|
|
}
|
|
|
|
//
|
|
#region Overrides ...
|
|
[NonAction]
|
|
[HttpGet("{id}")]
|
|
public override async Task<ActionResult<XCategoryDto>> 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<ActionResult<IEnumerable<XCategoryDto>>> 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<ActionResult<XCategoryDto>> 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<ActionResult<IEnumerable<XCategoryDto>>> 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<ActionResult<XQueryResult<XCategoryDto>>> 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<ActionResult<XQueryResult<XCategoryDto>>> 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<ActionResult<XCategoryDto>> Add(
|
|
[FromBody] XCategoryDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await base.Add(
|
|
item: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
[NonAction]
|
|
[HttpPut("{id}")]
|
|
public override async Task<ActionResult<XCategoryDto>> 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<ActionResult<XCategoryDto>> Remove(
|
|
[FromRoute] int id,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await base.Remove(
|
|
id: id,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Actions ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}/HasLocale")]
|
|
public virtual async Task<ActionResult<bool>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Category Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Category Item for by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/AddResource")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Category Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/Refresh")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/All")]
|
|
public virtual async Task<ActionResult<IEnumerable<XCategoryResourceDto>>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/One")]
|
|
public virtual async Task<ActionResult<XCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/Many")]
|
|
public virtual async Task<ActionResult<IEnumerable<XCategoryResourceDto>>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Query")]
|
|
public virtual async Task<ActionResult<XQueryResult<XCategoryResourceDto>>> 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<XCategory, int>, IXBaseRepositoryController<XCategory, int>
|
|
{
|
|
protected XCategoryRepositoryControllerBase(
|
|
ILogger<XCategoryRepositoryControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider,
|
|
IXCategoryRepository repository,
|
|
Func<IQueryable<XCategory>, IOrderedQueryable<XCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XCategory>, IIncludableQueryable<XCategory, object>> 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<XCategory, int, XCategoryEntityHub>, IXBaseRepositoryProviderController<XCategory, int, XCategoryEntityHub>
|
|
{
|
|
protected XCategoryRepositoryProviderControllerBase(
|
|
ILogger<XCategoryRepositoryProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXCategoryRepositoryProvider provider,
|
|
Func<IQueryable<XCategory>, IOrderedQueryable<XCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XCategory>, IIncludableQueryable<XCategory, object>> 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<XCategory, XCategoryDto, int>, IXBaseServiceController<XCategory, XCategoryDto, int>
|
|
{
|
|
protected XCategoryServiceControllerBase(
|
|
ILogger<XCategoryServiceControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider,
|
|
IXCategoryRepositoryService repositoryService,
|
|
Func<IQueryable<XCategory>, IOrderedQueryable<XCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XCategory>, IIncludableQueryable<XCategory, object>> 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<XCategory, XCategoryDto, int, XCategoryDtoHub>, IXBaseServiceProviderController<XCategory, XCategoryDto, int, XCategoryDtoHub>
|
|
{
|
|
protected XCategoryServiceProviderControllerBase(
|
|
ILogger<XCategoryServiceProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXCategoryServiceProvider provider,
|
|
Func<IQueryable<XCategory>, IOrderedQueryable<XCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XCategory>, IIncludableQueryable<XCategory, object>> 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>, IXSubCategoryProviderController
|
|
{
|
|
private readonly IXSubCategoryProvider provider;
|
|
|
|
protected XSubCategoryProviderControllerBase(
|
|
ILogger<XSubCategoryProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryProvider provider,
|
|
Func<IQueryable<XSubCategory>, IOrderedQueryable<XSubCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XSubCategory>, IIncludableQueryable<XSubCategory, object>> defaultIncludeBuilder = null
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider,
|
|
provider,
|
|
defaultOrderBuilder,
|
|
defaultIncludeBuilder
|
|
)
|
|
{
|
|
this.provider = provider;
|
|
}
|
|
|
|
//
|
|
#region Overrides ...
|
|
[NonAction]
|
|
[HttpGet("{id}")]
|
|
public override async Task<ActionResult<XSubCategoryDto>> 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<ActionResult<IEnumerable<XSubCategoryDto>>> 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<ActionResult<XSubCategoryDto>> 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<ActionResult<IEnumerable<XSubCategoryDto>>> 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<ActionResult<XQueryResult<XSubCategoryDto>>> 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<ActionResult<XQueryResult<XSubCategoryDto>>> 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<ActionResult<XSubCategoryDto>> Add(
|
|
[FromBody] XSubCategoryDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await base.Add(
|
|
item: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
[NonAction]
|
|
[HttpPut("{id}")]
|
|
public override async Task<ActionResult<XSubCategoryDto>> 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<ActionResult<XSubCategoryDto>> Remove(
|
|
[FromRoute] int id,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await base.Remove(
|
|
id: id,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Actions ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}/HasLocale")]
|
|
public virtual async Task<ActionResult<bool>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Category Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/AddResource")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Category Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("Resources/{id}")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/Refresh")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/All")]
|
|
public virtual async Task<ActionResult<IEnumerable<XSubCategoryResourceDto>>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/One")]
|
|
public virtual async Task<ActionResult<XSubCategoryResourceDto>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/Many")]
|
|
public virtual async Task<ActionResult<IEnumerable<XSubCategoryResourceDto>>> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Query")]
|
|
public virtual async Task<ActionResult<XQueryResult<XSubCategoryResourceDto>>> 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<XSubCategory, int>, IXBaseRepositoryController<XSubCategory, int>
|
|
{
|
|
protected XSubCategoryRepositoryControllerBase(
|
|
ILogger<XSubCategoryRepositoryControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryRepository repository,
|
|
Func<IQueryable<XSubCategory>, IOrderedQueryable<XSubCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XSubCategory>, IIncludableQueryable<XSubCategory, object>> 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<XSubCategory, int, XSubCategoryEntityHub>, IXBaseRepositoryProviderController<XSubCategory, int, XSubCategoryEntityHub>
|
|
{
|
|
protected XSubCategoryRepositoryProviderControllerBase(
|
|
ILogger<XSubCategoryRepositoryProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryRepositoryProvider provider,
|
|
Func<IQueryable<XSubCategory>, IOrderedQueryable<XSubCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XSubCategory>, IIncludableQueryable<XSubCategory, object>> 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<XSubCategory, XSubCategoryDto, int>, IXBaseServiceController<XSubCategory, XSubCategoryDto, int>
|
|
{
|
|
protected XSubCategoryServiceControllerBase(
|
|
ILogger<XSubCategoryServiceControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryRepositoryService repositoryService,
|
|
Func<IQueryable<XSubCategory>, IOrderedQueryable<XSubCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XSubCategory>, IIncludableQueryable<XSubCategory, object>> 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>, IXBaseServiceProviderController<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>
|
|
{
|
|
protected XSubCategoryServiceProviderControllerBase(
|
|
ILogger<XSubCategoryServiceProviderControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryServiceProvider provider,
|
|
Func<IQueryable<XSubCategory>, IOrderedQueryable<XSubCategory>> defaultOrderBuilder = null,
|
|
Func<IQueryable<XSubCategory>, IIncludableQueryable<XSubCategory, object>> 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
|
|
{
|
|
/// <summary>
|
|
/// Extract Service Configurations ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
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<XCategoryServiceConfiguration>();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service Configuration ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="configuration"></param>
|
|
public static void AddXCategoryServiceConfiguration(
|
|
this IServiceCollection source,
|
|
IConfiguration configuration
|
|
)
|
|
{
|
|
//
|
|
// Extract Configuration Class ...
|
|
var config = configuration.GetXCategoryServiceConfigurations();
|
|
|
|
//
|
|
// Register Class as Service ...
|
|
source.AddXCategoryServiceConfiguration(config);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service Configuration ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="configuration"></param>
|
|
public static void AddXCategoryServiceConfiguration(
|
|
this IServiceCollection source,
|
|
XCategoryServiceConfiguration configuration
|
|
)
|
|
{
|
|
//
|
|
// Normalize Configuration Class ...
|
|
if (configuration.IsNull())
|
|
{
|
|
configuration = new XCategoryServiceConfiguration();
|
|
}
|
|
|
|
//
|
|
// Register ...
|
|
source.AddSingleton(configuration);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="repositoryType"></param>
|
|
/// <param name="lifeTime"></param>
|
|
public static void AddXCategoryService(
|
|
this IServiceCollection services,
|
|
XRepositoryType repositoryType,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
)
|
|
{
|
|
AddCategoryService(
|
|
contextType: null,
|
|
services: services,
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service ...
|
|
/// </summary>
|
|
/// <typeparam name="TContext"></typeparam>
|
|
/// <param name="services"></param>
|
|
/// <param name="repositoryType"></param>
|
|
/// <param name="lifeTime"></param>
|
|
public static void AddXCategoryService<TContext>(
|
|
this IServiceCollection services,
|
|
XRepositoryType repositoryType,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
)
|
|
where TContext : XDbContext
|
|
{
|
|
AddCategoryService(
|
|
services: services,
|
|
lifeTime: lifeTime,
|
|
contextType: typeof(TContext),
|
|
repositoryType: repositoryType
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use XSubCategoryService Middleware ...
|
|
/// </summary>
|
|
/// <param name="app"></param>
|
|
/// <param name="isDevelopmentEnvironment"></param>
|
|
public static void UseXCategoryService(
|
|
this IApplicationBuilder app,
|
|
bool isDevelopmentEnvironment = false
|
|
)
|
|
{
|
|
//
|
|
#region Using Hubs ...
|
|
//
|
|
var pushHelper = new XPushServiceHelper();
|
|
|
|
//
|
|
// Category ...
|
|
pushHelper.AddHub<XCategoryDtoHub>(XCategoryServiceConstants.XCategoryDtoHub);
|
|
pushHelper.AddHub<XCategoryEntityHub>(XCategoryServiceConstants.XCategoryEntityHub);
|
|
|
|
//
|
|
// SubCategory ...
|
|
pushHelper.AddHub<XSubCategoryDtoHub>(XCategoryServiceConstants.XSubCategoryDtoHub);
|
|
pushHelper.AddHub<XSubCategoryEntityHub>(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<IXCategoryProvider>();
|
|
var subCategoryProvider = scope.ServiceProvider.GetService<IXSubCategoryProvider>();
|
|
var configuration = scope.ServiceProvider.GetService<XCategoryServiceConfiguration>();
|
|
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;
|
|
|
|
/// <summary>
|
|
/// a LogTag for Service ...
|
|
/// </summary>
|
|
private static string XLogTag = XCategoryServiceConstants.XCategoryServiceDILogTag;
|
|
|
|
/// <summary>
|
|
/// print a log in Console ...
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
private static void Log(string message)
|
|
{
|
|
Console.WriteLine($"{XLogTag} => {message}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="repositoryType"></param>
|
|
/// <param name="contextType"></param>
|
|
/// <param name="lifeTime"></param>
|
|
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<XRepositoryDescriptor>(
|
|
args: null,
|
|
runtimeType: contextType,
|
|
methodName: XCategoryServiceConstants.GetXCategoryEFRepositoryDescriptor
|
|
);
|
|
|
|
//
|
|
// SubCategory ...
|
|
subCategoryDescriptor = typeof(XCategoryServiceHelper)
|
|
.InvokeGenericMethod<XRepositoryDescriptor>(
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Extensions Method Related to XCategoryResourceDto ...
|
|
/// </summary>
|
|
public static class XCategoryResourceExtensions
|
|
{
|
|
/// <summary>
|
|
/// Extract Available Languages ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check Has Locale or not ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="language"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item Translation ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="language"></param>
|
|
/// <returns></returns>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Extract References of a Model ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static IList<XReference<string>> GetReferences(
|
|
this XCategory source
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XReference<string>>();
|
|
|
|
//
|
|
if (
|
|
!source.IsNullOrDefault() &&
|
|
!source.References.IsNullOrEmpty()
|
|
)
|
|
{
|
|
//
|
|
result = source.References
|
|
.ParseXReferenceList<string>()
|
|
.ToList();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extract References of a Model ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static IList<XReference<string>> GetReferences(
|
|
this XCategoryDto source
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XReference<string>>();
|
|
|
|
//
|
|
if (
|
|
!source.IsNullOrDefault() &&
|
|
!source.References.IsNullOrEmpty()
|
|
)
|
|
{
|
|
//
|
|
result = source.References
|
|
.ParseXReferenceList<string>()
|
|
.ToList();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Model's References by Providing References List ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="references"></param>
|
|
/// <param name="forceClean"></param>
|
|
/// <returns></returns>
|
|
public static XCategory UpdateReferences(
|
|
this XCategory source,
|
|
IList<XReference<string>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Model's References by Providing References List ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="references"></param>
|
|
/// <param name="forceClean"></param>
|
|
/// <returns></returns>
|
|
public static XCategoryDto UpdateReferences(
|
|
this XCategoryDto source,
|
|
IList<XReference<string>> 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
|
|
{
|
|
/// <summary>
|
|
/// Extensions Method Related to XSubCategoryResourceDto ...
|
|
/// </summary>
|
|
public static class XSubCategoryResourceExtensions
|
|
{
|
|
/// <summary>
|
|
/// Extract Available Languages ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check Has Locale or not ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="language"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item Translation ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="language"></param>
|
|
/// <returns></returns>
|
|
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>,
|
|
TContext
|
|
> GetXCategoryEFRepositoryDescriptor<TContext>()
|
|
where TContext : XDbContext
|
|
{
|
|
//
|
|
var result = new XEFRepositoryDescriptor<
|
|
XCategory,
|
|
int,
|
|
IXCategoryKeyGenerator,
|
|
XCategoryKeyGenerator,
|
|
IXCategoryRepositoryEvents,
|
|
XCategoryRepositoryEvents,
|
|
XCategoryGraphType,
|
|
IntGraphType,
|
|
XCategoryGraphQuery,
|
|
IXCategoryGraphQLTypeHelper,
|
|
XCategoryGraphQLTypeHelper,
|
|
XCategoryGraphSchema,
|
|
IXCategoryRepository,
|
|
XCategoryEFRepository<TContext>,
|
|
TContext
|
|
>();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public static XEFRepositoryDescriptor<
|
|
XCategory,
|
|
int,
|
|
IXCategoryKeyGenerator,
|
|
XCategoryKeyGenerator,
|
|
IXCategoryRepositoryEvents,
|
|
XCategoryRepositoryEvents,
|
|
XCategoryGraphType,
|
|
IntGraphType,
|
|
XCategoryGraphQuery,
|
|
IXCategoryGraphQLTypeHelper,
|
|
XCategoryGraphQLTypeHelper,
|
|
XCategoryGraphSchema,
|
|
IXCategoryRepository,
|
|
XCategoryEFRepository<TContext>,
|
|
TContext,
|
|
IXCategorySeeder,
|
|
TSeederImplementation
|
|
> GetXCategoryEFRepositoryDescriptor<TContext, TSeederImplementation>()
|
|
where TContext : XDbContext
|
|
where TSeederImplementation : XBaseDbSeeder<XCategory, int>
|
|
{
|
|
//
|
|
var result = new XEFRepositoryDescriptor<
|
|
XCategory,
|
|
int,
|
|
IXCategoryKeyGenerator,
|
|
XCategoryKeyGenerator,
|
|
IXCategoryRepositoryEvents,
|
|
XCategoryRepositoryEvents,
|
|
XCategoryGraphType,
|
|
IntGraphType,
|
|
XCategoryGraphQuery,
|
|
IXCategoryGraphQLTypeHelper,
|
|
XCategoryGraphQLTypeHelper,
|
|
XCategoryGraphSchema,
|
|
IXCategoryRepository,
|
|
XCategoryEFRepository<TContext>,
|
|
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>,
|
|
TContext
|
|
> GetXSubCategoryEFRepositoryDescriptor<TContext>()
|
|
where TContext : XDbContext
|
|
{
|
|
//
|
|
var result = new XEFRepositoryDescriptor<
|
|
XSubCategory,
|
|
int,
|
|
IXSubCategoryKeyGenerator,
|
|
XSubCategoryKeyGenerator,
|
|
IXSubCategoryRepositoryEvents,
|
|
XSubCategoryRepositoryEvents,
|
|
XSubCategoryGraphType,
|
|
IntGraphType,
|
|
XSubCategoryGraphQuery,
|
|
IXSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphSchema,
|
|
IXSubCategoryRepository,
|
|
XSubCategoryEFRepository<TContext>,
|
|
TContext
|
|
>();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public static XEFRepositoryDescriptor<
|
|
XSubCategory,
|
|
int,
|
|
IXSubCategoryKeyGenerator,
|
|
XSubCategoryKeyGenerator,
|
|
IXSubCategoryRepositoryEvents,
|
|
XSubCategoryRepositoryEvents,
|
|
XSubCategoryGraphType,
|
|
IntGraphType,
|
|
XSubCategoryGraphQuery,
|
|
IXSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphSchema,
|
|
IXSubCategoryRepository,
|
|
XSubCategoryEFRepository<TContext>,
|
|
TContext,
|
|
IXSubCategorySeeder,
|
|
TSeederImplementation
|
|
> GetXSubCategoryEFRepositoryDescriptor<TContext, TSeederImplementation>()
|
|
where TContext : XDbContext
|
|
where TSeederImplementation : XBaseDbSeeder<XSubCategory, int>
|
|
{
|
|
//
|
|
var result = new XEFRepositoryDescriptor<
|
|
XSubCategory,
|
|
int,
|
|
IXSubCategoryKeyGenerator,
|
|
XSubCategoryKeyGenerator,
|
|
IXSubCategoryRepositoryEvents,
|
|
XSubCategoryRepositoryEvents,
|
|
XSubCategoryGraphType,
|
|
IntGraphType,
|
|
XSubCategoryGraphQuery,
|
|
IXSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphQLTypeHelper,
|
|
XSubCategoryGraphSchema,
|
|
IXSubCategoryRepository,
|
|
XSubCategoryEFRepository<TContext>,
|
|
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<TSeederImplementation>()
|
|
where TSeederImplementation : XBaseDbSeeder<XCategory, int>
|
|
{
|
|
//
|
|
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<TSeederImplementation>()
|
|
where TSeederImplementation : XBaseDbSeeder<XSubCategory, int>
|
|
{
|
|
//
|
|
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<TSeederImplementation>()
|
|
where TSeederImplementation : XBaseDbSeeder<XCategory, int>
|
|
{
|
|
//
|
|
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<TSeederImplementation>()
|
|
where TSeederImplementation : XBaseDbSeeder<XSubCategory, int>
|
|
{
|
|
//
|
|
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<TKey> : IXBaseReferencedProvider<XCategoryDto, TKey>
|
|
{}
|
|
}
|
|
|
|
### 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<XCategory, XCategoryDto, int, XCategoryDtoHub>, IXCategorySubCategoryReferenceProvider
|
|
{
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<bool> HasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> GetResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> Add(
|
|
XCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> AddResource(
|
|
XCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> Remove(
|
|
int id,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> Update(
|
|
int id,
|
|
XCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> Refresh(
|
|
XCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XCategoryResourceDto>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> FindOneResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XCategoryResourceDto>> FindManyResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XQueryResult<XCategoryResourceDto>> QueryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
IAsyncEnumerable<XCategoryResourceDto> 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<XCategory, XCategoryDto, int, XCategoryDtoHub>
|
|
{
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}/HasLocale")]
|
|
Task<ActionResult<bool>> HasLocale(
|
|
[FromRoute] int id,
|
|
[FromQuery] string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}")]
|
|
Task<ActionResult<XCategoryResourceDto>> GetResource(
|
|
[FromRoute] int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources")]
|
|
Task<ActionResult<XCategoryResourceDto>> Add(
|
|
[FromBody] XCategoryDto item,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/AddResource")]
|
|
Task<ActionResult<XCategoryResourceDto>> AddResource(
|
|
[FromBody] XCategoryResourceDto item,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("Resources/{id}")]
|
|
Task<ActionResult<XCategoryResourceDto>> Remove(
|
|
[FromRoute] int id,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("Resources/{id}")]
|
|
Task<ActionResult<XCategoryResourceDto>> Update(
|
|
[FromRoute] int id,
|
|
[FromBody] XCategoryDto item,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/Refresh")]
|
|
Task<ActionResult<XCategoryResourceDto>> Refresh(
|
|
[FromBody] XCategoryResourceDto resource,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/All")]
|
|
Task<ActionResult<IEnumerable<XCategoryResourceDto>>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/One")]
|
|
Task<ActionResult<XCategoryResourceDto>> FindOneResource(
|
|
[FromQuery] string query,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/Many")]
|
|
Task<ActionResult<IEnumerable<XCategoryResourceDto>>> FindManyResource(
|
|
[FromQuery] string query,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Query")]
|
|
Task<ActionResult<XQueryResult<XCategoryResourceDto>>> 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
|
|
{
|
|
/// <summary>
|
|
/// Completely Exported Service ...
|
|
/// </summary>
|
|
public interface IXCategoryService
|
|
{
|
|
//
|
|
#region Category Provider ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<bool> CategoryHasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> GetCategoryResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> AddCategory(
|
|
XCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> AddCategoryResource(
|
|
XCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> RemoveCategory(
|
|
int id,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> UpdateCategory(
|
|
int id,
|
|
XCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> RefreshCategory(
|
|
XCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XCategoryResourceDto>> GetAllCategoryResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XCategoryResourceDto> FindOneCategoryResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XCategoryResourceDto>> FindManyCategoryResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XQueryResult<XCategoryResourceDto>> QueryCategoryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
IAsyncEnumerable<XCategoryResourceDto> GetAllCategoryResourcesAsAsyncEnumerable(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
#endregion
|
|
|
|
//
|
|
#region SubCategory Provider ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<bool> SubCategoryHasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> GetSubCategoryResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> AddSubCategory(
|
|
XSubCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> AddSubCategoryResource(
|
|
XSubCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> RemoveSubCategory(
|
|
int id,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> UpdateSubCategory(
|
|
int id,
|
|
XSubCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> RefreshSubCategory(
|
|
XSubCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XSubCategoryResourceDto>> GetAllSubCategoryResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> FindOneSubCategoryResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XSubCategoryResourceDto>> FindManySubCategoryResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XQueryResult<XSubCategoryResourceDto>> QuerySubCategoryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
IAsyncEnumerable<XSubCategoryResourceDto> GetAllSubCategoryResourcesAsAsyncEnumerable(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Interfaces\IXCategorySubCategoryReferenceProvider.cs
|
|
|
|
namespace xCategoryService.Interfaces
|
|
{
|
|
/// <summary>
|
|
/// a Service for SubCategory Referencing on Category ...
|
|
/// </summary>
|
|
public interface IXCategorySubCategoryReferenceProvider : IXBaseCategoryProvider<int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>
|
|
{
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<bool> HasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> GetResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> Add(
|
|
XSubCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> AddResource(
|
|
XSubCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> Remove(
|
|
int id,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> Update(
|
|
int id,
|
|
XSubCategoryDto item,
|
|
string language = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> Refresh(
|
|
XSubCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XSubCategoryResourceDto>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XSubCategoryResourceDto> FindOneResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<IEnumerable<XSubCategoryResourceDto>> FindManyResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XQueryResult<XSubCategoryResourceDto>> QueryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
IAsyncEnumerable<XSubCategoryResourceDto> 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>
|
|
{
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}/HasLocale")]
|
|
Task<ActionResult<bool>> HasLocale(
|
|
[FromRoute] int id,
|
|
[FromQuery] string language,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/{id}")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> GetResource(
|
|
[FromRoute] int id,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> Add(
|
|
[FromBody] XSubCategoryDto item,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/AddResource")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> AddResource(
|
|
[FromBody] XSubCategoryResourceDto item,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("Resources/{id}")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> Remove(
|
|
[FromRoute] int id,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("Resources/{id}")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> Update(
|
|
[FromRoute] int id,
|
|
[FromBody] XSubCategoryDto item,
|
|
[FromQuery] string language = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Resources/Refresh")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> Refresh(
|
|
[FromBody] XSubCategoryResourceDto resource,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/All")]
|
|
Task<ActionResult<IEnumerable<XSubCategoryResourceDto>>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/One")]
|
|
Task<ActionResult<XSubCategoryResourceDto>> FindOneResource(
|
|
[FromQuery] string query,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Find/Many")]
|
|
Task<ActionResult<IEnumerable<XSubCategoryResourceDto>>> FindManyResource(
|
|
[FromQuery] string query,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Resources/Query")]
|
|
Task<ActionResult<XQueryResult<XSubCategoryResourceDto>>> 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<XCategory, XCategoryDto, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, XCategoryDto, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, XCategoryDto, int, XCategoryDtoHub>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, XSubCategoryDto, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, XSubCategoryDto, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int, XCategoryEntityHub>
|
|
{ }
|
|
}
|
|
|
|
### 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<XCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int, XSubCategoryEntityHub>
|
|
{ }
|
|
}
|
|
|
|
### 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<XSubCategory, int>
|
|
{ }
|
|
}
|
|
|
|
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xCategoryService\Models\Dtos\XCategoryDto.cs
|
|
|
|
using xModels.Base;
|
|
|
|
namespace xCategoryService.Models.Dtos
|
|
{
|
|
public class XCategoryDto : XBaseIntIDEntityDto
|
|
{
|
|
/// <summary>
|
|
/// Title of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Description of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// References List String Representation ...
|
|
/// each SubCategory Referenced to Category ID which List here ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Represent a Category by all of it's Resources ...
|
|
/// </summary>
|
|
public class XCategoryResourceDto : XBaseDto
|
|
{
|
|
/// <summary>
|
|
/// Category Dto Item for Add or Update ...
|
|
/// </summary>
|
|
public XCategoryDto Item { get; set; }
|
|
|
|
/// <summary>
|
|
/// Exists Category Titles ...
|
|
/// </summary>
|
|
public XResourceDto Titles { get; set; }
|
|
|
|
/// <summary>
|
|
/// Exists Category Description ...
|
|
/// </summary>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Title of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Description of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// References List String Representation ...
|
|
/// each SubCategory Referenced to Category ID which List here ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// SubCategory Dto Item for Add or Update ...
|
|
/// </summary>
|
|
public XSubCategoryDto Item { get; set; }
|
|
|
|
/// <summary>
|
|
/// Exists SubCategory Titles ...
|
|
/// </summary>
|
|
public XResourceDto Titles { get; set; }
|
|
|
|
/// <summary>
|
|
/// Exists SubCategory Description ...
|
|
/// </summary>
|
|
public XResourceDto Descriptions { get; set; }
|
|
|
|
/// <summary>
|
|
/// Exists Category Resource Dto for Add or Update Category or
|
|
/// Related Categopry ...
|
|
/// </summary>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Title of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Description of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// References List String Representation ...
|
|
/// each SubCategory Referenced to Category ID which List here ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Title of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Description of SubCategory ...
|
|
/// this is a Resource Title ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
public string Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// References List String Representation ...
|
|
/// each SubCategory Referenced to Category ID which List here ...
|
|
/// </summary>
|
|
/// <value></value>
|
|
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<TKey> : IXBaseCategoryProvider<TKey>
|
|
{
|
|
//
|
|
#region Props ...
|
|
/// <summary>
|
|
/// Provider Identifier ...
|
|
/// </summary>
|
|
public string Provider { get; }
|
|
|
|
/// <summary>
|
|
/// Tag Provider for Maipulating Tags ...
|
|
/// </summary>
|
|
public IXCategoryServiceProvider CategoryProvider { get; }
|
|
#endregion
|
|
|
|
//
|
|
#region Constructor ...
|
|
public XBaseCategoryProvider(
|
|
string providedFor,
|
|
IXCategoryServiceProvider categoryProvider
|
|
)
|
|
{
|
|
//
|
|
Provider = providedFor;
|
|
CategoryProvider = categoryProvider;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Referenced Actions ...
|
|
/// <summary>
|
|
/// Get Specified Indexed Reference for Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="forIndex"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve all Exists References of Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XCategoryDto>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extract all Referencing Models for Specified Key ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XReference<TKey>>> 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<TKey>())
|
|
.Where(x => x.ProvidedFor == Provider && $"{x.ReferencedTo}" == $"{providedForId}")
|
|
.OrderBy(x => x.Index)
|
|
.AsEnumerable();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Count References ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve References of Specific Provided ID as Query ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XQueryResult<XCategoryDto>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Reference a Model to Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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<string>
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Reference a Model to Specific XRefence<TKey/> ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="reference"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AddReference(
|
|
XCategoryDto model,
|
|
XReference<TKey> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Reference a Model for Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Reference a Model for Specific XRefence<TKey/> ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="reference"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RemoveReference(
|
|
XCategoryDto model,
|
|
XReference<TKey> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove All References to Specified Key ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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<IEnumerable<int>> GetReferencingIndexes(
|
|
TKey providedForId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate ...
|
|
var isValid =
|
|
!providedForId.IsNull();
|
|
if (!isValid)
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var result = new List<int>();
|
|
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<XCategory, int>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configure Entities ...
|
|
/// </summary>
|
|
/// <param name="modelBuilder"></param>
|
|
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<XCategory, XCategoryDto, int, XCategoryDtoHub>, 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 ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Category by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async IAsyncEnumerable<XCategoryResourceDto> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XCategoryResourceDto>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XCategoryResourceDto>();
|
|
|
|
//
|
|
var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken);
|
|
await foreach (var item in enumerable)
|
|
{
|
|
//
|
|
if (cancellationToken.IsCancellationRequested)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result.Add(item);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryResourceDto> FindOneResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XCategoryResourceDto>> FindManyResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var isApproved = false;
|
|
var result = new List<XCategoryResourceDto>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XQueryResult<XCategoryResourceDto>> QueryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> 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<XCategoryResourceDto>
|
|
{
|
|
Page = query.Page,
|
|
Items = [.. items],
|
|
PageSize = query.PageSize,
|
|
TotalPages = totalPagesCount,
|
|
TotalItems = totalItemsCount,
|
|
TotalFilteredPages = filteredPagesCount,
|
|
TotalFilteredItems = filteredItemsCount
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region SubCategory References ...
|
|
/// <summary>
|
|
/// Get Specified Indexed Reference for Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="forIndex"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XCategoryDto> GetReference(
|
|
int providedForId,
|
|
int forIndex = 0,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.GetReference(
|
|
forIndex: forIndex,
|
|
providedForId: providedForId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve all Exists References of Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XCategoryDto>> GetAllReferences(
|
|
int providedForId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.GetAllReferences(
|
|
providedForId: providedForId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extract all Referencing Models for Specified Key ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XReference<int>>> GetAllReferencings(
|
|
int providedForId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.GetAllReferencings(
|
|
providedForId: providedForId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Count References ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> CountReferences(
|
|
int providedForId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.CountReferences(
|
|
providedForId: providedForId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve References of Specific Provided ID as Query ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XQueryResult<XCategoryDto>> QueryReferences(
|
|
XQuery query,
|
|
int providedForId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.QueryReferences(
|
|
query: query,
|
|
providedForId: providedForId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Reference a Model to Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Reference a Model to Specific XRefence<TKey/> ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="reference"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AddReference(
|
|
XCategoryDto model,
|
|
XReference<int> reference,
|
|
string connectionId = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.AddReference(
|
|
model: model,
|
|
reference: reference,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Reference a Model for Specific Provided ID ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Reference a Model for Specific XRefence<TKey/> ...
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <param name="reference"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RemoveReference(
|
|
XCategoryDto model,
|
|
XReference<int> reference,
|
|
string connectionId = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await categorySubCategoryReferenceProvider
|
|
.RemoveReference(
|
|
model: model,
|
|
reference: reference,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove All References to Specified Key ...
|
|
/// </summary>
|
|
/// <param name="providedForId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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
|
|
{
|
|
/// <summary>
|
|
/// Completely Exported Service ...
|
|
/// </summary>
|
|
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 ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<bool> CategoryHasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.HasLocale(
|
|
id: id,
|
|
language: language,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> GetCategoryResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.GetResource(
|
|
id: id,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item by It's Locales ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> AddCategoryResource(
|
|
XCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.AddResource(
|
|
item: item,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> RefreshCategory(
|
|
XCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.Refresh(
|
|
resource: resource,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XCategoryResourceDto>> GetAllCategoryResources(
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.GetAllResources(
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XCategoryResourceDto> FindOneCategoryResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.FindOneResource(
|
|
predicate: predicate,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XCategoryResourceDto>> FindManyCategoryResource(
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.FindManyResource(
|
|
predicate: predicate,
|
|
orderBuilder: orderBuilder,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XQueryResult<XCategoryResourceDto>> QueryCategoryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XCategoryResourceDto>, IOrderedQueryable<XCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await categoryProvider
|
|
.QueryResources(
|
|
query: query,
|
|
predicate: predicate,
|
|
orderBuilder: orderBuilder,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual IAsyncEnumerable<XCategoryResourceDto> GetAllCategoryResourcesAsAsyncEnumerable(
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return categoryProvider
|
|
.GetAllResourcesAsAsyncEnumerable(
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region SubCategory Provider ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<bool> SubCategoryHasLocale(
|
|
int id,
|
|
string language,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.HasLocale(
|
|
id: id,
|
|
language: language,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> GetSubCategoryResource(
|
|
int id,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.GetResource(
|
|
id: id,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> AddSubCategoryResource(
|
|
XSubCategoryResourceDto item,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.AddResource(
|
|
item: item,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> 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
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> RefreshSubCategory(
|
|
XSubCategoryResourceDto resource,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.Refresh(
|
|
resource: resource,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XSubCategoryResourceDto>> GetAllSubCategoryResources(
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.GetAllResources(
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XSubCategoryResourceDto> FindOneSubCategoryResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.FindOneResource(
|
|
predicate: predicate,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XSubCategoryResourceDto>> FindManySubCategoryResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.FindManyResource(
|
|
predicate: predicate,
|
|
orderBuilder: orderBuilder,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XQueryResult<XSubCategoryResourceDto>> QuerySubCategoryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
return await subCategoryProvider
|
|
.QueryResources(
|
|
query: query,
|
|
predicate: predicate,
|
|
orderBuilder: orderBuilder,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual IAsyncEnumerable<XSubCategoryResourceDto> 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<int>, 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<XSubCategory, int>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configure Entities ...
|
|
/// </summary>
|
|
/// <param name="modelBuilder"></param>
|
|
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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>, 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 ...
|
|
/// <summary>
|
|
/// Check Has Specified Locale or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load an Item by all of it's Related Translations ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Item by it's Locales and Reference ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="language">if null, Remove All</param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an Item for Specified Language ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="language"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh a Resource ...
|
|
/// </summary>
|
|
/// <param name="resource"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources as Async Enumerable ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async IAsyncEnumerable<XSubCategoryResourceDto> 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Resources ...
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XSubCategoryResourceDto>> GetAllResources(
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XSubCategoryResourceDto>();
|
|
|
|
//
|
|
var enumerable = GetAllResourcesAsAsyncEnumerable(cancellationToken);
|
|
await foreach (var item in enumerable)
|
|
{
|
|
//
|
|
if (cancellationToken.IsCancellationRequested)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result.Add(item);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find One Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XSubCategoryResourceDto> FindOneResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Resource ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<XSubCategoryResourceDto>> FindManyResource(
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var isApproved = false;
|
|
var result = new List<XSubCategoryResourceDto>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Resources by Query Pattern ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<XQueryResult<XSubCategoryResourceDto>> QueryResources(
|
|
XQuery query = null,
|
|
Expression<Func<XSubCategoryResourceDto, bool>> predicate = null,
|
|
Func<IQueryable<XSubCategoryResourceDto>, IOrderedQueryable<XSubCategoryResourceDto>> 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<XSubCategoryResourceDto>
|
|
{
|
|
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<XCategory, XCategoryDto, int>, IXCategoryDtoHub
|
|
{
|
|
public XCategoryDtoHub(
|
|
ILogger<XCategoryDtoHub> 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<XCategory, XCategoryDto, int>, IXCategoryRepositoryService
|
|
{
|
|
public XCategoryRepositoryService(
|
|
IXCategoryRepository repository,
|
|
IEnumerable<Profile> 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<XCategory, XCategoryDto, int, XCategoryDtoHub>, IXCategoryServiceProvider
|
|
{
|
|
public XCategoryServiceProvider(
|
|
IHubContext<XCategoryDtoHub> 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<XSubCategory, XSubCategoryDto, int>, IXSubCategoryDtoHub
|
|
{
|
|
public XSubCategoryDtoHub(
|
|
ILogger<XSubCategoryDtoHub> 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<XSubCategory, XSubCategoryDto, int>, IXSubCategoryRepositoryService
|
|
{
|
|
public XSubCategoryRepositoryService(
|
|
IXSubCategoryRepository repository,
|
|
IEnumerable<Profile> 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<XSubCategory, XSubCategoryDto, int, XSubCategoryDtoHub>, IXSubCategoryServiceProvider
|
|
{
|
|
public XSubCategoryServiceProvider(
|
|
IHubContext<XSubCategoryDtoHub> 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<TContext> : XBaseEFRepository<XCategory, int, TContext>, IXCategoryRepository
|
|
where TContext : XDbContext
|
|
{
|
|
public XCategoryEFRepository(
|
|
IXUnitOfWorks<TContext> 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<XCategory, int>, IXCategoryEntityHub
|
|
{
|
|
public XCategoryEntityHub(
|
|
ILogger<XCategoryEntityHub> 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<XCategory, int>, 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<XCategory>, 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<XCategory, int>, 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<XCategory>, 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<XCategory, int, XCategoryEntityHub>, IXCategoryRepositoryProvider
|
|
{
|
|
public XCategoryRepositoryProvider(
|
|
IHubContext<XCategoryEntityHub> 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<XCategory, int>, 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<TContext> : XBaseEFRepository<XSubCategory, int, TContext>, IXSubCategoryRepository
|
|
where TContext : XDbContext
|
|
{
|
|
public XSubCategoryEFRepository(
|
|
IXUnitOfWorks<TContext> 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<XSubCategory, int>, IXSubCategoryEntityHub
|
|
{
|
|
public XSubCategoryEntityHub(
|
|
ILogger<XSubCategoryEntityHub> 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<XSubCategory, int>, 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<XSubCategory>, 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<XSubCategory, int>, 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<XSubCategory>, 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<XSubCategory, int, XSubCategoryEntityHub>, IXSubCategoryRepositoryProvider
|
|
{
|
|
public XSubCategoryRepositoryProvider(
|
|
IHubContext<XSubCategoryEntityHub> 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<XSubCategory, int>, 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<XCategory, int>, 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<XCategory, int, XCategoryGraphType, IntGraphType>
|
|
{
|
|
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<XCategory, int>
|
|
{
|
|
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<XSubCategory, int>, 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<XSubCategory, int, XSubCategoryGraphType, IntGraphType>
|
|
{
|
|
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<XSubCategory, int>
|
|
{
|
|
public XSubCategoryGraphType() : base()
|
|
{
|
|
Field(x => x.Title);
|
|
Field(x => x.Description);
|
|
Field(x => x.References);
|
|
}
|
|
}
|
|
}
|