ListForm AppService performans güçlendirmesi

This commit is contained in:
Sedat Öztürk 2026-02-04 21:51:05 +03:00
parent 8014d9df34
commit 1f97581874
3 changed files with 138 additions and 110 deletions

View file

@ -11,6 +11,7 @@ using Microsoft.EntityFrameworkCore;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using static Erp.Platform.PlatformConsts; using static Erp.Platform.PlatformConsts;
namespace Erp.Platform.ListForms; namespace Erp.Platform.ListForms;
@ -46,42 +47,35 @@ public class ListFormCustomizationAppService : PlatformAppService
throw new BadHttpRequestException("Type UI veya Grid olmalıdır"); throw new BadHttpRequestException("Type UI veya Grid olmalıdır");
} }
var query = await repository.GetQueryableAsync(); var queryable = await repository.GetQueryableAsync();
var itemsUser = await query // Tek query ile tüm ilgili kayıtları çek (3 query yerine 1)
.Where(a => var allItems = await AsyncExecuter.ToListAsync(
queryable.Where(a =>
a.ListFormCode == listFormCode && a.ListFormCode == listFormCode &&
a.UserId == CurrentUser.UserName && a.CustomizationType == type &&
a.RoleId == null && (
a.CustomizationType == type) // User customizations
(a.UserId == CurrentUser.UserName && a.RoleId == null) ||
// Role customizations
(a.UserId == null && CurrentUser.Roles.Contains(a.RoleId)) ||
// Global customizations
(a.UserId == null && a.RoleId == null)
)
)
.WhereIf(!filterName.IsNullOrWhiteSpace(), a => a.FilterName == filterName) .WhereIf(!filterName.IsNullOrWhiteSpace(), a => a.FilterName == filterName)
.ToListAsync(); );
var itemsRole = await query
.Where(a =>
a.ListFormCode == listFormCode &&
a.UserId == null &&
CurrentUser.Roles.Contains(a.RoleId) &&
a.CustomizationType == type)
.WhereIf(!filterName.IsNullOrWhiteSpace(), a => a.FilterName == filterName)
.ToListAsync();
var itemsGlobal = await query
.Where(a =>
a.ListFormCode == listFormCode &&
a.UserId == null &&
a.RoleId == null &&
a.CustomizationType == type)
.WhereIf(!filterName.IsNullOrWhiteSpace(), a => a.FilterName == filterName)
.ToListAsync();
var items = new List<ListFormCustomization>(); // Öncelik sırasına göre sırala: User > Role > Global
items.AddRange(itemsUser); var items = allItems
items.AddRange(itemsRole); .OrderByDescending(a => a.UserId != null ? 3 : (a.RoleId != null ? 2 : 1))
items.AddRange(itemsGlobal); .ToList();
return ObjectMapper.Map<List<ListFormCustomization>, List<ListFormCustomizationForUserDto>>(items); return ObjectMapper.Map<List<ListFormCustomization>, List<ListFormCustomizationForUserDto>>(items);
} }
//Bu hem update, hem create yapıyor //Bu hem update, hem create yapıyor
[UnitOfWork]
public async Task<ListFormCustomizationForUserDto> CreateAsync(CreateUpdateListFormCustomizationForUserDto input) public async Task<ListFormCustomizationForUserDto> CreateAsync(CreateUpdateListFormCustomizationForUserDto input)
{ {
await CheckAccessAsync(input.ListFormCode); await CheckAccessAsync(input.ListFormCode);
@ -94,12 +88,15 @@ public class ListFormCustomizationAppService : PlatformAppService
throw new BadHttpRequestException("Filter data boş olamaz"); throw new BadHttpRequestException("Filter data boş olamaz");
} }
var item = await repository.FirstOrDefaultAsync(a => var queryable = await repository.GetQueryableAsync();
a.ListFormCode == input.ListFormCode && var item = await AsyncExecuter.FirstOrDefaultAsync(
a.UserId == CurrentUser.UserName && queryable.Where(a =>
a.RoleId == null && a.ListFormCode == input.ListFormCode &&
a.FilterName == input.FilterName && a.UserId == CurrentUser.UserName &&
a.CustomizationType == input.CustomizationType); a.RoleId == null &&
a.FilterName == input.FilterName &&
a.CustomizationType == input.CustomizationType)
);
if (item == null) if (item == null)
{ {
@ -111,13 +108,13 @@ public class ListFormCustomizationAppService : PlatformAppService
ListFormCode = input.ListFormCode, ListFormCode = input.ListFormCode,
UserId = CurrentUser.UserName UserId = CurrentUser.UserName
}; };
await repository.InsertAsync(item); await repository.InsertAsync(item, autoSave: true);
} }
else else
{ {
item.FilterName = input.FilterName; item.FilterName = input.FilterName;
item.CustomizationData = input.CustomizationData; item.CustomizationData = input.CustomizationData;
await repository.UpdateAsync(item); await repository.UpdateAsync(item, autoSave: true);
} }
return ObjectMapper.Map<ListFormCustomization, ListFormCustomizationForUserDto>(item); return ObjectMapper.Map<ListFormCustomization, ListFormCustomizationForUserDto>(item);
@ -125,11 +122,14 @@ public class ListFormCustomizationAppService : PlatformAppService
public async Task DeleteAsync(Guid id) public async Task DeleteAsync(Guid id)
{ {
var item = await repository.FirstOrDefaultAsync(a => var queryable = await repository.GetQueryableAsync();
a.Id == id && var item = await AsyncExecuter.FirstOrDefaultAsync(
a.UserId == CurrentUser.UserName && queryable.Where(a =>
a.RoleId == null a.Id == id &&
a.UserId == CurrentUser.UserName &&
a.RoleId == null)
); );
if (item == null) if (item == null)
{ {
throw new EntityNotFoundException("Item not found"); throw new EntityNotFoundException("Item not found");
@ -142,8 +142,6 @@ public class ListFormCustomizationAppService : PlatformAppService
await CheckAccessAsync(item.ListFormCode); await CheckAccessAsync(item.ListFormCode);
await repository.DeleteAsync(item); await repository.DeleteAsync(item, autoSave: true);
} }
} }

View file

@ -15,6 +15,7 @@ using Volo.Abp;
using Volo.Abp.Content; using Volo.Abp.Content;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using static Erp.Platform.PlatformConsts; using static Erp.Platform.PlatformConsts;
namespace Erp.Platform.ListForms.ImportManager; namespace Erp.Platform.ListForms.ImportManager;
@ -89,7 +90,8 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
public async Task<ListFormsImportDto> GetAsync(Guid id) public async Task<ListFormsImportDto> GetAsync(Guid id)
{ {
var session = await _importSessionRepository.FirstOrDefaultAsync(a => a.Id == id) var queryable = await _importSessionRepository.GetQueryableAsync();
var session = await AsyncExecuter.FirstOrDefaultAsync(queryable.Where(a => a.Id == id))
?? throw new EntityNotFoundException(typeof(ListFormImport), id); ?? throw new EntityNotFoundException(typeof(ListFormImport), id);
if (!await _authManager.CanAccess(session.ListFormCode, AuthorizationTypeEnum.Import)) if (!await _authManager.CanAccess(session.ListFormCode, AuthorizationTypeEnum.Import))
@ -103,10 +105,14 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
if (!await _authManager.CanAccess(listFormCode, AuthorizationTypeEnum.Import)) if (!await _authManager.CanAccess(listFormCode, AuthorizationTypeEnum.Import))
throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]); throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]);
var sessions = await _importSessionRepository.GetListAsync(x => x.ListFormCode == listFormCode); var queryable = await _importSessionRepository.GetQueryableAsync();
var sessions = await AsyncExecuter.ToListAsync(
queryable
.Where(x => x.ListFormCode == listFormCode)
.OrderByDescending(x => x.CreationTime)
);
var ordered = sessions.OrderByDescending(x => x.CreationTime).ToList(); return ObjectMapper.Map<List<ListFormImport>, List<ListFormsImportDto>>(sessions);
return ObjectMapper.Map<List<ListFormImport>, List<ListFormsImportDto>>(ordered);
} }
@ -116,7 +122,8 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
if (!await _authManager.CanAccess(input.ListFormCode, AuthorizationTypeEnum.Import)) if (!await _authManager.CanAccess(input.ListFormCode, AuthorizationTypeEnum.Import))
throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]); throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]);
var session = await _importSessionRepository.FirstOrDefaultAsync(a => a.Id == id) var queryable = await _importSessionRepository.GetQueryableAsync();
var session = await AsyncExecuter.FirstOrDefaultAsync(queryable.Where(a => a.Id == id))
?? throw new EntityNotFoundException(typeof(ListFormImport), id); ?? throw new EntityNotFoundException(typeof(ListFormImport), id);
if (!string.IsNullOrEmpty(input.Status)) session.Status = input.Status; if (!string.IsNullOrEmpty(input.Status)) session.Status = input.Status;
@ -126,9 +133,11 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
return ObjectMapper.Map<ListFormImport, ListFormsImportDto>(session); return ObjectMapper.Map<ListFormImport, ListFormsImportDto>(session);
} }
[UnitOfWork]
public async Task<ListFormImportExecuteDto> ExecuteAsync([FromBody] ExecuteImportRequest request) public async Task<ListFormImportExecuteDto> ExecuteAsync([FromBody] ExecuteImportRequest request)
{ {
var session = await _importSessionRepository.FirstOrDefaultAsync(a => a.Id == request.SessionId) var queryable = await _importSessionRepository.GetQueryableAsync();
var session = await AsyncExecuter.FirstOrDefaultAsync(queryable.Where(a => a.Id == request.SessionId))
?? throw new UserFriendlyException("Import session not found."); ?? throw new UserFriendlyException("Import session not found.");
// Izin logic process // Izin logic process
@ -159,6 +168,10 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
execute.Progress = 20; execute.Progress = 20;
await _importSessionExecuteRepository.UpdateAsync(execute, autoSave: true); await _importSessionExecuteRepository.UpdateAsync(execute, autoSave: true);
// Batch processing için - daha az update
const int updateInterval = 50; // Her 50 satırda bir update
var lastUpdateIndex = 0;
// Process each row individually // Process each row individually
for (int i = 0; i < request.SelectedRowsData.Count; i++) for (int i = 0; i < request.SelectedRowsData.Count; i++)
{ {
@ -177,17 +190,20 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
// If database insert fails, count as error // If database insert fails, count as error
errorCount++; errorCount++;
// Log the error if needed // Log the error if needed
Logger.LogWarning("Error inserting row {0} during import for session {1}: {2}", i, session.Id, ex.Message); Logger.LogWarning("Error inserting row {RowIndex} during import for session {SessionId}: {ErrorMessage}", i, session.Id, ex.Message);
} }
// Update progress // Update progress - optimizasyon: daha az update
var progressPercentage = 20 + (int)((double)(i + 1) / processedCount * 70); // Progress from 20% to 90% if ((i + 1 - lastUpdateIndex >= updateInterval) || i == processedCount - 1)
execute.Progress = progressPercentage;
// Update progress every 10 rows or on last row to avoid too many database updates
if ((i + 1) % 10 == 0 || i == processedCount - 1)
{ {
await _importSessionExecuteRepository.UpdateAsync(execute, autoSave: true); var progressPercentage = 20 + (int)((double)(i + 1) / processedCount * 70); // Progress from 20% to 90%
execute.Progress = progressPercentage;
execute.ExecRows = i + 1;
execute.ValidRows = validCount;
execute.ErrorRows = errorCount;
await _importSessionExecuteRepository.UpdateAsync(execute, autoSave: false);
lastUpdateIndex = i + 1;
} }
} }
} }
@ -216,22 +232,27 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
public async Task<List<ListFormImportExecuteDto>> GetListExecutesAsync(Guid sessionId) public async Task<List<ListFormImportExecuteDto>> GetListExecutesAsync(Guid sessionId)
{ {
var sessions = await _importSessionExecuteRepository.GetListAsync(x => x.ImportId == sessionId); var queryable = await _importSessionExecuteRepository.GetQueryableAsync();
var sessions = await AsyncExecuter.ToListAsync(
queryable
.Where(x => x.ImportId == sessionId)
.OrderByDescending(x => x.CreationTime)
);
var ordered = sessions.OrderByDescending(x => x.CreationTime).ToList(); return ObjectMapper.Map<List<ListFormImportExecute>, List<ListFormImportExecuteDto>>(sessions);
return ObjectMapper.Map<List<ListFormImportExecute>, List<ListFormImportExecuteDto>>(ordered);
} }
public async Task DeleteAsync(Guid id) public async Task DeleteAsync(Guid id)
{ {
var session = await _importSessionRepository.FirstOrDefaultAsync(a => a.Id == id) var queryable = await _importSessionRepository.GetQueryableAsync();
var session = await AsyncExecuter.FirstOrDefaultAsync(queryable.Where(a => a.Id == id))
?? throw new EntityNotFoundException(typeof(ListFormImport), id); ?? throw new EntityNotFoundException(typeof(ListFormImport), id);
// Izin logic process // Izin logic process
if (!await _authManager.CanAccess(session.ListFormCode, AuthorizationTypeEnum.Import)) if (!await _authManager.CanAccess(session.ListFormCode, AuthorizationTypeEnum.Import))
throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]); throw new Volo.Abp.UserFriendlyException(L[AppErrorCodes.NoAuth]);
await _importSessionRepository.DeleteAsync(id); await _importSessionRepository.DeleteAsync(id, autoSave: true);
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using Erp.Languages.Entities; using Erp.Languages.Entities;
@ -10,7 +11,7 @@ using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement;
using static Erp.Settings.SettingsConsts; using Volo.Abp.Uow;
namespace Erp.Platform.ListForms; namespace Erp.Platform.ListForms;
@ -41,6 +42,7 @@ public class ListFormWizardAppService(
private readonly ILookupNormalizer lookupNormalizer = LookupNormalizer; private readonly ILookupNormalizer lookupNormalizer = LookupNormalizer;
private readonly string cultureNameDefault = PlatformConsts.DefaultLanguage; private readonly string cultureNameDefault = PlatformConsts.DefaultLanguage;
[UnitOfWork]
public async Task Create(WizardCreateInputDto input) public async Task Create(WizardCreateInputDto input)
{ {
var listFormCode = input.ListFormCode; var listFormCode = input.ListFormCode;
@ -48,42 +50,45 @@ public class ListFormWizardAppService(
var titleLangKey = PlatformConsts.Wizard.WizardKeyTitle(listFormCode); var titleLangKey = PlatformConsts.Wizard.WizardKeyTitle(listFormCode);
var code = PlatformConsts.Wizard.WizardKey(listFormCode); var code = PlatformConsts.Wizard.WizardKey(listFormCode);
//Dil //Dil - Language Keys
// Dil Key
// App.Platform.Form-001 => Text EN: ..., Text TR: ...
// App.Platform.Form-001.Title => Text EN: ..., Text TR: ...
await CreateLangKey(nameLangKey, input.LanguageTextMenuEn, input.LanguageTextMenuTr); await CreateLangKey(nameLangKey, input.LanguageTextMenuEn, input.LanguageTextMenuTr);
await CreateLangKey(titleLangKey, input.LanguageTextTitleEn, input.LanguageTextTitleTr); await CreateLangKey(titleLangKey, input.LanguageTextTitleEn, input.LanguageTextTitleTr);
await CreateLangKey(PlatformConsts.Wizard.WizardKeyDesc(listFormCode), input.LanguageTextDescEn, input.LanguageTextDescTr); await CreateLangKey(PlatformConsts.Wizard.WizardKeyDesc(listFormCode), input.LanguageTextDescEn, input.LanguageTextDescTr);
//Permission //Permission Group
// Group Name => Platform
// App.Platform.Form-001 => LanguageKey: App.Platform.Form-001.Menu, Parent Name: Ø
// App.Platform.Form-001.Create => LanguageKey: App.Create, Parent Name: App.Platform.Form-001
// App.Platform.Form-001.Update => LanguageKey: App.Update, Parent Name: App.Platform.Form-001
// App.Platform.Form-001.Delete => LanguageKey: App.Delete, Parent Name: App.Platform.Form-001
// Dil
// Dil Key
var groupName = input.PermissionGroupName ?? PlatformConsts.AppName; var groupName = input.PermissionGroupName ?? PlatformConsts.AppName;
if (!await repoPermGroup.AnyAsync(a => a.Name == groupName)) if (!await repoPermGroup.AnyAsync(a => a.Name == groupName))
{ {
await repoPermGroup.InsertAsync(new PermissionGroupDefinitionRecord(GuidGenerator.Create(), groupName, groupName)); await repoPermGroup.InsertAsync(new PermissionGroupDefinitionRecord(GuidGenerator.Create(), groupName, groupName), autoSave: false);
await CreateLangKey(groupName, groupName, groupName); await CreateLangKey(groupName, groupName, groupName);
} }
var permRead = await repoPerm.FirstOrDefaultAsync(a => a.GroupName == groupName && a.Name == code) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, code, null, nameLangKey, true, MultiTenancySides.Both));
var permCreate = await repoPerm.FirstOrDefaultAsync(a => a.GroupName == groupName && a.Name == PlatformConsts.Wizard.PermCreate(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermCreate(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyCreate, true, MultiTenancySides.Both));
var permUpdate = await repoPerm.FirstOrDefaultAsync(a => a.GroupName == groupName && a.Name == PlatformConsts.Wizard.PermUpdate(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermUpdate(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyUpdate, true, MultiTenancySides.Both));
var permDelete = await repoPerm.FirstOrDefaultAsync(a => a.GroupName == groupName && a.Name == PlatformConsts.Wizard.PermDelete(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermDelete(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyDelete, true, MultiTenancySides.Both));
var permExport = await repoPerm.FirstOrDefaultAsync(a => a.GroupName == groupName && a.Name == PlatformConsts.Wizard.PermExport(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermExport(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyExport, true, MultiTenancySides.Both));
// Permission'ları tek seferde kontrol et ve oluştur
var queryable = await repoPerm.GetQueryableAsync();
var existingPerms = await AsyncExecuter.ToListAsync(
queryable.Where(a => a.GroupName == groupName)
);
var permRead = existingPerms.FirstOrDefault(a => a.Name == code) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, code, null, nameLangKey, true, MultiTenancySides.Both), autoSave: false);
var permCreate = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermCreate(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermCreate(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyCreate, true, MultiTenancySides.Both), autoSave: false);
var permUpdate = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermUpdate(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermUpdate(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyUpdate, true, MultiTenancySides.Both), autoSave: false);
var permDelete = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermDelete(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermDelete(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyDelete, true, MultiTenancySides.Both), autoSave: false);
var permExport = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermExport(listFormCode)) ??
await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermExport(listFormCode), permRead.Name, PlatformConsts.Wizard.LangKeyExport, true, MultiTenancySides.Both), autoSave: false);
// Permission Grants - Bulk Insert
var adminUserName = PlatformConsts.AbpIdentity.User.AdminEmailDefaultValue; var adminUserName = PlatformConsts.AbpIdentity.User.AdminEmailDefaultValue;
var adminUser = await userRepository.FindByNormalizedUserNameAsync(lookupNormalizer.NormalizeName(adminUserName)); var adminUser = await userRepository.FindByNormalizedUserNameAsync(lookupNormalizer.NormalizeName(adminUserName));
var adminRole = await roleRepository.FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName)); var adminRole = await roleRepository.FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName));
await permissionGrantRepository.InsertManyAsync( await permissionGrantRepository.InsertManyAsync(
[ [
new PermissionGrant(Guid.NewGuid(), permRead.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName), new PermissionGrant(Guid.NewGuid(), permRead.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName),
@ -91,17 +96,11 @@ public class ListFormWizardAppService(
new PermissionGrant(Guid.NewGuid(), permUpdate.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName), new PermissionGrant(Guid.NewGuid(), permUpdate.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName),
new PermissionGrant(Guid.NewGuid(), permDelete.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName), new PermissionGrant(Guid.NewGuid(), permDelete.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName),
new PermissionGrant(Guid.NewGuid(), permExport.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName), new PermissionGrant(Guid.NewGuid(), permExport.Name, "R", PlatformConsts.AbpIdentity.User.AdminRoleName),
]); ], autoSave: false);
//Menu //Menu Parent
// App.Platform.Form-001 => LanguageKey: App.Platform.Form-001.Menu, Permission: App.Platform.Form-001, Parent Name: Platform var menuQueryable = await repoMenu.GetQueryableAsync();
// Permission var menuParent = await AsyncExecuter.FirstOrDefaultAsync(menuQueryable.Where(a => a.Code == input.MenuParentCode));
// Group Name
// Dil
// Dil Key
// Dil
// Dil Key
var menuParent = await repoMenu.FirstOrDefaultAsync(a => a.Code == input.MenuParentCode);
if (menuParent == null) if (menuParent == null)
{ {
await CreateLangKey(PlatformConsts.Wizard.WizardKeyParent(listFormCode), input.LanguageTextMenuParentEn, input.LanguageTextMenuParentTr); await CreateLangKey(PlatformConsts.Wizard.WizardKeyParent(listFormCode), input.LanguageTextMenuParentEn, input.LanguageTextMenuParentTr);
@ -110,9 +109,11 @@ public class ListFormWizardAppService(
Code = input.MenuParentCode, Code = input.MenuParentCode,
DisplayName = PlatformConsts.Wizard.WizardKeyParent(listFormCode), DisplayName = PlatformConsts.Wizard.WizardKeyParent(listFormCode),
IsDisabled = false, IsDisabled = false,
}); }, autoSave: false);
} }
var menu = await repoMenu.FirstOrDefaultAsync(a => a.Code == code) ??
//Menu
var menu = await AsyncExecuter.FirstOrDefaultAsync(menuQueryable.Where(a => a.Code == code)) ??
await repoMenu.InsertAsync(new Menu await repoMenu.InsertAsync(new Menu
{ {
Code = code, Code = code,
@ -125,10 +126,11 @@ public class ListFormWizardAppService(
CssClass = null, CssClass = null,
Url = PlatformConsts.Wizard.MenuUrl(listFormCode), Url = PlatformConsts.Wizard.MenuUrl(listFormCode),
RequiredPermissionName = permRead.Name RequiredPermissionName = permRead.Name
}); }, autoSave: false);
//Data Source //Data Source
var dataSource = repoDataSource.FirstOrDefaultAsync(a => a.Code == input.DataSourceCode); var dataSourceQueryable = await repoDataSource.GetQueryableAsync();
var dataSource = await AsyncExecuter.FirstOrDefaultAsync(dataSourceQueryable.Where(a => a.Code == input.DataSourceCode));
if (dataSource is null) if (dataSource is null)
{ {
await repoDataSource.InsertAsync(new DataSource await repoDataSource.InsertAsync(new DataSource
@ -136,7 +138,7 @@ public class ListFormWizardAppService(
Code = input.DataSourceCode, Code = input.DataSourceCode,
DataSourceType = input.DataSourceConnectionString.IndexOf("Server") >= 0 ? DataSourceTypeEnum.Mssql : DataSourceTypeEnum.Postgresql, DataSourceType = input.DataSourceConnectionString.IndexOf("Server") >= 0 ? DataSourceTypeEnum.Mssql : DataSourceTypeEnum.Postgresql,
ConnectionString = input.DataSourceConnectionString ConnectionString = input.DataSourceConnectionString
}); }, autoSave: false);
} }
//ListForm //ListForm
@ -148,7 +150,7 @@ public class ListFormWizardAppService(
Title = titleLangKey, Title = titleLangKey,
CultureName = PlatformConsts.DefaultLanguage, CultureName = PlatformConsts.DefaultLanguage,
Description = PlatformConsts.Wizard.WizardKeyDesc(listFormCode), Description = PlatformConsts.Wizard.WizardKeyDesc(listFormCode),
SelectCommandType = input.SelectCommandType, //SelectCommandTypeEnum.Table, SelectCommandType = input.SelectCommandType,
SelectCommand = input.SelectCommand, SelectCommand = input.SelectCommand,
KeyFieldName = input.KeyFieldName, KeyFieldName = input.KeyFieldName,
KeyFieldDbSourceType = input.KeyFieldDbSourceType, KeyFieldDbSourceType = input.KeyFieldDbSourceType,
@ -159,21 +161,28 @@ public class ListFormWizardAppService(
U = permUpdate.Name, U = permUpdate.Name,
D = permDelete.Name D = permDelete.Name
}), }),
}); }, autoSave: true);
} }
private async Task<LanguageKey> CreateLangKey(string key, string textEn, string textTr) private async Task<LanguageKey> CreateLangKey(string key, string textEn, string textTr)
{ {
var res = PlatformConsts.AppName; var res = PlatformConsts.AppName;
var langKey = await repoLangKey.FirstOrDefaultAsync(a => a.ResourceName == res && a.Key == key)
?? await repoLangKey.InsertAsync(new LanguageKey { ResourceName = res, Key = key }); var keyQueryable = await repoLangKey.GetQueryableAsync();
var langTextEn = await repoLangText.FirstOrDefaultAsync(a => a.ResourceName == res && a.Key == langKey.Key && a.CultureName == cultureNameDefault) var langKey = await AsyncExecuter.FirstOrDefaultAsync(keyQueryable.Where(a => a.ResourceName == res && a.Key == key))
?? await repoLangText.InsertAsync(new LanguageText { ResourceName = res, Key = langKey.Key, CultureName = cultureNameDefault, Value = textEn }); ?? await repoLangKey.InsertAsync(new LanguageKey { ResourceName = res, Key = key }, autoSave: false);
var langTextTitleTr = await repoLangText.FirstOrDefaultAsync(a => a.ResourceName == res && a.Key == langKey.Key && a.CultureName == LanguageCodes.Tr)
?? await repoLangText.InsertAsync(new LanguageText { ResourceName = res, Key = langKey.Key, CultureName = LanguageCodes.En, Value = textTr }); var textQueryable = await repoLangText.GetQueryableAsync();
var existingTexts = await AsyncExecuter.ToListAsync(
textQueryable.Where(a => a.ResourceName == res && a.Key == langKey.Key)
);
var langTextEn = existingTexts.FirstOrDefault(a => a.CultureName == cultureNameDefault)
?? await repoLangText.InsertAsync(new LanguageText { ResourceName = res, Key = langKey.Key, CultureName = cultureNameDefault, Value = textEn }, autoSave: false);
var langTextTr = existingTexts.FirstOrDefault(a => a.CultureName == LanguageCodes.Tr)
?? await repoLangText.InsertAsync(new LanguageText { ResourceName = res, Key = langKey.Key, CultureName = LanguageCodes.Tr, Value = textTr }, autoSave: false);
return langKey; return langKey;
} }
} }