public class CustomHooks : EntityTypeCustomHooks<Project>
{
public override async Task AfterUpsert(
CustomHooksContext context,
Project contextEntity,
Project detachedEntity
)
{
var billingTypeService = context.GetEntityService<ProjectBillingType>();
var billingType = await billingTypeService
.Get(bt => bt.Id == contextEntity.BillingTypeId)
.FirstOrDefaultAsync();
var projectService = context.GetEntityService<Project>();
var maxRowNumber = await projectService.Get().MaxAsync(p => p.IntegerValue1);
// Создайте дополнительное поле типа "Целое число". В данном случае IntegerValue1. Это индекс номера.
if (context.OperationType == EntityServiceOperation.Insert)
contextEntity.IntegerValue1 = (maxRowNumber ?? 0) + 1;
var billingTypeCode = billingType?.Code?.ToUpper() ?? "NONE";
var rowNumber = contextEntity.IntegerValue1?.ToString("D5") ?? "NONE";
// Шаблон: PR-[BillingType]-[Index]
contextEntity.Code = $"PR-{billingTypeCode}-{rowNumber}";
}
}
Перейти на русскую версию?