last ...
This commit is contained in:
@@ -1,291 +1,180 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using xCommons.Attributes;
|
using xCommons.Attributes;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
|
using xDataService.Controllers;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
using xModels.Interfaces;
|
|
||||||
|
|
||||||
namespace xIdentityService.Controllers {
|
namespace xIdentityService.Controllers
|
||||||
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[RequireXPowered(false)]
|
[RequireXPowered(false)]
|
||||||
public abstract class XIBaseEntityController<TEntity, TKey> : XIBaseController, IXEntityControllerActions<TEntity, TKey>
|
public abstract class XIBaseEntityController<TEntity, TKey> : XIBaseController, IXEntityControllerActions<TEntity, TKey>
|
||||||
where TEntity : XBaseEntity<TKey> {
|
where TEntity : XBaseEntity<TKey>
|
||||||
public readonly IXBaseRepository<TEntity, TKey> repository;
|
{
|
||||||
|
//
|
||||||
|
#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(
|
protected XIBaseEntityController(
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
XAppConfiguration appConfiguration,
|
XAppConfiguration appConfiguration,
|
||||||
IXIdentityProvider identityProvider,
|
IXIdentityProvider identityProvider,
|
||||||
XValidationProvider validationProvider,
|
XValidationProvider validationProvider,
|
||||||
IXBaseRepository<TEntity, TKey> repository
|
IXBaseRepository<TEntity, TKey> repository,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
||||||
) : base(
|
) : base(
|
||||||
logger,
|
logger,
|
||||||
appConfiguration,
|
appConfiguration,
|
||||||
identityProvider,
|
identityProvider,
|
||||||
validationProvider
|
validationProvider
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
this.repository = repository;
|
Repository = repository;
|
||||||
|
DefaultOrderBuilder = defaultOrderBuilder;
|
||||||
|
DefaultIncludeBuilder = defaultIncludeBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
#region Interface Implementations ...
|
|
||||||
//
|
|
||||||
#region Retrieve ...
|
|
||||||
[HttpGet ("{id}")]
|
|
||||||
public virtual async Task<ActionResult<TEntity>> Get (
|
|
||||||
[FromRoute] TKey id, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
ValidationProvider.NotNull (id);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Result ...
|
|
||||||
var result = await repository
|
|
||||||
.GetAsync (
|
|
||||||
id,
|
|
||||||
ignoreSoftDeleteds : ignoreSoftDeleteds,
|
|
||||||
containsDetail : containsDetail
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok (result
|
|
||||||
.ToDynamicObject ());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult (ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
public virtual async Task<ActionResult<IEnumerable<TEntity>>> GetAll (
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Get Result ...
|
|
||||||
var result = await repository
|
|
||||||
.GetAllAsync (
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
containsDetail: containsDetail
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok (result
|
|
||||||
.ToDynamicObject ());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult (ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet ("FindOne/{query}")]
|
|
||||||
public virtual async Task<ActionResult<TEntity>> FindOne (
|
|
||||||
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
ValidationProvider.NotEmpty (query);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Result ...
|
|
||||||
var result = await repository
|
|
||||||
.FindOneAsync (t =>
|
|
||||||
t.PropValuesContains (query),
|
|
||||||
ignoreSoftDeleteds : ignoreSoftDeleteds,
|
|
||||||
containsDetail : containsDetail
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok (result
|
|
||||||
.ToDynamicObject ());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult (ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet ("FindMany/{query}")]
|
|
||||||
public virtual async Task<ActionResult<IEnumerable<TEntity>>> FindMany (
|
|
||||||
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
ValidationProvider.NotEmpty (query);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Result ...
|
|
||||||
var result = await repository
|
|
||||||
.FindManyAsync (t =>
|
|
||||||
t.PropValuesContains (query),
|
|
||||||
ignoreSoftDeleteds : ignoreSoftDeleteds,
|
|
||||||
containsDetail : containsDetail
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok (result
|
|
||||||
.ToDynamicObject ());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult (ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet ("Query")]
|
|
||||||
public virtual async Task<ActionResult<XQueryResult<TEntity>>> Query (
|
|
||||||
[FromQuery] XQuery query, [FromQuery] bool ignoreSoftDeleteds = true
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
ValidationProvider.NotNull (query);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Result ...
|
|
||||||
var result = await repository
|
|
||||||
.QueryAsync (
|
|
||||||
query,
|
|
||||||
ignoreSoftDeleteds : ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok (result
|
|
||||||
.ToDynamicObject ());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult (ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// TODO: Fix this ...
|
|
||||||
// [HttpGet ("RequestPage")]
|
|
||||||
// public virtual async Task<ActionResult<XPageResponse<TEntity>>> RequestPage (
|
|
||||||
// [FromQuery] XPageRequest request, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
// ) {
|
|
||||||
// //
|
|
||||||
// try {
|
|
||||||
// //
|
|
||||||
// // Validate Args ...
|
|
||||||
// ValidationProvider.NotNull (request);
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // Get Result ...
|
|
||||||
// var result = await repository
|
|
||||||
// .RequestPageAsync (
|
|
||||||
// request,
|
|
||||||
// ignoreSoftDeleteds : ignoreSoftDeleteds,
|
|
||||||
// containsDetail : containsDetail
|
|
||||||
// );
|
|
||||||
|
|
||||||
// //
|
|
||||||
// return Ok (result
|
|
||||||
// .ToDynamicObject ());
|
|
||||||
// } catch (Exception ex) {
|
|
||||||
// //
|
|
||||||
// var result = GetExceptionActionResult (ex);
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
//
|
//
|
||||||
#region Add ...
|
#region Add ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual async Task<ActionResult<TEntity>> Add(
|
public virtual async Task<ActionResult<TEntity>> Add(
|
||||||
[FromBody] TEntity item
|
[FromBody] TEntity item,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
ValidationProvider.NotNull(item);
|
ValidationProvider.NotNull(item);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.AddAsync(
|
.AddAsync(
|
||||||
item,
|
item,
|
||||||
saveChanges : true
|
saveChanges: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add or Update Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost("AddOrUpdate")]
|
[HttpPost("AddOrUpdate")]
|
||||||
public virtual async Task<ActionResult<TEntity>> AddOrUpdate(
|
public virtual async Task<ActionResult<TEntity>> AddOrUpdate(
|
||||||
[FromBody] TEntity item
|
[FromBody] TEntity item,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
ValidationProvider.NotNull(item);
|
ValidationProvider.NotNull(item);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.AddOrUpdateAsync(
|
.AddOrUpdateAsync(
|
||||||
item,
|
item,
|
||||||
saveChanges : true
|
saveChanges: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a Collection of Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost("AddMany")]
|
[HttpPost("AddMany")]
|
||||||
public virtual async Task<ActionResult> AddMany(
|
public virtual async Task<ActionResult> AddMany(
|
||||||
[FromBody] XBaseRangeRequest<TEntity> request
|
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
await ValidationProvider
|
await ValidationProvider
|
||||||
@@ -296,15 +185,276 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
await repository
|
await Repository
|
||||||
.AddRangeAsync(
|
.AddRangeAsync(
|
||||||
request.Items,
|
request.Items,
|
||||||
saveChanges : true
|
saveChanges: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok();
|
return Ok();
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
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);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
@@ -314,15 +464,29 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Update ...
|
#region Update ...
|
||||||
|
/// <summary>
|
||||||
|
/// Update Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public virtual async Task<ActionResult<TEntity>> Update(
|
public virtual async Task<ActionResult<TEntity>> Update(
|
||||||
[FromRoute] TKey id, [FromBody] TEntity item
|
[FromRoute] TKey id,
|
||||||
) {
|
[FromBody] TEntity item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
await ValidationProvider
|
await ValidationProvider
|
||||||
@@ -332,32 +496,47 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.UpdateAsync(
|
.UpdateAsync(
|
||||||
id,
|
id: id,
|
||||||
item,
|
item: item,
|
||||||
saveChanges : true
|
saveChanges: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a Collection of items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost("UpdateMany")]
|
[HttpPost("UpdateMany")]
|
||||||
public virtual async Task<ActionResult<bool>> UpdateMany(
|
public virtual async Task<ActionResult<bool>> UpdateMany(
|
||||||
[FromBody] XBaseRangeRequest<TEntity> request
|
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
await ValidationProvider
|
await ValidationProvider
|
||||||
@@ -368,16 +547,19 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.UpdateRangeAsync(
|
.UpdateRangeAsync(
|
||||||
request.Items,
|
saveChanges: true,
|
||||||
saveChanges : true
|
items: request.Items,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
@@ -387,28 +569,44 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Exists ...
|
#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")]
|
[HttpGet("{id}/IsExists")]
|
||||||
public virtual async Task<ActionResult<bool>> IsExists(
|
public virtual async Task<ActionResult<bool>> IsExists(
|
||||||
[FromRoute] TKey id, [FromQuery] bool ignoreSoftDeleteds = true
|
[FromRoute] TKey id,
|
||||||
) {
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
ValidationProvider.NotNull(id);
|
ValidationProvider.NotNull(id);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.IsExistsAsync(
|
.IsExistsAsync(
|
||||||
id,
|
id: id,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
@@ -418,43 +616,70 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Remove ...
|
#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}")]
|
[HttpDelete("{id}")]
|
||||||
public virtual async Task<ActionResult<TEntity>> Remove(
|
public virtual async Task<ActionResult<TEntity>> Remove(
|
||||||
[FromRoute] TKey id,
|
[FromRoute] TKey id,
|
||||||
bool softDelete = true
|
[FromQuery] bool softDelete = true,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
ValidationProvider.NotNull(id);
|
ValidationProvider.NotNull(id);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
var result = await repository
|
var result = await Repository
|
||||||
.RemoveAsync(
|
.RemoveAsync(
|
||||||
id,
|
id: id,
|
||||||
saveChanges: true,
|
saveChanges: true,
|
||||||
softDelete : softDelete
|
softDelete: softDelete,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok(result
|
return Ok(result
|
||||||
.ToDynamicObject());
|
.ToDynamicObject());
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
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")]
|
[HttpPost("RemoveMany")]
|
||||||
public virtual async Task<ActionResult> RemoveMany(
|
public virtual async Task<ActionResult> RemoveMany(
|
||||||
[FromBody] XBaseRangeRequest<TEntity> request,
|
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||||
bool softDelete = true
|
[FromQuery] bool softDelete = true,
|
||||||
) {
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
await ValidationProvider
|
await ValidationProvider
|
||||||
@@ -465,16 +690,19 @@ namespace xIdentityService.Controllers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Get Result ...
|
// Get Result ...
|
||||||
await repository
|
await Repository
|
||||||
.RemoveRangeAsync(
|
.RemoveRangeAsync(
|
||||||
request.Items,
|
|
||||||
saveChanges: true,
|
saveChanges: true,
|
||||||
softDelete : softDelete
|
items: request.Items,
|
||||||
|
softDelete: softDelete,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return Ok();
|
return Ok();
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = GetExceptionActionResult(ex);
|
var result = GetExceptionActionResult(ex);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -28,12 +28,10 @@
|
|||||||
|
|
||||||
<!-- Local Dependencies -->
|
<!-- Local Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- <ProjectReference Include="../xDataService/xDataService.csproj" />
|
|
||||||
<ProjectReference Include="../xHttpService/xHttpService.csproj" /> -->
|
|
||||||
|
|
||||||
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||||
|
<ProjectReference Include="../xHttpService/xHttpService.csproj" />
|
||||||
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
|
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
|
||||||
<PackageReference Include="xDashboard.xHttpService" Version="1.0.0" />
|
<!-- <PackageReference Include="xDashboard.xHttpService" Version="1.0.0" /> -->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
|
|||||||
Reference in New Issue
Block a user