last ...
This commit is contained in:
@@ -1,33 +1,41 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Providers {
|
||||
namespace xDataService.Providers
|
||||
{
|
||||
public class XIntKeyGenerator<TEntity> : IXKeyGenerator<TEntity, int>
|
||||
where TEntity : XBaseEntity<int> {
|
||||
public async Task<int> GenerateKey (IXBaseRepository<TEntity, int> repository) {
|
||||
//
|
||||
var items = (await repository.GetAllAsync ())
|
||||
.OrderByDescending (nameof (XBaseEntity<int>.Id));
|
||||
var last = items
|
||||
.FirstOrDefault ();
|
||||
where TEntity : XBaseEntity<int>
|
||||
{
|
||||
public async Task<int> GenerateKey(
|
||||
IXBaseRepository<TEntity, int> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
public bool IsEmpty (int id) {
|
||||
//
|
||||
var result = id <= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool IsEmpty(int id)
|
||||
{
|
||||
//
|
||||
var result = id <= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user