last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,712 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Controllers;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xModels.Base;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
|
namespace xDataService.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Abstract Controller for Providing Entity Dto Repository Service Actions Implementatin ...
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TDto"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
public abstract class XBaseEntityDtoController<TEntity, TDto, TKey> : XBaseController, IXEntityDtoControllerActions<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 XBaseEntityDtoController(
|
||||||
|
ILogger<XBaseEntityDtoController<TEntity, TDto, TKey>> logger,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
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,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-2
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
@@ -32,9 +33,12 @@ namespace xDataService.Db {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save Changes Async
|
/// Save Changes Async
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> SaveChangesAsync () {
|
public async Task<int> SaveChangesAsync (
|
||||||
return await DbContext.SaveChangesAsync ();
|
CancellationToken cancellationToken = default
|
||||||
|
) {
|
||||||
|
return await DbContext.SaveChangesAsync (cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose () {
|
public void Dispose () {
|
||||||
|
|||||||
+663
-742
File diff suppressed because it is too large
Load Diff
@@ -13,10 +13,6 @@ namespace xDataService.Extensions {
|
|||||||
return source.GetArgument<bool> (XGraphQLHelper.IgnoreSoftDeletedArgument.Name);
|
return source.GetArgument<bool> (XGraphQLHelper.IgnoreSoftDeletedArgument.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetContainsDetailArgument<T> (this IResolveFieldContext<T> source) {
|
|
||||||
return source.GetArgument<bool> (XGraphQLHelper.ContainsDetailArgument.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetSearchQueryArgument<T> (this IResolveFieldContext<T> source) {
|
public static string GetSearchQueryArgument<T> (this IResolveFieldContext<T> source) {
|
||||||
return source.GetArgument<string> (XGraphQLHelper.SearchQueryArgument.Name);
|
return source.GetArgument<string> (XGraphQLHelper.SearchQueryArgument.Name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,15 +41,14 @@ namespace xDataService.GraphQL {
|
|||||||
name: helper.GetInQuerySingleName (),
|
name: helper.GetInQuerySingleName (),
|
||||||
arguments: new QueryArguments (
|
arguments: new QueryArguments (
|
||||||
XGraphQLHelper.GetIdArgument<TGraphKey> (),
|
XGraphQLHelper.GetIdArgument<TGraphKey> (),
|
||||||
XGraphQLHelper.IgnoreSoftDeletedArgument,
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
XGraphQLHelper.ContainsDetailArgument
|
|
||||||
),
|
),
|
||||||
resolve : async context =>
|
resolve : async context =>
|
||||||
await repository
|
await repository
|
||||||
.GetAsync (
|
.GetAsync (
|
||||||
|
includeBuilder: null,
|
||||||
id: context.GetIdArgument<TKey> (),
|
id: context.GetIdArgument<TKey> (),
|
||||||
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (),
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
containsDetail: context.GetContainsDetailArgument ()
|
|
||||||
)
|
)
|
||||||
.ToDynamicObject ()
|
.ToDynamicObject ()
|
||||||
);
|
);
|
||||||
@@ -59,14 +58,14 @@ namespace xDataService.GraphQL {
|
|||||||
FieldAsync<ListGraphType<TGraph>> (
|
FieldAsync<ListGraphType<TGraph>> (
|
||||||
name: helper.GetInQueryCollectionName (),
|
name: helper.GetInQueryCollectionName (),
|
||||||
arguments: new QueryArguments (
|
arguments: new QueryArguments (
|
||||||
XGraphQLHelper.IgnoreSoftDeletedArgument,
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
XGraphQLHelper.ContainsDetailArgument
|
|
||||||
),
|
),
|
||||||
resolve : async context =>
|
resolve : async context =>
|
||||||
await repository
|
await repository
|
||||||
.GetAllAsync (
|
.GetAllAsync (
|
||||||
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (),
|
orderBuilder: null,
|
||||||
containsDetail: context.GetContainsDetailArgument ()
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
)
|
)
|
||||||
.ToDynamicObject ()
|
.ToDynamicObject ()
|
||||||
);
|
);
|
||||||
@@ -77,8 +76,7 @@ namespace xDataService.GraphQL {
|
|||||||
name: helper.GetFindOneName (),
|
name: helper.GetFindOneName (),
|
||||||
arguments: new QueryArguments (
|
arguments: new QueryArguments (
|
||||||
XGraphQLHelper.SearchQueryArgument,
|
XGraphQLHelper.SearchQueryArgument,
|
||||||
XGraphQLHelper.IgnoreSoftDeletedArgument,
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
XGraphQLHelper.ContainsDetailArgument
|
|
||||||
),
|
),
|
||||||
resolve : async (context) => {
|
resolve : async (context) => {
|
||||||
//
|
//
|
||||||
@@ -89,9 +87,9 @@ namespace xDataService.GraphQL {
|
|||||||
//
|
//
|
||||||
return await repository
|
return await repository
|
||||||
.FindOneAsync (
|
.FindOneAsync (
|
||||||
whereClause: whereClase,
|
includeBuilder: null,
|
||||||
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (),
|
predicate: whereClase,
|
||||||
containsDetail: context.GetContainsDetailArgument ()
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
)
|
)
|
||||||
.ToDynamicObject ();
|
.ToDynamicObject ();
|
||||||
}
|
}
|
||||||
@@ -103,8 +101,7 @@ namespace xDataService.GraphQL {
|
|||||||
name: helper.GetFindManyName (),
|
name: helper.GetFindManyName (),
|
||||||
arguments: new QueryArguments (
|
arguments: new QueryArguments (
|
||||||
XGraphQLHelper.SearchQueryArgument,
|
XGraphQLHelper.SearchQueryArgument,
|
||||||
XGraphQLHelper.IgnoreSoftDeletedArgument,
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
XGraphQLHelper.ContainsDetailArgument
|
|
||||||
),
|
),
|
||||||
resolve : async (context) => {
|
resolve : async (context) => {
|
||||||
//
|
//
|
||||||
@@ -115,9 +112,10 @@ namespace xDataService.GraphQL {
|
|||||||
//
|
//
|
||||||
return await repository
|
return await repository
|
||||||
.FindManyAsync (
|
.FindManyAsync (
|
||||||
whereClause: whereClase,
|
orderBuilder: null,
|
||||||
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (),
|
includeBuilder: null,
|
||||||
containsDetail: context.GetContainsDetailArgument ()
|
predicate: whereClase,
|
||||||
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
)
|
)
|
||||||
.ToDynamicObject ();
|
.ToDynamicObject ();
|
||||||
}
|
}
|
||||||
@@ -134,6 +132,9 @@ namespace xDataService.GraphQL {
|
|||||||
resolve : async context =>
|
resolve : async context =>
|
||||||
await repository
|
await repository
|
||||||
.QueryAsync (
|
.QueryAsync (
|
||||||
|
predicate: null,
|
||||||
|
orderBuilder: null,
|
||||||
|
includeBuilder: null,
|
||||||
query: context.GetQueryArgument (),
|
query: context.GetQueryArgument (),
|
||||||
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
)
|
)
|
||||||
@@ -144,9 +145,14 @@ namespace xDataService.GraphQL {
|
|||||||
// Count ...
|
// Count ...
|
||||||
FieldAsync<IntGraphType> (
|
FieldAsync<IntGraphType> (
|
||||||
name: helper.GetCountName (),
|
name: helper.GetCountName (),
|
||||||
|
arguments: new QueryArguments (
|
||||||
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
|
),
|
||||||
resolve: async context =>
|
resolve: async context =>
|
||||||
await repository
|
await repository
|
||||||
.CountAsync ()
|
.CountAsync (
|
||||||
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -154,11 +160,13 @@ namespace xDataService.GraphQL {
|
|||||||
FieldAsync<BooleanGraphType> (
|
FieldAsync<BooleanGraphType> (
|
||||||
name: helper.GetExistsName (),
|
name: helper.GetExistsName (),
|
||||||
arguments: new QueryArguments (
|
arguments: new QueryArguments (
|
||||||
XGraphQLHelper.GetIdArgument<TGraphKey> ()
|
XGraphQLHelper.GetIdArgument<TGraphKey> (),
|
||||||
|
XGraphQLHelper.IgnoreSoftDeletedArgument
|
||||||
),
|
),
|
||||||
resolve : async context =>
|
resolve : async context =>
|
||||||
await repository.IsExistsAsync (
|
await repository.IsExistsAsync (
|
||||||
context.GetIdArgument<TKey> ()
|
id: context.GetIdArgument<TKey> (),
|
||||||
|
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -18,12 +18,6 @@ namespace xDataService.Constants {
|
|||||||
Description = "determines result should ignore soft deleted items or not ..."
|
Description = "determines result should ignore soft deleted items or not ..."
|
||||||
};
|
};
|
||||||
|
|
||||||
public static QueryArgument<BooleanGraphType> ContainsDetailArgument = new QueryArgument<BooleanGraphType> {
|
|
||||||
Name = "containsDetail",
|
|
||||||
DefaultValue = false,
|
|
||||||
Description = "determines result should contains navigation properties or not ..."
|
|
||||||
};
|
|
||||||
|
|
||||||
public static QueryArgument<StringGraphType> SearchQueryArgument = new QueryArgument<StringGraphType> {
|
public static QueryArgument<StringGraphType> SearchQueryArgument = new QueryArgument<StringGraphType> {
|
||||||
Name = "searchQuery",
|
Name = "searchQuery",
|
||||||
Description = "the value which had to looking for ..."
|
Description = "the value which had to looking for ..."
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+246
-153
@@ -2,18 +2,23 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
|
|
||||||
namespace xDataService.Interfaces {
|
namespace xDataService.Interfaces
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a Base Repository Interface for Manipulate
|
/// Base Repository Pattern Contracts in XDashboard's Data Service ...
|
||||||
/// an Entity in DataBase
|
/// use for Data Manipulation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
public interface IXBaseRepository<T, TKey> : IDisposable
|
public interface IXBaseRepository<T, TKey> : IDisposable
|
||||||
where T : XBaseEntity<TKey> {
|
where T : XBaseEntity<TKey>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
#region Add ...
|
#region Add ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -21,10 +26,12 @@ namespace xDataService.Interfaces {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="saveChanges"></param>
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<T> AddAsync (
|
Task<T> AddAsync(
|
||||||
T item,
|
T item,
|
||||||
bool saveChanges = true
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,10 +39,12 @@ namespace xDataService.Interfaces {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="saveChanges"></param>
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<T> AddOrUpdateAsync (
|
Task<T> AddOrUpdateAsync(
|
||||||
T item,
|
T item,
|
||||||
bool saveChanges = true
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,135 +52,12 @@ namespace xDataService.Interfaces {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
/// <param name="saveChanges"></param>
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task AddRangeAsync (
|
Task AddRangeAsync(
|
||||||
IEnumerable<T> items,
|
IEnumerable<T> items,
|
||||||
bool saveChanges = true
|
bool saveChanges = true,
|
||||||
);
|
CancellationToken cancellationToken = default
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Remove ...
|
|
||||||
/// <summary>
|
|
||||||
/// remove an Entity by it's Id ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="softDelete"></param>
|
|
||||||
/// <param name="saveChanges"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<T> RemoveAsync (
|
|
||||||
TKey id,
|
|
||||||
bool softDelete = true,
|
|
||||||
bool saveChanges = true
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// remove an Entity ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="softDelete"></param>
|
|
||||||
/// <param name="saveChanges"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<T> RemoveAsync (
|
|
||||||
T item,
|
|
||||||
bool softDelete = true,
|
|
||||||
bool saveChanges = true
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// remove a range of exists Entities ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items"></param>
|
|
||||||
/// <param name="softDelete"></param>
|
|
||||||
/// <param name="saveChanges"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task RemoveRangeAsync (
|
|
||||||
IEnumerable<T> items,
|
|
||||||
bool softDelete = true,
|
|
||||||
bool saveChanges = true
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Retrieve ...
|
|
||||||
/// <summary>
|
|
||||||
/// retrieve whole items as queryable ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
IQueryable<T> AsQueryable ();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// retrieve an Entity by it's Id ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="containsDetail"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<T> GetAsync (
|
|
||||||
TKey id,
|
|
||||||
bool ignoreSoftDeleteds = true,
|
|
||||||
bool containsDetail = false
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// retrieve all exists Entities ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="containsDetail"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<T>> GetAllAsync (
|
|
||||||
bool ignoreSoftDeleteds = true,
|
|
||||||
bool containsDetail = false
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// find an Entity by providing a Conditional Expression ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="whereClause"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="containsDetail"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<T> FindOneAsync (
|
|
||||||
Expression<Func<T, bool>> whereClause,
|
|
||||||
bool ignoreSoftDeleteds = true,
|
|
||||||
bool containsDetail = false
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// find a collection of Entities by proving a Conditional Expression ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="whereClause"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="containsDetail"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<T>> FindManyAsync (
|
|
||||||
Expression<Func<T, bool>> whereClause,
|
|
||||||
bool ignoreSoftDeleteds = true,
|
|
||||||
bool containsDetail = false
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// retrieve Entities based on XQuery Pagination structure ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XQueryResult<T>> QueryAsync (
|
|
||||||
XQuery query,
|
|
||||||
bool ignoreSoftDeleteds = true
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="whereClause"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XQueryResult<T>> ConditionalQueryAsync (
|
|
||||||
Expression<Func<T, bool>> whereClause,
|
|
||||||
XQuery query,
|
|
||||||
bool ignoreSoftDeleteds = true
|
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -183,11 +69,13 @@ namespace xDataService.Interfaces {
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="saveChanges"></param>
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<T> UpdateAsync (
|
Task<T> UpdateAsync(
|
||||||
TKey id,
|
TKey id,
|
||||||
T item,
|
T item,
|
||||||
bool saveChanges = true
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -195,10 +83,60 @@ namespace xDataService.Interfaces {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
/// <param name="saveChanges"></param>
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> UpdateRangeAsync (
|
Task<bool> UpdateRangeAsync(
|
||||||
IEnumerable<T> items,
|
IEnumerable<T> items,
|
||||||
bool saveChanges = true
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<T> RemoveAsync(
|
||||||
|
TKey id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<T> RemoveAsync(
|
||||||
|
T item,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove a range of exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RemoveRangeAsync(
|
||||||
|
IEnumerable<T> items,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -208,18 +146,139 @@ namespace xDataService.Interfaces {
|
|||||||
/// count all exists Entities ...
|
/// count all exists Entities ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> CountAsync (bool ignoreSoftDeleteds = true);
|
Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// count all exists Entities Pages by providing page size ...
|
/// count all exists Entities Pages by providing page size ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pageSize"></param>
|
/// <param name="pageSize"></param>
|
||||||
/// <param name="totalItems"></param>
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> PagesCountAsync (
|
Task<int> PagesCountAsync(
|
||||||
int pageSize,
|
int pageSize,
|
||||||
int? totalItems = null
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Retrieve ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve whole items as queryable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asNoTracking">a flag for Tracking behaviour</param>
|
||||||
|
/// <param name="predicate">an Expression for Filter Items ...</param>
|
||||||
|
/// <param name="orderBuilder">an Order Builder expression for Ordering Query ...</param>
|
||||||
|
/// <param name="includeBuilder">an Include Builder expression for Including Navigation Properties ...</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IQueryable<T> AsQueryable(
|
||||||
|
bool asNoTracking = true,
|
||||||
|
Expression<Func<T, bool>> predicate = null,
|
||||||
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBuilder = null,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<T> GetAsync(
|
||||||
|
TKey id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<T>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBuilder = null,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Entities
|
||||||
|
/// as Async Enumerable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IAsyncEnumerable<T> GetAllAsAsyncEnumerable(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBuilder = null,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Entity by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<T> FindOneAsync(
|
||||||
|
Expression<Func<T, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Entities by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<T>> FindManyAsync(
|
||||||
|
Expression<Func<T, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBuilder = null,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<T>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<T, bool>> predicate = null,
|
||||||
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBuilder = null,
|
||||||
|
Func<IQueryable<T>, IIncludableQueryable<T, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -230,10 +289,12 @@ namespace xDataService.Interfaces {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> IsExistsAsync (
|
Task<bool> IsExistsAsync(
|
||||||
TKey id,
|
TKey id,
|
||||||
bool ignoreSoftDeleteds = true
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -243,31 +304,63 @@ namespace xDataService.Interfaces {
|
|||||||
/// Save all unsaved Transactions on DbContext ...
|
/// Save all unsaved Transactions on DbContext ...
|
||||||
/// used fo Unit Of Works Design Pattern ...
|
/// used fo Unit Of Works Design Pattern ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> SaveChangesAsync ();
|
Task<int> SaveChangesAsync(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Key ...
|
#region Key ...
|
||||||
TKey GetKey (T item);
|
/// <summary>
|
||||||
|
/// Retrieve Key of Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
TKey GetKey(T item);
|
||||||
|
|
||||||
void SetKey (
|
/// <summary>
|
||||||
|
/// Set Key of Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
void SetKey(
|
||||||
ref T item,
|
ref T item,
|
||||||
TKey id
|
TKey id
|
||||||
);
|
);
|
||||||
|
|
||||||
Task<T> HandleKeyAsync (T item);
|
/// <summary>
|
||||||
|
/// Handle Checking Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<T> HandleKeyAsync(
|
||||||
|
T item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Detach ...
|
#region Detach ...
|
||||||
void Detach (T item);
|
/// <summary>
|
||||||
|
/// Detach an Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
void Detach(T item);
|
||||||
|
|
||||||
void Detach (IEnumerable<T> items);
|
/// <summary>
|
||||||
|
/// Detach an Enumerable of Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
void Detach(IEnumerable<T> items);
|
||||||
|
|
||||||
void Detach (XQueryResult<T> query);
|
/// <summary>
|
||||||
|
/// Detach a Query Result of Entity ...
|
||||||
void Detach (XPageResponse<T> page);
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
void Detach(XQueryResult<T> query);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using xModels.Base;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
|
namespace xDataService.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Interface for Manipulating Data Using Services based on Dto Mapping ...
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TDto"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
public interface IXBaseRepositoryService<TEntity, TDto, TKey> : IDisposable
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TDto : XBaseEntityDto<TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Properties ...
|
||||||
|
/// <summary>
|
||||||
|
/// Mapper Instance ...
|
||||||
|
/// </summary>
|
||||||
|
IMapper Mapper { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Repository Implementation for Data Manipulations ...
|
||||||
|
/// </summary>
|
||||||
|
IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mapping Profile Configuration ...
|
||||||
|
///
|
||||||
|
/// this Configuration used for Mapping TEntity to Dto and reverse ...
|
||||||
|
/// default mapping prepared on Constructing time, other custom maps
|
||||||
|
/// must handled manually if required ...
|
||||||
|
/// </summary>
|
||||||
|
MapperConfiguration MapperConfiguration { get; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
|
//
|
||||||
|
#region Add ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Dto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> AddAsync(
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// add or update a Dto (add if not exists/update if exists) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> AddOrUpdateAsync(
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// add a range of new Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task AddRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Update ...
|
||||||
|
/// <summary>
|
||||||
|
/// Update an Dto values ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> UpdateAsync(
|
||||||
|
TKey id,
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a range of Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> UpdateRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Dto by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> RemoveAsync(
|
||||||
|
TKey id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Dto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> RemoveAsync(
|
||||||
|
TDto item,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove a range of exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RemoveRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Count ...
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities Pages by providing page size ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageSize"></param>
|
||||||
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> PagesCountAsync(
|
||||||
|
int pageSize,
|
||||||
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Retrieve ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Dto by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> GetAsync(
|
||||||
|
TKey id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<TDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Dto by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TDto> FindOneAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<TDto>> FindManyAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<TDto>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<TEntity, bool>> predicate = null,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Exists ...
|
||||||
|
/// <summary>
|
||||||
|
/// Check a Dto exists or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsExistsAsync(
|
||||||
|
TKey id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using xModels.Base;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
|
namespace xDataService.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Interface for Base Repository Actions Providing Using Controllers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TDto"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
public interface IXEntityControllerActions<TEntity, TKey>
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> DefaultOrderBuilder { get; }
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> DefaultIncludeBuilder { get; }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Add ...
|
||||||
|
Task<ActionResult<TEntity>> Add(
|
||||||
|
TEntity item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<TEntity>> AddOrUpdate(
|
||||||
|
TEntity item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult> AddMany(
|
||||||
|
XBaseRangeRequest<TEntity> request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Retrieve ...
|
||||||
|
Task<ActionResult<TEntity>> Get(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<IEnumerable<TEntity>>> GetAll(
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<TEntity>> FindOne(
|
||||||
|
[FromRoute] string query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<IEnumerable<TEntity>>> FindMany(
|
||||||
|
[FromRoute] string query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<XQueryResult<TEntity>>> Query(
|
||||||
|
[FromQuery] XQuery query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Update ...
|
||||||
|
Task<ActionResult<TEntity>> Update(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromBody] TEntity item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<bool>> UpdateMany(
|
||||||
|
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Exists ...
|
||||||
|
Task<ActionResult<bool>> IsExists(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool ignoreSoftDeletedss = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Remove ...
|
||||||
|
Task<ActionResult<TEntity>> Remove(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool softDelete = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult> RemoveMany(
|
||||||
|
[FromBody] XBaseRangeRequest<TEntity> request,
|
||||||
|
[FromQuery] bool softDelete = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using xModels.Base;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
|
namespace xDataService.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Interface for Base RepositoryService Actions Providing Using Controllers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TDto"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
public interface IXEntityDtoControllerActions<TEntity, TDto, TKey>
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TDto : XBaseEntityDto<TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
IXBaseRepositoryService<TEntity, TDto, TKey> RepositoryService { get; }
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> DefaultOrderBuilder { get; }
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> DefaultIncludeBuilder { get; }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Add ...
|
||||||
|
Task<ActionResult<TDto>> Add(
|
||||||
|
TDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<TDto>> AddOrUpdate(
|
||||||
|
TDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult> AddMany(
|
||||||
|
XBaseRangeRequest<TDto> request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Retrieve ...
|
||||||
|
Task<ActionResult<TDto>> Get(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<IEnumerable<TDto>>> GetAll(
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<TDto>> FindOne(
|
||||||
|
[FromRoute] string query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<IEnumerable<TDto>>> FindMany(
|
||||||
|
[FromRoute] string query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<XQueryResult<TDto>>> Query(
|
||||||
|
[FromQuery] XQuery query,
|
||||||
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||||
|
[FromQuery] bool useDefaultOrders = false,
|
||||||
|
[FromQuery] bool useDefaultIncludes = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Update ...
|
||||||
|
Task<ActionResult<TDto>> Update(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromBody] TDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult<bool>> UpdateMany(
|
||||||
|
[FromBody] XBaseRangeRequest<TDto> request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Exists ...
|
||||||
|
Task<ActionResult<bool>> IsExists(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool ignoreSoftDeletedss = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Remove ...
|
||||||
|
Task<ActionResult<TDto>> Remove(
|
||||||
|
[FromRoute] TKey id,
|
||||||
|
[FromQuery] bool softDelete = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<ActionResult> RemoveMany(
|
||||||
|
[FromBody] XBaseRangeRequest<TDto> request,
|
||||||
|
[FromQuery] bool softDelete = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
|
|
||||||
@@ -6,7 +7,8 @@ namespace xDataService.Interfaces {
|
|||||||
where TEntity : XBaseEntity<TKey> {
|
where TEntity : XBaseEntity<TKey> {
|
||||||
bool IsEmpty (TKey id);
|
bool IsEmpty (TKey id);
|
||||||
Task<TKey> GenerateKey (
|
Task<TKey> GenerateKey (
|
||||||
IXBaseRepository<TEntity, TKey> repository
|
IXBaseRepository<TEntity, TKey> repository,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using xDataService.Db;
|
using xDataService.Db;
|
||||||
@@ -15,6 +16,8 @@ namespace xDataService.Interfaces {
|
|||||||
TDbContext DbContext { get; }
|
TDbContext DbContext { get; }
|
||||||
DbSet<T> GetDbSet<T, TKey> () where T : XBaseEntity<TKey>;
|
DbSet<T> GetDbSet<T, TKey> () where T : XBaseEntity<TKey>;
|
||||||
int SaveChanges ();
|
int SaveChanges ();
|
||||||
Task<int> SaveChangesAsync ();
|
Task<int> SaveChangesAsync (
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1104
-1046
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,745 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xModels.Base;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
|
namespace xDataService.Providers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// a Base Repository Service Implementation which Use a Repository Patterns Implementatin
|
||||||
|
/// and provides Data Manipulation Methods using Dtos instead of Entities ...
|
||||||
|
///
|
||||||
|
/// it can be use of following Repository Patterns Implementation:
|
||||||
|
/// <see cref="XBaseEFRepository"/>>
|
||||||
|
/// <see cref="XBaseMongoRepository"/>>
|
||||||
|
/// <see cref="XBaseInMemoryRepository"/>>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TDto"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
public abstract class XBaseRepositoryService<TEntity, TDto, TKey> : IXBaseRepositoryService<TEntity, TDto, TKey>
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TDto : XBaseEntityDto<TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Properties ...
|
||||||
|
/// <summary>
|
||||||
|
/// Mapper Instance ...
|
||||||
|
/// </summary>
|
||||||
|
public IMapper Mapper { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Repository Implementation for Data Manipulations ...
|
||||||
|
/// </summary>
|
||||||
|
public IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mapping Profile Configuration ...
|
||||||
|
///
|
||||||
|
/// this Configuration used for Mapping TEntity to Dto and reverse ...
|
||||||
|
/// default mapping prepared on Constructing time, other custom maps
|
||||||
|
/// must handled manually if required ...
|
||||||
|
/// </summary>
|
||||||
|
public MapperConfiguration MapperConfiguration { get; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
public XBaseRepositoryService(
|
||||||
|
IXBaseRepository<TEntity, TKey> repository,
|
||||||
|
IEnumerable<Profile> mapperProfiles = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Repository = repository;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Preparing Mapping Configurations ...
|
||||||
|
MapperConfiguration = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Add Default Profiles ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Entity To Dto ...
|
||||||
|
cfg.CreateMap<TEntity, TDto>()
|
||||||
|
.ForMember(dest => dest.Deleted, opt => opt.Ignore());
|
||||||
|
|
||||||
|
//
|
||||||
|
// Dto to Entity ...
|
||||||
|
cfg.CreateMap<TDto, TEntity>()
|
||||||
|
.ForMember(dest => dest.Deleted, opt => opt.Ignore());
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Provided Profiles if Provided ...
|
||||||
|
// if Same Profiles Provided, here resolved ...
|
||||||
|
if (!mapperProfiles.IsNull() &&
|
||||||
|
mapperProfiles.HasChild())
|
||||||
|
{
|
||||||
|
cfg.AddProfiles(mapperProfiles);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// Make Mapper Instance using prepared Configuration ...
|
||||||
|
Mapper = MapperConfiguration.CreateMapper();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
|
//
|
||||||
|
#region Add ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Dto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> AddAsync(
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
bool isValid = !item.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = Mapper.Map<TEntity>(item);
|
||||||
|
|
||||||
|
//
|
||||||
|
entity = await Repository.AddAsync(
|
||||||
|
item: entity,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// add or update a Dto (add if not exists/update if exists) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> AddOrUpdateAsync(
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
bool isValid = !item.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = Mapper.Map<TEntity>(item);
|
||||||
|
|
||||||
|
//
|
||||||
|
entity = await Repository.AddOrUpdateAsync(
|
||||||
|
item: entity,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// add a range of new Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task AddRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
bool isValid =
|
||||||
|
!items.IsNull() &&
|
||||||
|
items.HasChild();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entities = Mapper.Map<IEnumerable<TEntity>>(items);
|
||||||
|
|
||||||
|
//
|
||||||
|
await Repository.AddRangeAsync(
|
||||||
|
items: entities,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Update ...
|
||||||
|
/// <summary>
|
||||||
|
/// Update an Dto values ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> UpdateAsync(
|
||||||
|
TKey id,
|
||||||
|
TDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = Mapper.Map<TEntity>(item);
|
||||||
|
|
||||||
|
//
|
||||||
|
entity = await Repository.UpdateAsync(
|
||||||
|
id: item.Id,
|
||||||
|
item: entity,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a range of Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> UpdateRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var result =
|
||||||
|
!items.IsNull() &&
|
||||||
|
items.HasChild();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entitis = Mapper.Map<IEnumerable<TEntity>>(items);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = await Repository.UpdateRangeAsync(
|
||||||
|
items: entitis,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Dto by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> RemoveAsync(
|
||||||
|
TKey id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = await Repository.RemoveAsync(
|
||||||
|
id: id,
|
||||||
|
softDelete: softDelete,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Dto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> RemoveAsync(
|
||||||
|
TDto item,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = Mapper.Map<TEntity>(item);
|
||||||
|
|
||||||
|
//
|
||||||
|
entity = await Repository.RemoveAsync(
|
||||||
|
item: entity,
|
||||||
|
softDelete: softDelete,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove a range of exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task RemoveRangeAsync(
|
||||||
|
IEnumerable<TDto> items,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!items.IsNull() &&
|
||||||
|
items.HasChild();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var entities = Mapper.Map<IEnumerable<TEntity>>(items);
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await Repository.RemoveRangeAsync(
|
||||||
|
items: entities,
|
||||||
|
softDelete: softDelete,
|
||||||
|
saveChanges: saveChanges,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Count ...
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await Repository.CountAsync(
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities Pages by providing page size ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageSize"></param>
|
||||||
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<int> PagesCountAsync(
|
||||||
|
int pageSize,
|
||||||
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await Repository.PagesCountAsync(
|
||||||
|
pageSize: pageSize,
|
||||||
|
totalItems: totalItems,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Exists ...
|
||||||
|
/// <summary>
|
||||||
|
/// Check a Dto exists or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> IsExistsAsync(
|
||||||
|
TKey id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await Repository.IsExistsAsync(
|
||||||
|
id: id,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Retrieve ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Dto by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> GetAsync(
|
||||||
|
TKey id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = await Repository.GetAsync(
|
||||||
|
id: id,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Dtos ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<TDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
IEnumerable<TDto> result = Enumerable.Empty<TDto>();
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entities = await Repository.GetAllAsync(
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<IEnumerable<TDto>>(entities);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Dto by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TDto> FindOneAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TDto result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entity = await Repository.FindOneAsync(
|
||||||
|
predicate: predicate,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<TDto>(entity);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<TDto>> FindManyAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
IEnumerable<TDto> result = Enumerable.Empty<TDto>();
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entities = await Repository.FindManyAsync(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<IEnumerable<TDto>>(entities);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<TDto>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<TEntity, bool>> predicate = null,
|
||||||
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
|
||||||
|
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XQueryResult<TDto> result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entityResult = await Repository.QueryAsync(
|
||||||
|
query: query,
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Mapper.Map<XQueryResult<TDto>>(entityResult);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public virtual void Dispose()
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
|
|
||||||
namespace xDataService.Providers {
|
namespace xDataService.Providers
|
||||||
|
{
|
||||||
public class XGuidKeyGenerator<TEntity> : IXKeyGenerator<TEntity, Guid>
|
public class XGuidKeyGenerator<TEntity> : IXKeyGenerator<TEntity, Guid>
|
||||||
where TEntity : XBaseEntity<Guid> {
|
where TEntity : XBaseEntity<Guid>
|
||||||
private readonly IXSequentialGuid sequentialGuid;
|
{
|
||||||
|
private readonly IXSequentialGuid sequentialGuid;
|
||||||
|
|
||||||
public XGuidKeyGenerator (
|
public XGuidKeyGenerator(
|
||||||
IXSequentialGuid sequentialGuid = null
|
IXSequentialGuid sequentialGuid = null
|
||||||
) {
|
)
|
||||||
this.sequentialGuid = sequentialGuid;
|
{
|
||||||
}
|
this.sequentialGuid = sequentialGuid;
|
||||||
|
}
|
||||||
public async Task<Guid> GenerateKey (
|
|
||||||
IXBaseRepository<TEntity, Guid> repository
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
await Task.CompletedTask;
|
|
||||||
|
|
||||||
|
public async Task<Guid> GenerateKey(
|
||||||
|
IXBaseRepository<TEntity, Guid> repository,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
return await Task.Run(() =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Check if provided SequentialGuid ...
|
// Check if provided SequentialGuid ...
|
||||||
if (sequentialGuid.IsNull ()) {
|
if (sequentialGuid.IsNull())
|
||||||
return Guid.NewGuid ();
|
{
|
||||||
} else {
|
return Guid.NewGuid();
|
||||||
return sequentialGuid.Next ();
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
public bool IsEmpty (Guid id) {
|
return sequentialGuid.Next();
|
||||||
//
|
}
|
||||||
var result = id.IsNull () || id.IsDefaultGuid ();
|
}, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty(Guid id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = id.IsNull() || id.IsDefaultGuid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,41 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xDataService.Extensions;
|
using xDataService.Extensions;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
|
|
||||||
namespace xDataService.Providers {
|
namespace xDataService.Providers
|
||||||
|
{
|
||||||
public class XIntKeyGenerator<TEntity> : IXKeyGenerator<TEntity, int>
|
public class XIntKeyGenerator<TEntity> : IXKeyGenerator<TEntity, int>
|
||||||
where TEntity : XBaseEntity<int> {
|
where TEntity : XBaseEntity<int>
|
||||||
public async Task<int> GenerateKey (IXBaseRepository<TEntity, int> repository) {
|
{
|
||||||
//
|
public async Task<int> GenerateKey(
|
||||||
var items = (await repository.GetAllAsync ())
|
IXBaseRepository<TEntity, int> repository,
|
||||||
.OrderByDescending (nameof (XBaseEntity<int>.Id));
|
CancellationToken cancellationToken = default
|
||||||
var last = items
|
)
|
||||||
.FirstOrDefault ();
|
{
|
||||||
|
//
|
||||||
|
var items = (await repository.GetAllAsync())
|
||||||
|
.OrderByDescending(nameof(XBaseEntity<int>.Id));
|
||||||
|
var last = items
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = last.IsNull () ? 1 : last.Id + 1;
|
var result = last.IsNull() ? 1 : last.Id + 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEmpty (int id) {
|
|
||||||
//
|
|
||||||
var result = id <= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty(int id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = id <= 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
|
|
||||||
namespace xDataService.Helpers {
|
namespace xDataService.Helpers
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// this service provide Sequential GUID mechanism for Entity Ids ...
|
/// this service provide Sequential GUID mechanism for Entity Ids ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class XSequentialGuid : IXSequentialGuid {
|
public class XSequentialGuid : IXSequentialGuid
|
||||||
|
{
|
||||||
private static int[] sqlOrderMap = null;
|
private static int[] sqlOrderMap = null;
|
||||||
private static int[] SQLORDERMAP {
|
private static int[] SQLORDERMAP
|
||||||
get {
|
{
|
||||||
if (sqlOrderMap == null) {
|
get
|
||||||
|
{
|
||||||
|
if (sqlOrderMap == null)
|
||||||
|
{
|
||||||
sqlOrderMap = new int[16] {
|
sqlOrderMap = new int[16] {
|
||||||
3,
|
3,
|
||||||
2,
|
2,
|
||||||
@@ -37,24 +42,29 @@ namespace xDataService.Helpers {
|
|||||||
|
|
||||||
private Guid currentGuid;
|
private Guid currentGuid;
|
||||||
|
|
||||||
public XSequentialGuid () {
|
public XSequentialGuid()
|
||||||
currentGuid = Guid.NewGuid ();
|
{
|
||||||
|
currentGuid = Guid.NewGuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guid GetCurrentGuid () {
|
public Guid GetCurrentGuid()
|
||||||
|
{
|
||||||
return currentGuid;
|
return currentGuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guid Next () {
|
public Guid Next()
|
||||||
byte[] bytes = currentGuid.ToByteArray ();
|
{
|
||||||
for (int mapIndex = 0; mapIndex < 16; mapIndex++) {
|
byte[] bytes = currentGuid.ToByteArray();
|
||||||
|
for (int mapIndex = 0; mapIndex < 16; mapIndex++)
|
||||||
|
{
|
||||||
int bytesIndex = SQLORDERMAP[mapIndex];
|
int bytesIndex = SQLORDERMAP[mapIndex];
|
||||||
bytes[bytesIndex]++;
|
bytes[bytesIndex]++;
|
||||||
if (bytes[bytesIndex] != 0) {
|
if (bytes[bytesIndex] != 0)
|
||||||
|
{
|
||||||
break; // No need to increment more significant bytes
|
break; // No need to increment more significant bytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentGuid = new Guid (bytes);
|
currentGuid = new Guid(bytes);
|
||||||
return currentGuid;
|
return currentGuid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,43 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xDataService.Interfaces;
|
using xDataService.Interfaces;
|
||||||
using xModels.Base;
|
using xModels.Base;
|
||||||
|
|
||||||
namespace xDataService.Providers {
|
namespace xDataService.Providers
|
||||||
public class XStringKeyGenerator : IXKeyGenerator<XBaseEntity<string>, string> {
|
{
|
||||||
|
public class XStringKeyGenerator : IXKeyGenerator<XBaseEntity<string>, string>
|
||||||
|
{
|
||||||
private readonly IXSequentialGuid sequentialGuid;
|
private readonly IXSequentialGuid sequentialGuid;
|
||||||
|
|
||||||
public XStringKeyGenerator (IXSequentialGuid sequentialGuid = null) {
|
public XStringKeyGenerator(IXSequentialGuid sequentialGuid = null)
|
||||||
|
{
|
||||||
this.sequentialGuid = sequentialGuid;
|
this.sequentialGuid = sequentialGuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GenerateKey (IXBaseRepository<XBaseEntity<string>, string> repository) {
|
public async Task<string> GenerateKey(
|
||||||
|
IXBaseRepository<XBaseEntity<string>, string> repository,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
|
|
||||||
//
|
//
|
||||||
if (sequentialGuid.IsNull ()) {
|
if (sequentialGuid.IsNull())
|
||||||
return Guid.NewGuid ().ToString ();
|
{
|
||||||
} else {
|
return Guid.NewGuid().ToString();
|
||||||
return sequentialGuid.Next ().ToString ();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sequentialGuid.Next().ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEmpty (string id) {
|
public bool IsEmpty(string id)
|
||||||
return id.IsNullOrEmpty ();
|
{
|
||||||
|
return id.IsNullOrEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
<!-- Local Dependencies -->
|
<!-- Local Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- <ProjectReference Include="../xModels/xModels.csproj" /> -->
|
<ProjectReference Include="../xModels/xModels.csproj" />
|
||||||
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
|
<!-- <PackageReference Include="xDashboard.xModels" Version="1.0.0" /> -->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
|
|||||||
Reference in New Issue
Block a user