Compare commits
10
Commits
a7916ebd8a
...
7e6f547081
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e6f547081 | ||
|
|
62687a9948 | ||
|
|
b55e9960a5 | ||
|
|
4898c04a5e | ||
|
|
32adfbc8d0 | ||
|
|
042f3eb812 | ||
|
|
8ebcf3c809 | ||
|
|
871df0b171 | ||
|
|
e557fd763e | ||
|
|
2ef7e559d7 |
@@ -3,7 +3,8 @@ using xExceptions.Attributes;
|
||||
namespace xIdentityService.Constants {
|
||||
public enum XAuthenticationScheme {
|
||||
[StringValue ("token")]
|
||||
XToken, [StringValue ("introspection")]
|
||||
XToken,
|
||||
[StringValue ("introspection")]
|
||||
XIntrospection,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Configurations;
|
||||
@@ -7,11 +7,16 @@ using xIdentityService.Interfaces;
|
||||
|
||||
namespace xIdentityService.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[RequireXPowered(false)]
|
||||
public abstract class XIBaseProviderController : XIBaseController
|
||||
/// <summary>
|
||||
/// Base Identity Api V1 Controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[RequireXPowered(true)]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public abstract class XBaseIdentityApiV1Controller : XBaseIdentityApiController
|
||||
{
|
||||
protected XIBaseProviderController(
|
||||
protected XBaseIdentityApiV1Controller(
|
||||
ILogger logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
@@ -16,11 +16,12 @@ using xIdentityService.Interfaces;
|
||||
|
||||
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,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
@@ -31,7 +32,7 @@ namespace xIdentityService.Controllers
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.identityProvider = identityProvider;
|
||||
IdentityProvider = identityProvider;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -79,10 +80,11 @@ namespace xIdentityService.Controllers
|
||||
ValidationProvider.NotNull(model);
|
||||
|
||||
//
|
||||
var result = identityProvider.GetUserSelectByParam(
|
||||
var result = IdentityProvider.GetUserSelectByParam(
|
||||
model,
|
||||
forceNotNull,
|
||||
excludes);
|
||||
excludes
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -96,10 +98,10 @@ namespace xIdentityService.Controllers
|
||||
public async Task<string> GetAccessToken()
|
||||
{
|
||||
//
|
||||
var accessToken = Request.Headers[XAuthorization.Header]
|
||||
.ToString();
|
||||
var accessToken = Request.Headers[XAuthorization.Header].ToString();
|
||||
if (accessToken.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
accessToken = await HttpContext
|
||||
.GetTokenAsync(XAuthorization.AccessToken);
|
||||
}
|
||||
@@ -110,6 +112,7 @@ namespace xIdentityService.Controllers
|
||||
.Contains(XAuthorization.TokenIdentifier
|
||||
.ToNormalString()))
|
||||
{
|
||||
//
|
||||
accessToken = accessToken
|
||||
.Remove(0, XAuthorization.TokenIdentifier.Length);
|
||||
}
|
||||
@@ -126,10 +129,10 @@ namespace xIdentityService.Controllers
|
||||
public async Task<string> GetRefreshToken()
|
||||
{
|
||||
//
|
||||
var refreshToken = Request.Headers[XAuthorization.RefreshToken]
|
||||
.ToString();
|
||||
var refreshToken = Request.Headers[XAuthorization.RefreshToken].ToString();
|
||||
if (refreshToken.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
refreshToken = await HttpContext
|
||||
.GetTokenAsync(XAuthorization.RefreshToken);
|
||||
}
|
||||
@@ -146,10 +149,10 @@ namespace xIdentityService.Controllers
|
||||
public async Task<long> GetTokenExpiresAt()
|
||||
{
|
||||
//
|
||||
var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt]
|
||||
.ToString();
|
||||
var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt].ToString();
|
||||
if (expiresAtStr.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
expiresAtStr = await HttpContext
|
||||
.GetTokenAsync(XAuthorization.ExpiresAt);
|
||||
}
|
||||
@@ -1,712 +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
|
||||
{
|
||||
[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
|
||||
}
|
||||
}
|
||||
@@ -1,713 +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
|
||||
{
|
||||
[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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xDataService.Models;
|
||||
using xIdentityModels.Models;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// a Referenced Service is a Service which can Referenced to other Items ...
|
||||
/// </summary>
|
||||
public interface IXBaseReferenced<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get Reference Identifier for Specified Provider and Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <returns></returns>
|
||||
string GetIdentifier<TReferenceKey>(
|
||||
string providedFor,
|
||||
TReferenceKey forProvidedId
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Check Specified Item has Refernce to Provider ...
|
||||
/// </summary>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsProvidedFor<TReferenceKey>(
|
||||
string providedFor,
|
||||
TReferenceKey forProvidedId,
|
||||
TKey id,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Reference to Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task AddReference<TReferenceKey>(
|
||||
string providedFor,
|
||||
TReferenceKey forProvidedId,
|
||||
TKey id,
|
||||
int forIndex = 0,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Reference from Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveReference<TReferenceKey>(
|
||||
string providedFor,
|
||||
TReferenceKey forProvidedId,
|
||||
TKey id,
|
||||
int forIndex = 0,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified References ...
|
||||
/// </summary>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TReferenceKey"></typeparam>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XReference<string>>> GetReferences(
|
||||
string providedFor,
|
||||
TKey id,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xDataService.Models;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityService.Interfaces
|
||||
{
|
||||
public interface IXBaseReferencedController<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Check an Item Has Reference to Specified ProvideFor and Specified forProvidedId ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/Reference/IsProvidedFor")]
|
||||
Task<ActionResult<bool>> IsProvidedFor(
|
||||
[FromRoute] TKey id,
|
||||
[FromQuery] string providedFor,
|
||||
[FromQuery] object forProvidedId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add a Reference to Item for Specified ProvideFor and Specified forProvidedId ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}/Reference")]
|
||||
Task<ActionResult> AddReference(
|
||||
[FromRoute] TKey id,
|
||||
[FromQuery] string providedFor,
|
||||
[FromQuery] object forProvidedId,
|
||||
[FromQuery] int forIndex = 0,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a Reference from Item for Specified ProvideFor and Specified forProvidedId ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}/Reference")]
|
||||
Task<ActionResult> RemoveReference(
|
||||
[FromRoute] TKey id,
|
||||
[FromQuery] string providedFor,
|
||||
[FromQuery] object forProvidedId,
|
||||
[FromQuery] int forIndex = 0,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve References of Specified Itemfor providedFor ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="providedFor"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/References")]
|
||||
Task<ActionResult<IEnumerable<XReference<string>>>> GetReferences(
|
||||
[FromRoute] TKey id,
|
||||
[FromQuery] string providedFor,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<!-- <add key="megan" value="https://hub.megan.ir/nuget/index.json" /> -->
|
||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="liget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
|
||||
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
+11
-1
@@ -1,12 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- Runtime Definition -->
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<Authors>Hadi Khazaee Asl</Authors>
|
||||
<Company>SaherElm IT Center</Company>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>xDashboard.xIdentityService</PackageId>
|
||||
|
||||
<Description>
|
||||
provide an interface to connect xDashboard IdentityServer and do OAuth Actions to xDashboard
|
||||
project.
|
||||
@@ -40,4 +42,12 @@
|
||||
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection"
|
||||
Version="4.0.0-preview.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- For XML Documentation Support -->
|
||||
<PropertyGroup>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user