initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.Infrastructure.AutoNumberGenerator;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
public static class AppDbContextExtensions
|
||||
{
|
||||
public static async Task<string> GenerateAutoNumberAsync(
|
||||
this AppDbContext context,
|
||||
string entityName,
|
||||
string prefixTemplate,
|
||||
string? suffixTemplate = null,
|
||||
int paddingLength = 4,
|
||||
bool useYear = true,
|
||||
bool useMonth = false,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var currentUserService = context.GetService<ICurrentUserService>();
|
||||
var tenantId = currentUserService?.TenantId;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tenantId))
|
||||
{
|
||||
throw new InvalidOperationException("TenantId cannot be null or empty for multi-tenant auto-number sequence generation. Ensure the user session context is valid.");
|
||||
}
|
||||
|
||||
var generator = context.GetService<AutoNumberGeneratorService>();
|
||||
|
||||
return await generator.GenerateNextNumberAsync(
|
||||
tenantId,
|
||||
entityName,
|
||||
prefixTemplate,
|
||||
suffixTemplate,
|
||||
paddingLength,
|
||||
useYear,
|
||||
useMonth,
|
||||
ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user