last ...
This commit is contained in:
@@ -1,291 +1,180 @@
|
||||
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.Controllers;
|
||||
using xDataService.Interfaces;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
using xModels.Interfaces;
|
||||
|
||||
namespace xIdentityService.Controllers {
|
||||
namespace xIdentityService.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[RequireXPowered(false)]
|
||||
public abstract class XIBaseEntityController<TEntity, TKey> : XIBaseController, IXEntityControllerActions<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey> {
|
||||
public readonly IXBaseRepository<TEntity, TKey> repository;
|
||||
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
|
||||
IXBaseRepository<TEntity, TKey> repository,
|
||||
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
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
|
||||
|
||||
//
|
||||
#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
|
||||
) {
|
||||
[FromBody] TEntity item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
ValidationProvider.NotNull(item);
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.AddAsync(
|
||||
item,
|
||||
saveChanges : true
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
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
|
||||
) {
|
||||
[FromBody] TEntity item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
ValidationProvider.NotNull(item);
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.AddOrUpdateAsync(
|
||||
item,
|
||||
saveChanges : true
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
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
|
||||
) {
|
||||
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
@@ -296,15 +185,276 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
await repository
|
||||
await Repository
|
||||
.AddRangeAsync(
|
||||
request.Items,
|
||||
saveChanges : true
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
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);
|
||||
return result;
|
||||
@@ -314,15 +464,29 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
#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
|
||||
) {
|
||||
[FromRoute] TKey id,
|
||||
[FromBody] TEntity item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
@@ -332,32 +496,47 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.UpdateAsync(
|
||||
id,
|
||||
item,
|
||||
saveChanges : true
|
||||
id: id,
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
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
|
||||
) {
|
||||
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
@@ -368,16 +547,19 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.UpdateRangeAsync(
|
||||
request.Items,
|
||||
saveChanges : true
|
||||
saveChanges: true,
|
||||
items: request.Items,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
@@ -387,28 +569,44 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
#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
|
||||
) {
|
||||
[FromRoute] TKey id,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotNull(id);
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.IsExistsAsync(
|
||||
id,
|
||||
id: id,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
@@ -418,43 +616,70 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
#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,
|
||||
bool softDelete = true
|
||||
) {
|
||||
[FromQuery] bool softDelete = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotNull(id);
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
var result = await repository
|
||||
var result = await Repository
|
||||
.RemoveAsync(
|
||||
id,
|
||||
id: id,
|
||||
saveChanges: true,
|
||||
softDelete : softDelete
|
||||
softDelete: softDelete,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
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,
|
||||
bool softDelete = true
|
||||
) {
|
||||
[FromQuery] bool softDelete = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try {
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
await ValidationProvider
|
||||
@@ -465,16 +690,19 @@ namespace xIdentityService.Controllers {
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
await repository
|
||||
await Repository
|
||||
.RemoveRangeAsync(
|
||||
request.Items,
|
||||
saveChanges: true,
|
||||
softDelete : softDelete
|
||||
items: request.Items,
|
||||
softDelete: softDelete,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
|
||||
<!-- Local Dependencies -->
|
||||
<ItemGroup>
|
||||
<!-- <ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||
<ProjectReference Include="../xHttpService/xHttpService.csproj" /> -->
|
||||
|
||||
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||
<ProjectReference Include="../xHttpService/xHttpService.csproj" />
|
||||
<!-- <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>
|
||||
|
||||
<!-- Dependencies -->
|
||||
|
||||
Reference in New Issue
Block a user