This commit is contained in:
2026-05-16 01:14:38 +03:30
parent 2ef7e559d7
commit e557fd763e
5 changed files with 57 additions and 1446 deletions
+32
View File
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using xCommons.Attributes;
using xCommons.Configurations;
using xCommons.Providers;
using xIdentityService.Interfaces;
namespace xIdentityService.Controllers
{
/// <summary>
/// Base Identity Api Controller
/// </summary>
[ApiController]
[RequireXPowered(true)]
[Route("api/[controller]")]
[Produces("application/json")]
public abstract class XBaseIdentityApiController : XBaseIdentityController
{
protected XBaseIdentityApiController(
ILogger logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{ }
}
}
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using xCommons.Attributes; using xCommons.Attributes;
using xCommons.Configurations; using xCommons.Configurations;
@@ -7,11 +7,16 @@ using xIdentityService.Interfaces;
namespace xIdentityService.Controllers namespace xIdentityService.Controllers
{ {
[Authorize] /// <summary>
[RequireXPowered(false)] /// Base Identity Api V1 Controller
public abstract class XIBaseProviderController : XIBaseController /// </summary>
[ApiController]
[ApiVersion("1.0")]
[RequireXPowered(true)]
[Route("api/v{version:apiVersion}/[controller]")]
public abstract class XBaseIdentityApiV1Controller : XBaseIdentityApiController
{ {
protected XIBaseProviderController( protected XBaseIdentityApiV1Controller(
ILogger logger, ILogger logger,
XAppConfiguration appConfiguration, XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider, IXIdentityProvider identityProvider,
@@ -16,11 +16,12 @@ using xIdentityService.Interfaces;
namespace xIdentityService.Controllers namespace xIdentityService.Controllers
{ {
public abstract class XIBaseController : XBaseController public abstract class XBaseIdentityController : XBaseController
{ {
private readonly IXIdentityProvider identityProvider; //
public IXIdentityProvider IdentityProvider { get; }
public XIBaseController( protected XBaseIdentityController(
ILogger logger, ILogger logger,
XAppConfiguration appConfiguration, XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider, IXIdentityProvider identityProvider,
@@ -31,7 +32,7 @@ namespace xIdentityService.Controllers
validationProvider validationProvider
) )
{ {
this.identityProvider = identityProvider; IdentityProvider = identityProvider;
} }
// //
@@ -79,10 +80,11 @@ namespace xIdentityService.Controllers
ValidationProvider.NotNull(model); ValidationProvider.NotNull(model);
// //
var result = identityProvider.GetUserSelectByParam( var result = IdentityProvider.GetUserSelectByParam(
model, model,
forceNotNull, forceNotNull,
excludes); excludes
);
// //
return result; return result;
@@ -96,10 +98,10 @@ namespace xIdentityService.Controllers
public async Task<string> GetAccessToken() public async Task<string> GetAccessToken()
{ {
// //
var accessToken = Request.Headers[XAuthorization.Header] var accessToken = Request.Headers[XAuthorization.Header].ToString();
.ToString();
if (accessToken.IsNullOrEmpty()) if (accessToken.IsNullOrEmpty())
{ {
//
accessToken = await HttpContext accessToken = await HttpContext
.GetTokenAsync(XAuthorization.AccessToken); .GetTokenAsync(XAuthorization.AccessToken);
} }
@@ -110,6 +112,7 @@ namespace xIdentityService.Controllers
.Contains(XAuthorization.TokenIdentifier .Contains(XAuthorization.TokenIdentifier
.ToNormalString())) .ToNormalString()))
{ {
//
accessToken = accessToken accessToken = accessToken
.Remove(0, XAuthorization.TokenIdentifier.Length); .Remove(0, XAuthorization.TokenIdentifier.Length);
} }
@@ -126,10 +129,10 @@ namespace xIdentityService.Controllers
public async Task<string> GetRefreshToken() public async Task<string> GetRefreshToken()
{ {
// //
var refreshToken = Request.Headers[XAuthorization.RefreshToken] var refreshToken = Request.Headers[XAuthorization.RefreshToken].ToString();
.ToString();
if (refreshToken.IsNullOrEmpty()) if (refreshToken.IsNullOrEmpty())
{ {
//
refreshToken = await HttpContext refreshToken = await HttpContext
.GetTokenAsync(XAuthorization.RefreshToken); .GetTokenAsync(XAuthorization.RefreshToken);
} }
@@ -146,10 +149,10 @@ namespace xIdentityService.Controllers
public async Task<long> GetTokenExpiresAt() public async Task<long> GetTokenExpiresAt()
{ {
// //
var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt] var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt].ToString();
.ToString();
if (expiresAtStr.IsNullOrEmpty()) if (expiresAtStr.IsNullOrEmpty())
{ {
//
expiresAtStr = await HttpContext expiresAtStr = await HttpContext
.GetTokenAsync(XAuthorization.ExpiresAt); .GetTokenAsync(XAuthorization.ExpiresAt);
} }
-714
View File
@@ -1,714 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Attributes;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xDataService.Interfaces;
using xExceptions.Constants;
using xIdentityService.Interfaces;
using xModels.Base;
using xModels.Dtos;
namespace xIdentityService.Controllers
{
//
// TODO: Complete this ...
// [Authorize]
// [RequireXPowered(false)]
// public abstract class XIBaseDomainController<TEntity, TDto, TKey> : XIBaseController, IXDomainControllerActions<TEntity, TDto, TKey>
// where TEntity : XBaseEntity<TKey>
// where TDto : XBaseEntityDto<TKey>
// {
// //
// #region Properties ...
// public IXBaseRepositoryService<TEntity, TDto, TKey> RepositoryService { get; }
// public Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> DefaultOrderBuilder { get; }
// public Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> DefaultIncludeBuilder { get; }
// #endregion
// //
// #region Constructor ...
// protected XIBaseDomainController(
// ILogger logger,
// XAppConfiguration appConfiguration,
// IXIdentityProvider identityProvider,
// XValidationProvider validationProvider,
// IXBaseRepositoryService<TEntity, TDto, TKey> repositoryService,
// Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
// Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
// ) : base(
// logger,
// appConfiguration,
// identityProvider,
// validationProvider
// )
// {
// //
// RepositoryService = repositoryService;
// DefaultOrderBuilder = defaultOrderBuilder;
// DefaultIncludeBuilder = defaultIncludeBuilder;
// }
// #endregion
// //
// #region Actions ...
// //
// #region Add ...
// /// <summary>
// /// Add Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost]
// public virtual async Task<ActionResult<TDto>> Add(
// [FromBody] TDto item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// ValidationProvider.NotNull(item);
// //
// // Get Result ...
// var result = await RepositoryService
// .AddAsync(
// item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Add or Update Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("AddOrUpdate")]
// public virtual async Task<ActionResult<TDto>> AddOrUpdate(
// [FromBody] TDto item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// ValidationProvider.NotNull(item);
// //
// // Get Result ...
// var result = await RepositoryService
// .AddOrUpdateAsync(
// item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Add a Collection of Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("AddMany")]
// public virtual async Task<ActionResult> AddMany(
// [FromBody] XBaseRangeRequest<TDto> request,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// await RepositoryService
// .AddRangeAsync(
// request.Items,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok();
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Retrieve ...
// /// <summary>
// /// Get Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("{id}")]
// public virtual async Task<ActionResult<TDto>> Get(
// [FromRoute] TKey id,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await RepositoryService
// .GetAsync(
// id,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Get All Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet]
// public virtual async Task<ActionResult<IEnumerable<TDto>>> GetAll(
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Get Result ...
// var result = await RepositoryService
// .GetAllAsync(
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Find Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("FindOne/{query}")]
// public virtual async Task<ActionResult<TDto>> FindOne(
// [FromRoute] string query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotEmpty(query);
// //
// // Get Result ...
// var result = await RepositoryService
// .FindOneAsync(
// predicate: t =>
// t.PropValuesContains(query),
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Find Many Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("FindMany/{query}")]
// public virtual async Task<ActionResult<IEnumerable<TDto>>> FindMany(
// [FromRoute] string query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotEmpty(query);
// //
// // Get Result ...
// var result = await RepositoryService
// .FindManyAsync(
// predicate: t =>
// t.PropValuesContains(query),
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Retrieve Items Based on Query Mechanism ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("Query")]
// public virtual async Task<ActionResult<XQueryResult<TDto>>> Query(
// [FromQuery] XQuery query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(query);
// //
// // Get Result ...
// var result = await RepositoryService
// .QueryAsync(
// query: query,
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Update ...
// /// <summary>
// /// Update Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPut("{id}")]
// public virtual async Task<ActionResult<TDto>> Update(
// [FromRoute] TKey id,
// [FromBody] TDto item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(id, item)
// .ValidateGroupAsync();
// //
// // Get Result ...
// var result = await RepositoryService
// .UpdateAsync(
// id: id,
// item: item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Update a Collection of items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("UpdateMany")]
// public virtual async Task<ActionResult<bool>> UpdateMany(
// [FromBody] XBaseRangeRequest<TDto> request,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// var result = await RepositoryService
// .UpdateRangeAsync(
// saveChanges: true,
// items: request.Items,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Exists ...
// /// <summary>
// ///Check an Item Exists or not ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("{id}/IsExists")]
// public virtual async Task<ActionResult<bool>> IsExists(
// [FromRoute] TKey id,
// [FromQuery] bool ignoreSoftDeleteds = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await RepositoryService
// .IsExistsAsync(
// id: id,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Remove ...
// /// <summary>
// /// Remove an Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="softDelete"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpDelete("{id}")]
// public virtual async Task<ActionResult<TDto>> Remove(
// [FromRoute] TKey id,
// [FromQuery] bool softDelete = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await RepositoryService
// .RemoveAsync(
// id: id,
// saveChanges: true,
// softDelete: softDelete,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Remove Many Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="softDelete"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("RemoveMany")]
// public virtual async Task<ActionResult> RemoveMany(
// [FromBody] XBaseRangeRequest<TDto> request,
// [FromQuery] bool softDelete = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// await RepositoryService
// .RemoveRangeAsync(
// saveChanges: true,
// items: request.Items,
// softDelete: softDelete,
// cancellationToken: cancellationToken
// );
// //
// return Ok();
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// #endregion
// }
}
-715
View File
@@ -1,715 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Attributes;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xDataService.Interfaces;
using xExceptions.Constants;
using xIdentityService.Interfaces;
using xModels.Base;
using xModels.Dtos;
namespace xIdentityService.Controllers
{
//
// TODO: Fix This ...
// [Authorize]
// [RequireXPowered(false)]
// public abstract class XIBaseEntityController<TEntity, TKey> : XIBaseController, IXEntityControllerActions<TEntity, TKey>
// where TEntity : XBaseEntity<TKey>
// {
// //
// #region Properties ...
// public IXBaseRepository<TEntity, TKey> Repository { get; }
// public Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> DefaultOrderBuilder { get; }
// public Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> DefaultIncludeBuilder { get; }
// #endregion
// //
// #region Constructor ...
// protected XIBaseEntityController(
// ILogger logger,
// XAppConfiguration appConfiguration,
// IXIdentityProvider identityProvider,
// XValidationProvider validationProvider,
// IXBaseRepository<TEntity, TKey> repository,
// Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
// Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
// ) : base(
// logger,
// appConfiguration,
// identityProvider,
// validationProvider
// )
// {
// //
// Repository = repository;
// DefaultOrderBuilder = defaultOrderBuilder;
// DefaultIncludeBuilder = defaultIncludeBuilder;
// }
// #endregion
// //
// #region Actions ...
// //
// #region Add ...
// /// <summary>
// /// Add Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost]
// public virtual async Task<ActionResult<TEntity>> Add(
// [FromBody] TEntity item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// ValidationProvider.NotNull(item);
// //
// // Get Result ...
// var result = await Repository
// .AddAsync(
// item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Add or Update Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("AddOrUpdate")]
// public virtual async Task<ActionResult<TEntity>> AddOrUpdate(
// [FromBody] TEntity item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// ValidationProvider.NotNull(item);
// //
// // Get Result ...
// var result = await Repository
// .AddOrUpdateAsync(
// item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Add a Collection of Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("AddMany")]
// public virtual async Task<ActionResult> AddMany(
// [FromBody] XBaseRangeRequest<TEntity> request,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// await Repository
// .AddRangeAsync(
// request.Items,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok();
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Retrieve ...
// /// <summary>
// /// Get Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("{id}")]
// public virtual async Task<ActionResult<TEntity>> Get(
// [FromRoute] TKey id,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await Repository
// .GetAsync(
// id,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Get All Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet]
// public virtual async Task<ActionResult<IEnumerable<TEntity>>> GetAll(
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Get Result ...
// var result = await Repository
// .GetAllAsync(
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Find Specified Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("FindOne/{query}")]
// public virtual async Task<ActionResult<TEntity>> FindOne(
// [FromRoute] string query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotEmpty(query);
// //
// // Get Result ...
// var result = await Repository
// .FindOneAsync(
// predicate: t =>
// t.PropValuesContains(query),
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Find Many Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("FindMany/{query}")]
// public virtual async Task<ActionResult<IEnumerable<TEntity>>> FindMany(
// [FromRoute] string query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotEmpty(query);
// //
// // Get Result ...
// var result = await Repository
// .FindManyAsync(
// predicate: t =>
// t.PropValuesContains(query),
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Retrieve Items Based on Query Mechanism ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="query"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="useDefaultOrders"></param>
// /// <param name="useDefaultIncludes"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("Query")]
// public virtual async Task<ActionResult<XQueryResult<TEntity>>> Query(
// [FromQuery] XQuery query,
// [FromQuery] bool ignoreSoftDeleteds = true,
// [FromQuery] bool useDefaultOrders = false,
// [FromQuery] bool useDefaultIncludes = false,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(query);
// //
// // Get Result ...
// var result = await Repository
// .QueryAsync(
// query: query,
// orderBuilder: useDefaultOrders
// ? DefaultOrderBuilder
// : null,
// includeBuilder: useDefaultIncludes
// ? DefaultIncludeBuilder
// : null,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Update ...
// /// <summary>
// /// Update Item ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="item"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPut("{id}")]
// public virtual async Task<ActionResult<TEntity>> Update(
// [FromRoute] TKey id,
// [FromBody] TEntity item,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(id, item)
// .ValidateGroupAsync();
// //
// // Get Result ...
// var result = await Repository
// .UpdateAsync(
// id: id,
// item: item,
// saveChanges: true,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Update a Collection of items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("UpdateMany")]
// public virtual async Task<ActionResult<bool>> UpdateMany(
// [FromBody] XBaseRangeRequest<TEntity> request,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// if (!ModelState.IsValid)
// {
// XException.InvalidArgs.Throw();
// }
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// var result = await Repository
// .UpdateRangeAsync(
// saveChanges: true,
// items: request.Items,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Exists ...
// /// <summary>
// ///Check an Item Exists or not ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="ignoreSoftDeleteds"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpGet("{id}/IsExists")]
// public virtual async Task<ActionResult<bool>> IsExists(
// [FromRoute] TKey id,
// [FromQuery] bool ignoreSoftDeleteds = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await Repository
// .IsExistsAsync(
// id: id,
// cancellationToken: cancellationToken,
// ignoreSoftDeleteds: ignoreSoftDeleteds
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// //
// #region Remove ...
// /// <summary>
// /// Remove an Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="id"></param>
// /// <param name="softDelete"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpDelete("{id}")]
// public virtual async Task<ActionResult<TEntity>> Remove(
// [FromRoute] TKey id,
// [FromQuery] bool softDelete = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// ValidationProvider.NotNull(id);
// //
// // Get Result ...
// var result = await Repository
// .RemoveAsync(
// id: id,
// saveChanges: true,
// softDelete: softDelete,
// cancellationToken: cancellationToken
// );
// //
// return Ok(result
// .ToDynamicObject());
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// /// <summary>
// /// Remove Many Items ...
// /// </summary>
// /// <remarks>
// /// </remarks>
// /// <param name="request"></param>
// /// <param name="softDelete"></param>
// /// <param name="cancellationToken"></param>
// /// <returns></returns>
// [HttpPost("RemoveMany")]
// public virtual async Task<ActionResult> RemoveMany(
// [FromBody] XBaseRangeRequest<TEntity> request,
// [FromQuery] bool softDelete = true,
// CancellationToken cancellationToken = default
// )
// {
// //
// try
// {
// //
// // Validate Args ...
// await ValidationProvider
// .GroupValidationBuilder()
// .AddNotNull(request)
// .AddNotZeroChilds(request.Items)
// .ValidateGroupAsync();
// //
// // Get Result ...
// await Repository
// .RemoveRangeAsync(
// saveChanges: true,
// items: request.Items,
// softDelete: softDelete,
// cancellationToken: cancellationToken
// );
// //
// return Ok();
// }
// catch (Exception ex)
// {
// //
// var result = GetExceptionActionResult(ex);
// return result;
// }
// }
// #endregion
// #endregion
// }
}