diff --git a/api/src/Sozsoft.Platform.Application/ListForms/ListFormWizardAppService.cs b/api/src/Sozsoft.Platform.Application/ListForms/ListFormWizardAppService.cs index d4f95f1..2a8d126 100644 --- a/api/src/Sozsoft.Platform.Application/ListForms/ListFormWizardAppService.cs +++ b/api/src/Sozsoft.Platform.Application/ListForms/ListFormWizardAppService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Threading.Tasks; @@ -15,6 +14,8 @@ using Volo.Abp.PermissionManagement; using Volo.Abp.Uow; using static Sozsoft.Platform.PlatformConsts; using System.Data; +using Microsoft.Extensions.Configuration; +using Sozsoft.Languages; namespace Sozsoft.Platform.ListForms; @@ -30,7 +31,9 @@ public class ListFormWizardAppService( IIdentityRoleRepository roleRepository, IIdentityUserRepository userRepository, IPermissionGrantRepository permissionGrantRepository, - ILookupNormalizer LookupNormalizer + ILookupNormalizer LookupNormalizer, + IConfiguration configuration, + LanguageTextAppService languageTextAppService ) : PlatformAppService(), IListFormWizardAppService { private readonly IRepository repoListForm = repoListForm; @@ -45,17 +48,21 @@ public class ListFormWizardAppService( private readonly IIdentityUserRepository userRepository = userRepository; private readonly IPermissionGrantRepository permissionGrantRepository = permissionGrantRepository; private readonly ILookupNormalizer lookupNormalizer = LookupNormalizer; + private readonly IConfiguration _configuration = configuration; + private readonly LanguageTextAppService _languageTextAppService = languageTextAppService; private readonly string cultureNameDefault = PlatformConsts.DefaultLanguage; [UnitOfWork] public async Task Create(ListFormWizardDto input) { var wizardName = input.WizardName.Trim(); - var titleLangKey = PlatformConsts.Wizard.WizardKeyTitle(wizardName); - var nameLangKey = PlatformConsts.Wizard.WizardKey(wizardName); - var descLangKey = PlatformConsts.Wizard.WizardKeyDesc(wizardName); + var titleLangKey = WizardConsts.WizardKeyTitle(wizardName); + var nameLangKey = WizardConsts.WizardKey(wizardName); + var descLangKey = WizardConsts.WizardKeyDesc(wizardName); + var code = WizardConsts.WizardKey(wizardName); - var code = PlatformConsts.Wizard.WizardKey(wizardName); + // Clear Redis Cache + await _languageTextAppService.ClearRedisCacheAsync(); //Dil - Language Keys await CreateLangKey(nameLangKey, input.LanguageTextMenuEn, input.LanguageTextMenuTr); @@ -79,23 +86,23 @@ public class ListFormWizardAppService( 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(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermCreate(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyCreate, true, MultiTenancySides.Both), autoSave: false); + var permCreate = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermCreate(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermCreate(wizardName), permRead.Name, WizardConsts.LangKeyCreate, true, MultiTenancySides.Both), autoSave: false); - var permUpdate = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermUpdate(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermUpdate(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyUpdate, true, MultiTenancySides.Both), autoSave: false); + var permUpdate = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermUpdate(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermUpdate(wizardName), permRead.Name, WizardConsts.LangKeyUpdate, true, MultiTenancySides.Both), autoSave: false); - var permDelete = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermDelete(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermDelete(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyDelete, true, MultiTenancySides.Both), autoSave: false); + var permDelete = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermDelete(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermDelete(wizardName), permRead.Name, WizardConsts.LangKeyDelete, true, MultiTenancySides.Both), autoSave: false); - var permExport = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermExport(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermExport(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyExport, true, MultiTenancySides.Both), autoSave: false); + var permExport = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermExport(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermExport(wizardName), permRead.Name, WizardConsts.LangKeyExport, true, MultiTenancySides.Both), autoSave: false); - var permImport = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermImport(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermImport(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyImport, true, MultiTenancySides.Both), autoSave: false); + var permImport = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermImport(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermImport(wizardName), permRead.Name, WizardConsts.LangKeyImport, true, MultiTenancySides.Both), autoSave: false); - var permNote = existingPerms.FirstOrDefault(a => a.Name == PlatformConsts.Wizard.PermNote(wizardName)) ?? - await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, PlatformConsts.Wizard.PermNote(wizardName), permRead.Name, PlatformConsts.Wizard.LangKeyNote, true, MultiTenancySides.Both), autoSave: false); + var permNote = existingPerms.FirstOrDefault(a => a.Name == WizardConsts.PermNote(wizardName)) ?? + await repoPerm.InsertAsync(new PermissionDefinitionRecord(Guid.NewGuid(), groupName, WizardConsts.PermNote(wizardName), permRead.Name, WizardConsts.LangKeyNote, true, MultiTenancySides.Both), autoSave: false); // Permission Grants - Bulk Insert var adminUserName = PlatformConsts.AbpIdentity.User.AdminEmailDefaultValue; @@ -118,11 +125,11 @@ public class ListFormWizardAppService( var menuParent = await AsyncExecuter.FirstOrDefaultAsync(menuQueryable.Where(a => a.Code == input.MenuParentCode)); if (menuParent == null) { - await CreateLangKey(PlatformConsts.Wizard.WizardKeyParent(wizardName), input.LanguageTextMenuParentEn, input.LanguageTextMenuParentTr); + await CreateLangKey(WizardConsts.WizardKeyParent(wizardName), input.LanguageTextMenuParentEn, input.LanguageTextMenuParentTr); menuParent = await repoMenu.InsertAsync(new Menu { Code = input.MenuParentCode, - DisplayName = PlatformConsts.Wizard.WizardKeyParent(wizardName), + DisplayName = WizardConsts.WizardKeyParent(wizardName), IsDisabled = false, }, autoSave: false); } @@ -135,11 +142,11 @@ public class ListFormWizardAppService( DisplayName = nameLangKey, IsDisabled = false, ParentCode = menuParent.Code, - Icon = input.MenuIcon ?? PlatformConsts.Wizard.MenuIcon, + Icon = input.MenuIcon ?? WizardConsts.MenuIcon, Target = null, ElementId = null, CssClass = null, - Url = PlatformConsts.Wizard.MenuUrl(code), + Url = WizardConsts.MenuUrl(code), RequiredPermissionName = permRead.Name }, autoSave: false); @@ -186,10 +193,10 @@ public class ListFormWizardAppService( { ListFormType = ListFormTypeEnum.List, PageSize = 10, - ExportJson = Wizard.DefaultExportJson, + ExportJson = WizardConsts.DefaultExportJson, IsSubForm = false, ShowNote = true, - LayoutJson = Wizard.DefaultLayoutJson(), + LayoutJson = WizardConsts.DefaultLayoutJson(), CultureName = LanguageCodes.En, ListFormCode = input.ListFormCode, Name = nameLangKey, @@ -203,19 +210,20 @@ public class ListFormWizardAppService( SelectCommand = input.SelectCommand, KeyFieldName = input.KeyFieldName, KeyFieldDbSourceType = input.KeyFieldDbSourceType, - DefaultFilter = Wizard.DefaultFilterJson, + DefaultFilter = WizardConsts.DefaultFilterJson, SortMode = GridOptions.SortModeSingle, - FilterRowJson = Wizard.DefaultFilterRowJson, - HeaderFilterJson = Wizard.DefaultHeaderFilterJson, - SearchPanelJson = Wizard.DefaultSearchPanelJson, + FilterRowJson = WizardConsts.DefaultFilterRowJson, + HeaderFilterJson = WizardConsts.DefaultHeaderFilterJson, + SearchPanelJson = WizardConsts.DefaultSearchPanelJson, GroupPanelJson = JsonSerializer.Serialize(new { Visible = false }), - SelectionJson = Wizard.DefaultSelectionSingleJson, - ColumnOptionJson = Wizard.DefaultColumnOptionJson(), - PermissionJson = Wizard.DefaultPermissionJson(code), - DeleteCommand = Wizard.DefaultDeleteCommand(nameof(TableNameEnum.Country)), - DeleteFieldsDefaultValueJson = Wizard.DefaultDeleteFieldsDefaultValueJson(input.KeyFieldDbSourceType), - PagerOptionJson = Wizard.DefaultPagerOptionJson, - EditingOptionJson = Wizard.DefaultEditingOptionJson(titleLangKey, 600, 500, input.AllowDeleting, input.AllowAdding, input.AllowEditing, input.ConfirmDelete, false, input.AllowDetail), + SelectionJson = WizardConsts.DefaultSelectionSingleJson, + ColumnOptionJson = WizardConsts.DefaultColumnOptionJson(), + PermissionJson = WizardConsts.DefaultPermissionJson(code), + DeleteCommand = WizardConsts.DefaultDeleteCommand(input.SelectCommand), + DeleteFieldsDefaultValueJson = WizardConsts.DefaultDeleteFieldsDefaultValueJson(input.KeyFieldDbSourceType), + InsertFieldsDefaultValueJson = WizardConsts.DefaultInsertFieldsDefaultValueJson(input.KeyFieldDbSourceType), + PagerOptionJson = WizardConsts.DefaultPagerOptionJson, + EditingOptionJson = WizardConsts.DefaultEditingOptionJson(titleLangKey, 600, 500, input.AllowDeleting, input.AllowAdding, input.AllowEditing, input.ConfirmDelete, false, input.AllowDetail), EditingFormJson = editingFormDtos.Count > 0 ? JsonSerializer.Serialize(editingFormDtos) : null, }, autoSave: true); diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostDataSeeder.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostDataSeeder.cs index 86fb949..1fe910b 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostDataSeeder.cs +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostDataSeeder.cs @@ -1,10 +1,8 @@ using System; -using System.Globalization; using System.IO; using System.Linq; using System.Text.Json; using System.Threading.Tasks; -using Sozsoft.Languages.Entities; using Sozsoft.Platform.Entities; using Sozsoft.Platform.Enums; using Sozsoft.Settings.Entities; @@ -12,14 +10,11 @@ using Microsoft.Extensions.Configuration; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; -using Volo.Abp.MultiTenancy; -using Volo.Abp.PermissionManagement; using Microsoft.EntityFrameworkCore; using EFCore.BulkExtensions; using System.Collections.Generic; using Sozsoft.Platform.Public; using static Sozsoft.Settings.SettingsConsts; -using Sozsoft.Platform.Extensions; namespace Sozsoft.Platform.Data.Seeds; @@ -104,65 +99,36 @@ public class ContactTitleSeedDto public string Abbreviation { get; set; } } -public class RouteSeedDto -{ - public string Key { get; set; } - public string Path { get; set; } - public string ComponentPath { get; set; } - public string RouteType { get; set; } - public string[] Authority { get; set; } -} - public class HostSeederDto { public List AiBots { get; set; } - public List Languages { get; set; } - public List LanguageTexts { get; set; } - public List LanguageFieldTitles { get; set; } public List DataSources { get; set; } public List Settings { get; set; } public List BackgroundWorkers { get; set; } public List NotificationRules { get; set; } - public List Menus { get; set; } - public List PermissionGroupDefinitionRecords { get; set; } - public List PermissionDefinitionRecords { get; set; } public List Currencies { get; set; } public List ContactTitles { get; set; } - public List Routes { get; set; } } #endregion public class HostDataSeeder : IDataSeedContributor, ITransientDependency { private readonly IRepository _aiBotRepository; - private readonly IRepository _languages; - private readonly IRepository _languageKey; - private readonly IRepository _languagesText; private readonly IRepository _dataSources; private readonly IRepository _settings; private readonly IRepository _backgroundWorkerRepository; - private readonly IRepository _menuRepository; - private readonly IRepository _permissionGroupRepository; - private readonly IRepository _permissionRepository; private readonly IRepository _currencyRepository; private readonly IRepository _countryGroupRepository; private readonly IRepository _countryRepository; private readonly IRepository _cityRepository; private readonly IRepository _districtRepository; private readonly IRepository _contactTitleRepository; - private readonly IRepository _routeRepository; public HostDataSeeder( IRepository aiBotRepository, - IRepository languages, - IRepository languageKey, - IRepository languagesText, IRepository dataSource, IRepository settings, IRepository backgroundWorkerRepository, - IRepository menuRepository, - IRepository permissionGroupRepository, - IRepository permissionRepository, IRepository currencyRepository, IRepository countryGroupRepository, IRepository countryRepository, @@ -172,23 +138,16 @@ public class HostDataSeeder : IDataSeedContributor, ITransientDependency IRepository routeRepository ) { - _languages = languages; - _languageKey = languageKey; - _languagesText = languagesText; + _aiBotRepository = aiBotRepository; _dataSources = dataSource; _settings = settings; _backgroundWorkerRepository = backgroundWorkerRepository; - _menuRepository = menuRepository; - _permissionGroupRepository = permissionGroupRepository; - _permissionRepository = permissionRepository; _currencyRepository = currencyRepository; _countryGroupRepository = countryGroupRepository; _countryRepository = countryRepository; _cityRepository = cityRepository; _districtRepository = districtRepository; _contactTitleRepository = contactTitleRepository; - _aiBotRepository = aiBotRepository; - _routeRepository = routeRepository; } private static IConfigurationRoot BuildConfiguration() @@ -436,22 +395,14 @@ public class HostDataSeeder : IDataSeedContributor, ITransientDependency { var settings = await _settings.GetListAsync(); var dataSources = await _dataSources.GetListAsync(); - var languages = await _languages.GetListAsync(); - var keys = await _languageKey.GetListAsync(); - var texts = await _languagesText.GetListAsync(); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(Path.Combine("Seeds", "HostData.json")) .AddJsonFile(Path.Combine("Seeds", $"HostData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), true) - .AddJsonFile(Path.Combine("Seeds", "LanguagesData.json")) - .AddJsonFile(Path.Combine("Seeds", "MenusData.json")) - .AddJsonFile(Path.Combine("Seeds", "PermissionsData.json")) .Build(); var items = configuration.Get(); - var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; - foreach (var item in items.Settings) { if (!settings.Any(a => a.Code == item.Code)) @@ -487,101 +438,6 @@ public class HostDataSeeder : IDataSeedContributor, ITransientDependency }); } - foreach (var item in items.Languages) - { - if (!languages.Any(a => a.CultureName == item.CultureName)) - { - await _languages.InsertAsync(new() - { - CultureName = item.CultureName, - UiCultureName = item.UiCultureName, - DisplayName = item.DisplayName, - IsEnabled = item.IsEnabled, - TwoLetterISOLanguageName = new CultureInfo(item.CultureName).TwoLetterISOLanguageName, - }); - } - } - - foreach (var item in items.LanguageTexts) - { - try - { - if (!keys.Any(a => a.Key == item.Key)) - { - await _languageKey.InsertAsync(new() - { - Key = item.Key, - ResourceName = item.ResourceName, - }); - } - if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key)) - { - await _languagesText.InsertAsync(new() - { - CultureName = "en", - Key = item.Key, - Value = item.En, - ResourceName = item.ResourceName, - }); - } - if (!texts.Any(a => a.CultureName == "tr" && a.Key == item.Key)) - { - - await _languagesText.InsertAsync(new() - { - CultureName = "tr", - Key = item.Key, - Value = item.Tr, - ResourceName = item.ResourceName, - }); - } - } - catch (Exception ex) - { - throw new Exception($"Hata veren Kod:' ResourceName='{item.ResourceName}', Key='{item.Key}' Message='{ex.Message}'"); - } - } - - foreach (var item in items.LanguageFieldTitles) - { - try - { - if (!keys.Any(a => a.Key == item.Key)) - { - await _languageKey.InsertAsync(new() - { - Key = item.Key, - ResourceName = item.ResourceName, - }); - } - if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key)) - { - await _languagesText.InsertAsync(new() - { - CultureName = "en", - Key = item.Key, - Value = item.En, - ResourceName = item.ResourceName, - }); - } - if (!texts.Any(a => a.CultureName == "tr" && a.Key == item.Key)) - { - - await _languagesText.InsertAsync(new() - { - CultureName = "tr", - Key = item.Key, - Value = item.Tr, - ResourceName = item.ResourceName, - }); - } - } - catch (Exception ex) - { - throw new Exception($"Hata veren Kod:' ResourceName='{item.ResourceName}', Key='{item.Key}' Message='{ex.Message}'"); - } - } - foreach (var item in items.BackgroundWorkers) { if (!await _backgroundWorkerRepository.AnyAsync(x => x.Name == item.Name)) @@ -597,63 +453,6 @@ public class HostDataSeeder : IDataSeedContributor, ITransientDependency } } - foreach (var item in items.Menus) - { - var exists = await _menuRepository.AnyAsync(x => x.Code == item.Code); - - if (!exists) - { - await _menuRepository.InsertAsync(new Menu - { - ParentCode = string.IsNullOrWhiteSpace(item.ParentCode) ? null : item.ParentCode, - Code = item.Code, - DisplayName = item.DisplayName, - Order = item.Order, - Url = item.Url, - Icon = item.Icon, - RequiredPermissionName = item.RequiredPermissionName, - IsDisabled = item.IsDisabled, - ShortName = item.ShortName - }); - } - } - - foreach (var item in items.PermissionGroupDefinitionRecords) - { - var exists = await _permissionGroupRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - await _permissionGroupRepository.InsertAsync(new PermissionGroupDefinitionRecord - { - Name = item.Name, - DisplayName = item.DisplayName - }); - } - } - - foreach (var item in items.PermissionDefinitionRecords) - { - var exists = await _permissionRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - var perm = new PermissionDefinitionRecord - { - GroupName = item.GroupName, - Name = item.Name, - ParentName = string.IsNullOrWhiteSpace(item.ParentName) ? null : item.ParentName, - DisplayName = item.DisplayName, - IsEnabled = item.IsEnabled, - MultiTenancySide = (MultiTenancySides)item.MultiTenancySide, - }; - - perm.SetMenuGroup(item.MenuGroup); - - await _permissionRepository.InsertAsync(perm); - } - } - foreach (var item in items.Currencies) { var exists = await _currencyRepository.AnyAsync(x => x.Id == item.Id); @@ -699,22 +498,6 @@ public class HostDataSeeder : IDataSeedContributor, ITransientDependency } } - foreach (var item in items.Routes) - { - var exists = await _routeRepository.AnyAsync(x => x.Key == item.Key); - - if (!exists) - { - await _routeRepository.InsertAsync(new Route( - item.Key, - item.Path, - item.ComponentPath, - item.RouteType, - item.Authority ?? [] - )); - } - } - await SeedCountyGroupsAsync(); await SeedCountriesAsync(); diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguageDataSeeder.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguageDataSeeder.cs new file mode 100644 index 0000000..76ffa9f --- /dev/null +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguageDataSeeder.cs @@ -0,0 +1,144 @@ +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using Sozsoft.Languages.Entities; +using Microsoft.Extensions.Configuration; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; + +namespace Sozsoft.Platform.Data.Seeds; + +public class LanguageSeederDto +{ + public List Languages { get; set; } + public List LanguageTexts { get; set; } + public List LanguageFieldTitles { get; set; } +} + +public class LanguageDataSeeder : IDataSeedContributor, ITransientDependency +{ + private readonly IRepository _languages; + private readonly IRepository _languageKey; + private readonly IRepository _languagesText; + + public LanguageDataSeeder( + IRepository languages, + IRepository languageKey, + IRepository languagesText) + { + _languages = languages; + _languageKey = languageKey; + _languagesText = languagesText; + } + + public async Task SeedAsync(DataSeedContext context) + { + var languages = await _languages.GetListAsync(); + var keys = await _languageKey.GetListAsync(); + var texts = await _languagesText.GetListAsync(); + + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(Path.Combine("Seeds", "LanguagesData.json")) + .Build(); + + var items = configuration.Get(); + + foreach (var item in items.Languages) + { + if (!languages.Any(a => a.CultureName == item.CultureName)) + { + await _languages.InsertAsync(new() + { + CultureName = item.CultureName, + UiCultureName = item.UiCultureName, + DisplayName = item.DisplayName, + IsEnabled = item.IsEnabled, + TwoLetterISOLanguageName = new CultureInfo(item.CultureName).TwoLetterISOLanguageName, + }); + } + } + + foreach (var item in items.LanguageTexts) + { + try + { + if (!keys.Any(a => a.Key == item.Key)) + { + await _languageKey.InsertAsync(new() + { + Key = item.Key, + ResourceName = item.ResourceName, + }); + } + if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key)) + { + await _languagesText.InsertAsync(new() + { + CultureName = "en", + Key = item.Key, + Value = item.En, + ResourceName = item.ResourceName, + }); + } + if (!texts.Any(a => a.CultureName == "tr" && a.Key == item.Key)) + { + await _languagesText.InsertAsync(new() + { + CultureName = "tr", + Key = item.Key, + Value = item.Tr, + ResourceName = item.ResourceName, + }); + } + } + catch (Exception ex) + { + throw new Exception($"Hata veren Kod:' ResourceName='{item.ResourceName}', Key='{item.Key}' Message='{ex.Message}'"); + } + } + + foreach (var item in items.LanguageFieldTitles) + { + try + { + if (!keys.Any(a => a.Key == item.Key)) + { + await _languageKey.InsertAsync(new() + { + Key = item.Key, + ResourceName = item.ResourceName, + }); + } + if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key)) + { + await _languagesText.InsertAsync(new() + { + CultureName = "en", + Key = item.Key, + Value = item.En, + ResourceName = item.ResourceName, + }); + } + if (!texts.Any(a => a.CultureName == "tr" && a.Key == item.Key)) + { + await _languagesText.InsertAsync(new() + { + CultureName = "tr", + Key = item.Key, + Value = item.Tr, + ResourceName = item.ResourceName, + }); + } + } + catch (Exception ex) + { + throw new Exception($"Hata veren Kod:' ResourceName='{item.ResourceName}', Key='{item.Key}' Message='{ex.Message}'"); + } + } + } +} diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json index 4609c9b..4f56b08 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json @@ -15908,6 +15908,12 @@ "en": "Rename", "tr": "Yeniden Adlandır" }, + { + "resourceName": "Platform", + "key": "ListForms.Wizard.Step1.ShortNameHint", + "en": "Auto-derived, editable", + "tr": "Otomatik oluşturulur, düzenlenebilir" + }, { "resourceName": "Platform", "key": "ListForms.Wizard.Step1.Delete", @@ -16100,6 +16106,12 @@ "en": "Editor Options", "tr": "Editör Seçenekleri" }, + { + "resourceName": "Platform", + "key": "ListForms.Wizard.Step3.Required", + "en": "Required", + "tr": "Zorunlu" + }, { "resourceName": "Platform", "key": "ListForms.Wizard.Step3.EditorScript", diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Administration.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Administration.cs index e5ef50c..91832f7 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Administration.cs +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Administration.cs @@ -16,7 +16,7 @@ using Volo.Abp.Identity; using AbpIdentity = Sozsoft.Platform.Data.Seeds.SeedConsts.AbpIdentity; using AppCodes = Sozsoft.Platform.Data.Seeds.SeedConsts.AppCodes; using static Sozsoft.Platform.PlatformConsts; -using static Sozsoft.Platform.PlatformSeeder.SeederDefaults; +using static Sozsoft.Platform.PlatformSeeder.ListFormSeeder_DefaultJsons; namespace Sozsoft.Platform.Data.Seeds; @@ -46,7 +46,7 @@ public class ListFormSeeder_Administration : IDataSeedContributor, ITransientDep { var configurationSection = _configuration.GetSection("OpenIddict:Applications"); var swaggerRootUrl = configurationSection["Platform_Swagger:RootUrl"]?.TrimEnd('/'); - var utils = new SeederUtils(_listFormRepository, _listFormFieldRepository); + var utils = new ListFormSeeder_Utils(_listFormRepository, _listFormFieldRepository); var listFormName = String.Empty; #region Permission Group @@ -5012,7 +5012,7 @@ public class ListFormSeeder_Administration : IDataSeedContributor, ITransientDep Name = listFormName, Title = listFormName, DataSourceCode = SeedConsts.DataSources.DefaultCode, - IsTenant = true, + IsTenant = false, IsBranch = false, IsOrganizationUnit = false, Description = listFormName, diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederDefaults.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_DefaultJsons.cs similarity index 99% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederDefaults.cs rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_DefaultJsons.cs index f4c03c0..f07f270 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederDefaults.cs +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_DefaultJsons.cs @@ -8,7 +8,7 @@ using static Sozsoft.Platform.PlatformConsts; namespace Sozsoft.Platform.PlatformSeeder; -public static class SeederDefaults +public static class ListFormSeeder_DefaultJsons { public static string DefaultDeleteCommand(string tableName) { diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs index 4b91be1..4adb682 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs @@ -16,7 +16,7 @@ using Volo.Abp.Identity; using Volo.Abp.TenantManagement; using AppCodes = Sozsoft.Platform.Data.Seeds.SeedConsts.AppCodes; using static Sozsoft.Platform.PlatformConsts; -using static Sozsoft.Platform.PlatformSeeder.SeederDefaults; +using static Sozsoft.Platform.PlatformSeeder.ListFormSeeder_DefaultJsons; using Microsoft.Extensions.Localization; using Sozsoft.Platform.Localization; @@ -52,7 +52,7 @@ public class ListFormSeeder_Saas : IDataSeedContributor, ITransientDependency { var configurationSection = _configuration.GetSection("OpenIddict:Applications"); var swaggerRootUrl = configurationSection["Platform_Swagger:RootUrl"]?.TrimEnd('/'); - var utils = new SeederUtils(_listFormRepository, _listFormFieldRepository); + var utils = new ListFormSeeder_Utils(_listFormRepository, _listFormFieldRepository); var listFormName = String.Empty; #region Tenant diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederUtils.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Utils.cs similarity index 99% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederUtils.cs rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Utils.cs index 0afd267..57a1505 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SeederUtils.cs +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/ListFormSeeder_Utils.cs @@ -12,12 +12,12 @@ using Volo.Abp.Domain.Repositories; namespace Sozsoft.Platform.Data.Seeds; -public class SeederUtils +public class ListFormSeeder_Utils { private readonly IRepository _listFormRepository; private readonly IRepository _listFormFieldRepository; - public SeederUtils( + public ListFormSeeder_Utils( IRepository listFormRepository, IRepository listFormFieldRepository) { diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/MenuDataSeeder.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/MenuDataSeeder.cs new file mode 100644 index 0000000..bc8c518 --- /dev/null +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/MenuDataSeeder.cs @@ -0,0 +1,88 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Collections.Generic; +using Sozsoft.Platform.Entities; +using Microsoft.Extensions.Configuration; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; + +namespace Sozsoft.Platform.Data.Seeds; + +public class RouteSeedDto +{ + public string Key { get; set; } + public string Path { get; set; } + public string ComponentPath { get; set; } + public string RouteType { get; set; } + public string[] Authority { get; set; } +} + +public class MenuSeederDto +{ + public List Routes { get; set; } + public List Menus { get; set; } +} + +public class MenuDataSeeder : IDataSeedContributor, ITransientDependency +{ + private readonly IRepository _routeRepository; + private readonly IRepository _menuRepository; + + public MenuDataSeeder( + IRepository routeRepository, + IRepository menuRepository + ) + { + _routeRepository = routeRepository; + _menuRepository = menuRepository; + } + + public async Task SeedAsync(DataSeedContext context) + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(Path.Combine("Seeds", "MenusData.json")) + .Build(); + + var items = configuration.Get(); + + foreach (var item in items.Routes) + { + var exists = await _routeRepository.AnyAsync(x => x.Key == item.Key); + + if (!exists) + { + await _routeRepository.InsertAsync(new Route( + item.Key, + item.Path, + item.ComponentPath, + item.RouteType, + item.Authority ?? [] + )); + } + } + + foreach (var item in items.Menus) + { + var exists = await _menuRepository.AnyAsync(x => x.Code == item.Code); + + if (!exists) + { + await _menuRepository.InsertAsync(new Menu + { + ParentCode = string.IsNullOrWhiteSpace(item.ParentCode) ? null : item.ParentCode, + Code = item.Code, + DisplayName = item.DisplayName, + Order = item.Order, + Url = item.Url, + Icon = item.Icon, + RequiredPermissionName = item.RequiredPermissionName, + IsDisabled = item.IsDisabled, + ShortName = item.ShortName + }); + } + } + } +} diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/PermissionDataSeeder.cs b/api/src/Sozsoft.Platform.DbMigrator/Seeds/PermissionDataSeeder.cs new file mode 100644 index 0000000..d380908 --- /dev/null +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/PermissionDataSeeder.cs @@ -0,0 +1,79 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Collections.Generic; +using Microsoft.Extensions.Configuration; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.MultiTenancy; +using Volo.Abp.PermissionManagement; +using Sozsoft.Platform.Extensions; + +namespace Sozsoft.Platform.Data.Seeds; + +public class PermissionSeederDto +{ + public List PermissionGroupDefinitionRecords { get; set; } + public List PermissionDefinitionRecords { get; set; } +} + +public class PermissionDataSeeder : IDataSeedContributor, ITransientDependency +{ + private readonly IRepository _permissionGroupRepository; + private readonly IRepository _permissionRepository; + + public PermissionDataSeeder( + IRepository permissionGroupRepository, + IRepository permissionRepository) + { + _permissionGroupRepository = permissionGroupRepository; + _permissionRepository = permissionRepository; + } + + public async Task SeedAsync(DataSeedContext context) + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(Path.Combine("Seeds", "PermissionsData.json")) + .Build(); + + var items = configuration.Get(); + + foreach (var item in items.PermissionGroupDefinitionRecords) + { + var exists = await _permissionGroupRepository.AnyAsync(x => x.Name == item.Name); + + if (!exists) + { + await _permissionGroupRepository.InsertAsync(new PermissionGroupDefinitionRecord + { + Name = item.Name, + DisplayName = item.DisplayName + }); + } + } + + foreach (var item in items.PermissionDefinitionRecords) + { + var exists = await _permissionRepository.AnyAsync(x => x.Name == item.Name); + + if (!exists) + { + var perm = new PermissionDefinitionRecord + { + GroupName = item.GroupName, + Name = item.Name, + ParentName = string.IsNullOrWhiteSpace(item.ParentName) ? null : item.ParentName, + DisplayName = item.DisplayName, + IsEnabled = item.IsEnabled, + MultiTenancySide = (MultiTenancySides)item.MultiTenancySide, + }; + + perm.SetMenuGroup(item.MenuGroup); + + await _permissionRepository.InsertAsync(perm); + } + } + } +} diff --git a/api/src/Sozsoft.Platform.Domain.Shared/PlatformConsts.cs b/api/src/Sozsoft.Platform.Domain.Shared/PlatformConsts.cs index 2eb3a89..edac43f 100644 --- a/api/src/Sozsoft.Platform.Domain.Shared/PlatformConsts.cs +++ b/api/src/Sozsoft.Platform.Domain.Shared/PlatformConsts.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Data; -using System.Text.Json; using Sozsoft.Languages.Languages; using Sozsoft.Platform.Enums; using Volo.Abp.Reflection; @@ -407,135 +405,6 @@ public static class PlatformConsts } } - public static class Wizard - { - public static string WizardKey(string code) => $"{Prefix.App}.Wizard.{code}"; - public static string WizardKeyTitle(string code) => $"{WizardKey(code)}.Title"; - public static string WizardKeyDesc(string code) => $"{WizardKey(code)}.Desc"; - public static string WizardKeyParent(string code) => $"{WizardKey(code)}.Parent"; - - public static string PermCreate(string code) => $"{WizardKey(code)}.Create"; - public static string PermUpdate(string code) => $"{WizardKey(code)}.Update"; - public static string PermDelete(string code) => $"{WizardKey(code)}.Delete"; - public static string PermExport(string code) => $"{WizardKey(code)}.Export"; - public static string PermImport(string code) => $"{WizardKey(code)}.Import"; - public static string PermNote(string code) => $"{WizardKey(code)}.Note"; - public static string LangKeyCreate => "Create"; - public static string LangKeyUpdate => "Update"; - public static string LangKeyDelete => "Delete"; - public static string LangKeyExport => "Export"; - public static string LangKeyImport => "Import"; - public static string LangKeyNote => "Note"; - - public static string MenuUrl(string code) => $"/admin/list/{code}"; - public static string MenuIcon => "FcList"; - - public static readonly string DefaultExportJson = JsonSerializer.Serialize(new - { - Enabled = true, - AllowExportSelectedData = false, - PrintingEnabled = true, - BackgroundColor = "#FFFFFF", - Margin = 10 - }); - - public static string DefaultLayoutJson(string DefaultLayout = "grid") => JsonSerializer.Serialize(new - { - Grid = true, - Pivot = true, - Chart = true, - Tree = true, - Gantt = true, - Scheduler = true, - DefaultLayout = DefaultLayout, - }); - - public static readonly string DefaultFilterJson = "\"IsDeleted\" = 'false'"; - public static readonly string DefaultFilterRowJson = JsonSerializer.Serialize(new { Visible = true }); - public static readonly string DefaultHeaderFilterJson = JsonSerializer.Serialize(new { Visible = true }); - public static readonly string DefaultSearchPanelJson = JsonSerializer.Serialize(new { Visible = true }); - public static readonly string DefaultGroupPanelJson = JsonSerializer.Serialize(new { Visible = true }); - - public static readonly string DefaultSelectionSingleJson = JsonSerializer.Serialize(new - { - Mode = GridOptions.SelectionModeNone, - AllowSelectAll = false - }); - - public static string DefaultColumnOptionJson(bool FocusedRowEnabled = true) => JsonSerializer.Serialize(new - { - ColumnFixingEnabled = true, - ColumnAutoWidth = true, - ColumnChooserEnabled = true, - AllowColumnResizing = true, - AllowColumnReordering = true, - ColumnResizingMode = "widget", - FocusedRowEnabled = FocusedRowEnabled, - }); - - public static string DefaultPermissionJson(string permissionName) - { - return JsonSerializer.Serialize(new - { - C = permissionName + ".Create", - R = permissionName, - U = permissionName + ".Update", - D = permissionName + ".Delete", - E = permissionName + ".Export", - I = permissionName + ".Import", - N = permissionName + ".Note", - }); - } - - public static string DefaultDeleteCommand(string tableName) - { - return $"UPDATE \"{TableNameResolver.GetFullTableName(tableName)}\" SET \"DeleterId\"=@DeleterId, \"DeletionTime\"=CURRENT_TIMESTAMP, \"IsDeleted\"='true' WHERE \"Id\"=@Id"; - } - - public static string DefaultDeleteFieldsDefaultValueJson(DbType dbType = DbType.Guid) - { - return JsonSerializer.Serialize(new[] - { - new { FieldName = "DeleterId", FieldDbType = DbType.Guid, Value = "@USERID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }, - new { FieldName = "Id", FieldDbType = dbType, Value = "@ID", CustomValueType = FieldCustomValueTypeEnum.CustomKey } - }); - } - - public static readonly string DefaultPagerOptionJson = JsonSerializer.Serialize(new - { - Visible = true, - AllowedPageSizes = "10,20,50,100", - ShowPageSizeSelector = true, - ShowNavigationButtons = true, - ShowInfo = false, - InfoText = "Page {0} of {1} ({2} items)", - DisplayMode = GridColumnOptions.PagerDisplayModeAdaptive, - ScrollingMode = GridColumnOptions.ScrollingModeStandard, - LoadPanelEnabled = "auto", - LoadPanelText = "Loading..." - }); - - public static string DefaultEditingOptionJson( - string Title, - int Width, - int Height, - bool AllowDeleting, - bool AllowAdding, - bool AllowEditing, - bool ConfirmDelete, - bool SendOnlyChangedFormValuesUpdate, - bool AllowDetail = false) => JsonSerializer.Serialize(new - { - Popup = new { Title = Title, Width = Width, Height = Height }, - AllowDeleting = AllowDeleting, - AllowAdding = AllowAdding, - AllowEditing = AllowEditing, - ConfirmDelete = ConfirmDelete, - SendOnlyChangedFormValuesUpdate = SendOnlyChangedFormValuesUpdate, - AllowDetail = AllowDetail - }); - } - public static class AppErrorCodes { public const string NoAuth = "Error:0001"; diff --git a/api/src/Sozsoft.Platform.Domain.Shared/WizardConsts.cs b/api/src/Sozsoft.Platform.Domain.Shared/WizardConsts.cs new file mode 100644 index 0000000..ae476e8 --- /dev/null +++ b/api/src/Sozsoft.Platform.Domain.Shared/WizardConsts.cs @@ -0,0 +1,144 @@ +using System.Data; +using System.Text.Json; +using Sozsoft.Platform.Enums; +using static Sozsoft.Platform.PlatformConsts; + +public static class WizardConsts +{ + public static string WizardKey(string code) => $"{Prefix.App}.Wizard.{code}"; + public static string WizardKeyTitle(string code) => $"{WizardKey(code)}.Title"; + public static string WizardKeyDesc(string code) => $"{WizardKey(code)}.Desc"; + public static string WizardKeyParent(string code) => $"{WizardKey(code)}.Parent"; + + public static string PermCreate(string code) => $"{WizardKey(code)}.Create"; + public static string PermUpdate(string code) => $"{WizardKey(code)}.Update"; + public static string PermDelete(string code) => $"{WizardKey(code)}.Delete"; + public static string PermExport(string code) => $"{WizardKey(code)}.Export"; + public static string PermImport(string code) => $"{WizardKey(code)}.Import"; + public static string PermNote(string code) => $"{WizardKey(code)}.Note"; + public static string LangKeyCreate => "Create"; + public static string LangKeyUpdate => "Update"; + public static string LangKeyDelete => "Delete"; + public static string LangKeyExport => "Export"; + public static string LangKeyImport => "Import"; + public static string LangKeyNote => "Note"; + + public static string MenuUrl(string code) => $"/admin/list/{code}"; + public static string MenuIcon => "FcList"; + + public static readonly string DefaultExportJson = JsonSerializer.Serialize(new + { + Enabled = true, + AllowExportSelectedData = false, + PrintingEnabled = true, + BackgroundColor = "#FFFFFF", + Margin = 10 + }); + + public static string DefaultLayoutJson(string DefaultLayout = "grid") => JsonSerializer.Serialize(new + { + Grid = true, + Pivot = true, + Chart = true, + Tree = true, + Gantt = true, + Scheduler = true, + DefaultLayout = DefaultLayout, + }); + + public static readonly string DefaultFilterJson = "\"IsDeleted\" = 'false'"; + public static readonly string DefaultFilterRowJson = JsonSerializer.Serialize(new { Visible = true }); + public static readonly string DefaultHeaderFilterJson = JsonSerializer.Serialize(new { Visible = true }); + public static readonly string DefaultSearchPanelJson = JsonSerializer.Serialize(new { Visible = true }); + public static readonly string DefaultGroupPanelJson = JsonSerializer.Serialize(new { Visible = true }); + + public static readonly string DefaultSelectionSingleJson = JsonSerializer.Serialize(new + { + Mode = GridOptions.SelectionModeNone, + AllowSelectAll = false + }); + + public static string DefaultColumnOptionJson(bool FocusedRowEnabled = true) => JsonSerializer.Serialize(new + { + ColumnFixingEnabled = true, + ColumnAutoWidth = true, + ColumnChooserEnabled = true, + AllowColumnResizing = true, + AllowColumnReordering = true, + ColumnResizingMode = "widget", + FocusedRowEnabled = FocusedRowEnabled, + }); + + public static string DefaultPermissionJson(string permissionName) + { + return JsonSerializer.Serialize(new + { + C = permissionName + ".Create", + R = permissionName, + U = permissionName + ".Update", + D = permissionName + ".Delete", + E = permissionName + ".Export", + I = permissionName + ".Import", + N = permissionName + ".Note", + }); + } + + public static string DefaultDeleteCommand(string tableName) + { + return $"UPDATE \"{tableName}\" SET \"DeleterId\"=@DeleterId, \"DeletionTime\"=CURRENT_TIMESTAMP, \"IsDeleted\"='true' WHERE \"Id\"=@Id"; + } + + public static string DefaultInsertFieldsDefaultValueJson(DbType dbType = DbType.Guid) + { + return JsonSerializer.Serialize(new[] + { + new { FieldName = "CreationTime", FieldDbType = DbType.DateTime, Value = "@NOW", CustomValueType = FieldCustomValueTypeEnum.CustomKey }, + new { FieldName = "CreatorId", FieldDbType = DbType.Guid, Value = "@USERID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }, + new { FieldName = "IsDeleted", FieldDbType = DbType.Boolean, Value = "false", CustomValueType = FieldCustomValueTypeEnum.Value }, + new { FieldName = "Id", FieldDbType = dbType, Value = "@NEWID", CustomValueType = FieldCustomValueTypeEnum.CustomKey } + }); + } + + public static string DefaultDeleteFieldsDefaultValueJson(DbType dbType = DbType.Guid) + { + return JsonSerializer.Serialize(new[] + { + new { FieldName = "DeleterId", FieldDbType = DbType.Guid, Value = "@USERID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }, + new { FieldName = "Id", FieldDbType = dbType, Value = "@ID", CustomValueType = FieldCustomValueTypeEnum.CustomKey } + }); + } + + public static readonly string DefaultPagerOptionJson = JsonSerializer.Serialize(new + { + Visible = true, + AllowedPageSizes = "10,20,50,100", + ShowPageSizeSelector = true, + ShowNavigationButtons = true, + ShowInfo = false, + InfoText = "Page {0} of {1} ({2} items)", + DisplayMode = GridColumnOptions.PagerDisplayModeAdaptive, + ScrollingMode = GridColumnOptions.ScrollingModeStandard, + LoadPanelEnabled = "auto", + LoadPanelText = "Loading..." + }); + + public static string DefaultEditingOptionJson( + string Title, + int Width, + int Height, + bool AllowDeleting, + bool AllowAdding, + bool AllowEditing, + bool ConfirmDelete, + bool SendOnlyChangedFormValuesUpdate, + bool AllowDetail = false) => JsonSerializer.Serialize(new + { + Popup = new { Title = Title, Width = Width, Height = Height }, + AllowDeleting = AllowDeleting, + AllowAdding = AllowAdding, + AllowEditing = AllowEditing, + ConfirmDelete = ConfirmDelete, + SendOnlyChangedFormValuesUpdate = SendOnlyChangedFormValuesUpdate, + AllowDetail = AllowDetail + }); +} diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTables.sql b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTables.sql new file mode 100644 index 0000000..50db692 --- /dev/null +++ b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTables.sql @@ -0,0 +1,32 @@ +IF OBJECT_ID(N'[dbo].[Adm_T_Behavior]', 'U') IS NULL +BEGIN + CREATE TABLE [dbo].[Adm_T_Behavior]( + [Id] [nvarchar](128) NOT NULL, + [TenantId] [uniqueidentifier] NULL, + [Name] [nvarchar](128) NOT NULL, + [CreationTime] [datetime2](7) NOT NULL, + [CreatorId] [uniqueidentifier] NULL, + [LastModificationTime] [datetime2](7) NULL, + [LastModifierId] [uniqueidentifier] NULL, + [IsDeleted] [bit] NOT NULL, + [DeleterId] [uniqueidentifier] NULL, + [DeletionTime] [datetime2](7) NULL, + CONSTRAINT [PK_Adm_T_Behavior] PRIMARY KEY CLUSTERED + ( + [Id] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] + ) ON [PRIMARY] +END +GO + +IF NOT EXISTS ( + SELECT 1 + FROM sys.default_constraints dc + JOIN sys.columns c ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id + WHERE dc.parent_object_id = OBJECT_ID(N'[dbo].[Adm_T_Behavior]') + AND c.name = N'IsDeleted' +) +BEGIN + ALTER TABLE [dbo].[Adm_T_Behavior] ADD DEFAULT (CONVERT([bit],(0))) FOR [IsDeleted] +END +GO \ No newline at end of file diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTablesSeeder.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTablesSeeder.cs new file mode 100644 index 0000000..9f3be42 --- /dev/null +++ b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/SqlTablesSeeder.cs @@ -0,0 +1,69 @@ +using System; +using System.IO; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Sozsoft.Platform.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; + +namespace Sozsoft.Platform.Data.Seeds; + +/// +/// Sql tables seeder for creating or updating database tables based on the current entity definitions. This seeder ensures that the database schema is in sync with the application's data model, allowing for smooth migrations and updates without manual intervention. +/// +public class SqlTablesSeeder : IDataSeedContributor, ITransientDependency +{ + private readonly IDbContextProvider _dbContextProvider; + private readonly ILogger _logger; + + public SqlTablesSeeder( + IDbContextProvider dbContextProvider, + ILogger logger) + { + _dbContextProvider = dbContextProvider; + _logger = logger; + } + + public async Task SeedAsync(DataSeedContext context) + { + var assemblyLocation = Path.GetDirectoryName(typeof(SqlTablesSeeder).Assembly.Location)!; + var sqlFilePath = Path.Combine(assemblyLocation, "Seeds", "SqlTables.sql"); + + if (!File.Exists(sqlFilePath)) + { + _logger.LogWarning("SqlTables.sql file not found at {Path}. Skipping SQL table seeding.", sqlFilePath); + return; + } + + var sqlContent = await File.ReadAllTextAsync(sqlFilePath); + + // Split by GO statements (SQL Server batch separator) + var batches = Regex.Split(sqlContent, @"^\s*GO\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase); + + var dbContext = await _dbContextProvider.GetDbContextAsync(); + + _logger.LogInformation("Starting database script seeding..."); + + foreach (var batch in batches) + { + var sql = batch.Trim(); + if (string.IsNullOrWhiteSpace(sql)) + continue; + + try + { + await dbContext.Database.ExecuteSqlRawAsync(sql); + } + catch (Exception ex) + { + _logger.LogWarning("SQL batch skipped (may already exist): {Message}", ex.Message); + } + } + + _logger.LogInformation("Database script seeding completed successfully."); + } +} + diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.Dev.json b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.Dev.json similarity index 100% rename from api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.Dev.json rename to api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.Dev.json diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.Production.json b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.Production.json similarity index 100% rename from api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.Production.json rename to api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.Production.json diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.json b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.json similarity index 100% rename from api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/Seeds/TenantData.json rename to api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantData.json diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDataSeeder.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantDataSeeder.cs similarity index 72% rename from api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDataSeeder.cs rename to api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantDataSeeder.cs index dfa3b3f..6b688e1 100644 --- a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDataSeeder.cs +++ b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantDataSeeder.cs @@ -4,20 +4,241 @@ using System.Text.Json; using System.Threading.Tasks; using Sozsoft.Platform.Entities; using Sozsoft.Platform.Forum; -using Sozsoft.Platform.Seeds; +using Sozsoft.Platform.Public; using Microsoft.Extensions.Configuration; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; using Microsoft.EntityFrameworkCore; -using System.Linq; -using System.Collections.Generic; using Volo.Abp.Identity; using Volo.Abp.Timing; -using Volo.Abp; +using System.Collections.Generic; namespace Sozsoft.Platform.Data.Seeds; +public class TenantSeederDto +{ + //Saas + public List GlobalSearch { get; set; } + public List CustomEndpoints { get; set; } + public List CustomComponents { get; set; } + + //Tanımlamalar + public List Sectors { get; set; } + public List WorkHours { get; set; } + public List UomCategories { get; set; } + public List Uoms { get; set; } + public List SkillTypes { get; set; } + public List Skills { get; set; } + public List SkillLevels { get; set; } + + public List Abouts { get; set; } + public List Services { get; set; } + public List PaymentMethods { get; set; } + public List InstallmentOptions { get; set; } + public List BlogCategories { get; set; } + public List BlogPosts { get; set; } + public List Products { get; set; } + public List Contacts { get; set; } + + //Report Templates + public List ReportCategories { get; set; } + public List ReportTemplates { get; set; } + + public List ForumCategories { get; set; } +} + +public class GlobalSearchSeedDto +{ + public string System { get; set; } + public string Group { get; set; } + public string Term { get; set; } + public string Weight { get; set; } + public string Url { get; set; } +} + +public class SectorSeedDto +{ + public string Name { get; set; } +} + +public class UomCategorySeedDto +{ + public Guid Id { get; set; } + + public string Name { get; set; } +} + +public class UomSeedDto +{ + public string Name { get; set; } + public string Type { get; set; } + public decimal Ratio { get; set; } + public bool IsActive { get; set; } + public decimal Rounding { get; set; } + public string UomCategoryName { get; set; } +} + +public class SkillTypeSeedDto +{ + public string Name { get; set; } +} + +public class SkillSeedDto +{ + public string Name { get; set; } + public string SkillTypeName { get; set; } +} + +public class SkillLevelSeedDto +{ + public string Name { get; set; } + public int Progress { get; set; } + public bool IsDefault { get; set; } + public string SkillTypeName { get; set; } +} + +public class BlogCategorySeedDto +{ + public string Name { get; set; } + public string Slug { get; set; } + public string Description { get; set; } + public int DisplayOrder { get; set; } + public int PostCount { get; set; } +} + +public class BlogPostSeedDto +{ + public string Title { get; set; } + public string Slug { get; set; } + public string ContentTr { get; set; } + public string ContentEn { get; set; } + public string ReadTime { get; set; } + public string Summary { get; set; } + public string CoverImage { get; set; } + public string CategoryName { get; set; } + public string UserName { get; set; } + public bool IsPublished { get; set; } + public DateTime PublishedAt { get; set; } +} + +public class ForumCategorySeedDto +{ + public string Name { get; set; } + public string Slug { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public int DisplayOrder { get; set; } + public bool IsActive { get; set; } +} + +public class CustomEndpointSeedDto +{ + public string Name { get; set; } + public string Description { get; set; } + public string Url { get; set; } + public string Method { get; set; } + public string DataSourceCode { get; set; } + public string Sql { get; set; } + public List ParametersJson { get; set; } + public List PermissionsJson { get; set; } +} + +public class PaymentMethodSeedDto +{ + public string Name { get; set; } + public decimal Commission { get; set; } + public string Logo { get; set; } +} + +public class InstallmentOptionSeedDto +{ + public int Installment { get; set; } + public string Name { get; set; } + public decimal Commission { get; set; } +} + +public class CustomComponentSeedDto +{ + public string Name { get; set; } + public string Code { get; set; } + public string Props { get; set; } + public string Description { get; set; } + public bool IsActive { get; set; } + public List Dependencies { get; set; } = new(); +} + +public class ReportTemplateSeedDto +{ + public string Name { get; set; } + public string Description { get; set; } + public string CategoryName { get; set; } + public string HtmlContent { get; set; } + public string Status { get; set; } +} + +public class ReportCategorySeedDto +{ + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } +} + +public class ServiceSeedDto +{ + public string Icon { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public string Type { get; set; } + public string[] Features { get; set; } +} + +public class AboutSeedDto +{ + public List Stats { get; set; } + public List Descriptions { get; set; } + public List Sections { get; set; } +} + +public class WorkHourSeedDto +{ + public string Name { get; set; } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } + public bool? IsFixed { get; set; } + public bool? Monday { get; set; } + public bool? Tuesday { get; set; } + public bool? Wednesday { get; set; } + public bool? Thursday { get; set; } + public bool? Friday { get; set; } + public bool? Saturday { get; set; } + public bool? Sunday { get; set; } +} + +public class ContactSeedDto +{ + public string Address { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string Location { get; set; } + public long TaxNumber { get; set; } + public BankDto Bank { get; set; } + public WorkHoursDto WorkHour { get; set; } + public MapDto Map { get; set; } +} + +public class ProductSeedDto +{ + public string Name { get; set; } + public string Description { get; set; } + public string Category { get; set; } + public int Order { get; set; } + public decimal? MonthlyPrice { get; set; } + public decimal? YearlyPrice { get; set; } + public bool IsQuantityBased { get; set; } + public string ImageUrl { get; set; } +} + public class TenantDataSeeder : IDataSeedContributor, ITransientDependency { private readonly IClock _clock; @@ -104,25 +325,14 @@ public class TenantDataSeeder : IDataSeedContributor, ITransientDependency _organizationUnitManager = organizationUnitManager; } - private static IConfigurationRoot BuildConfiguration() - { - var builder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? ""}.json", true); - - return builder.Build(); - } - public async Task SeedAsync(DataSeedContext context) { var assemblyLocation = Path.GetDirectoryName(typeof(TenantDataSeeder).Assembly.Location)!; - var basePath = Path.Combine(assemblyLocation, "Tenants", "Seeds"); var configuration = new ConfigurationBuilder() - .SetBasePath(basePath) - .AddJsonFile("TenantData.json", optional: false, reloadOnChange: false) - .AddJsonFile($"TenantData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json", optional: true) + .SetBasePath(assemblyLocation) + .AddJsonFile(Path.Combine("Seeds", "TenantData.json"), optional: false, reloadOnChange: false) + .AddJsonFile(Path.Combine("Seeds", $"TenantData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), optional: true) .Build(); var items = configuration.Get(); diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantIdentityDataSeeder.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantIdentityDataSeeder.cs similarity index 100% rename from api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantIdentityDataSeeder.cs rename to api/src/Sozsoft.Platform.EntityFrameworkCore/Seeds/TenantIdentityDataSeeder.cs diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Sozsoft.Platform.EntityFrameworkCore.csproj b/api/src/Sozsoft.Platform.EntityFrameworkCore/Sozsoft.Platform.EntityFrameworkCore.csproj index 5c95fa1..8771d48 100644 --- a/api/src/Sozsoft.Platform.EntityFrameworkCore/Sozsoft.Platform.EntityFrameworkCore.csproj +++ b/api/src/Sozsoft.Platform.EntityFrameworkCore/Sozsoft.Platform.EntityFrameworkCore.csproj @@ -8,19 +8,23 @@ - - + + PreserveNewest Always - + PreserveNewest Always - + PreserveNewest Always + + PreserveNewest + Always + diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDatabaseViewCreator.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDatabaseViewCreator.cs deleted file mode 100644 index 50b9205..0000000 --- a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantDatabaseViewCreator.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Threading.Tasks; -using Sozsoft.Platform.EntityFrameworkCore; -using Sozsoft.Platform.Enums; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using Volo.Abp.Data; -using Volo.Abp.DependencyInjection; -using Volo.Abp.EntityFrameworkCore; - -namespace Sozsoft.Platform.Data.Seeds; - -/// -/// Database view seeder for creating or updating database views -/// -public class DatabaseViewSeeder : IDataSeedContributor, ITransientDependency -{ - private readonly IDbContextProvider _dbContextProvider; - private readonly ILogger _logger; - - public DatabaseViewSeeder( - IDbContextProvider dbContextProvider, - ILogger logger) - { - _dbContextProvider = dbContextProvider; - _logger = logger; - } - - public async Task SeedAsync(DataSeedContext context) - { - try - { - var dbContext = await _dbContextProvider.GetDbContextAsync(); - - _logger.LogInformation("Starting database view seeding..."); - - _logger.LogInformation("Database view seeding completed successfully."); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error occurred while seeding database views."); - throw; - } - } -} - diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantSeederDto.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantSeederDto.cs deleted file mode 100644 index d0b1551..0000000 --- a/api/src/Sozsoft.Platform.EntityFrameworkCore/Tenants/TenantSeederDto.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using System.Collections.Generic; -using Sozsoft.Platform.Entities; -using Sozsoft.Platform.Public; - -namespace Sozsoft.Platform.Seeds; - -public class TenantSeederDto -{ - //Saas - public List GlobalSearch { get; set; } - public List CustomEndpoints { get; set; } - public List CustomComponents { get; set; } - - //Tanımlamalar - public List Sectors { get; set; } - public List WorkHours { get; set; } - public List UomCategories { get; set; } - public List Uoms { get; set; } - public List SkillTypes { get; set; } - public List Skills { get; set; } - public List SkillLevels { get; set; } - - public List Abouts { get; set; } - public List Services { get; set; } - public List PaymentMethods { get; set; } - public List InstallmentOptions { get; set; } - public List BlogCategories { get; set; } - public List BlogPosts { get; set; } - public List Products { get; set; } - public List Contacts { get; set; } - - //Report Templates - public List ReportCategories { get; set; } - public List ReportTemplates { get; set; } - - public List ForumCategories { get; set; } -} - -public class GlobalSearchSeedDto -{ - public string System { get; set; } - public string Group { get; set; } - public string Term { get; set; } - public string Weight { get; set; } - public string Url { get; set; } -} - -public class SectorSeedDto -{ - public string Name { get; set; } -} - -public class UomCategorySeedDto -{ - public Guid Id { get; set; } - - public string Name { get; set; } -} - -public class UomSeedDto -{ - public string Name { get; set; } - public string Type { get; set; } - public decimal Ratio { get; set; } - public bool IsActive { get; set; } - public decimal Rounding { get; set; } - public string UomCategoryName { get; set; } -} - -public class SkillTypeSeedDto -{ - public string Name { get; set; } -} - -public class SkillSeedDto -{ - public string Name { get; set; } - public string SkillTypeName { get; set; } -} - -public class SkillLevelSeedDto -{ - public string Name { get; set; } - public int Progress { get; set; } - public bool IsDefault { get; set; } - public string SkillTypeName { get; set; } -} - -public class BlogCategorySeedDto -{ - public string Name { get; set; } - public string Slug { get; set; } - public string Description { get; set; } - public int DisplayOrder { get; set; } - public int PostCount { get; set; } -} - -public class BlogPostSeedDto -{ - public string Title { get; set; } - public string Slug { get; set; } - public string ContentTr { get; set; } - public string ContentEn { get; set; } - public string ReadTime { get; set; } - public string Summary { get; set; } - public string CoverImage { get; set; } - public string CategoryName { get; set; } - public string UserName { get; set; } - public bool IsPublished { get; set; } - public DateTime PublishedAt { get; set; } -} - -public class ForumCategorySeedDto -{ - public string Name { get; set; } - public string Slug { get; set; } - public string Description { get; set; } - public string Icon { get; set; } - public int DisplayOrder { get; set; } - public bool IsActive { get; set; } -} - -public class CustomEndpointSeedDto -{ - public string Name { get; set; } - public string Description { get; set; } - public string Url { get; set; } - public string Method { get; set; } - public string DataSourceCode { get; set; } - public string Sql { get; set; } - public List ParametersJson { get; set; } - public List PermissionsJson { get; set; } -} - -public class PaymentMethodSeedDto -{ - public string Name { get; set; } - public decimal Commission { get; set; } - public string Logo { get; set; } -} - -public class InstallmentOptionSeedDto -{ - public int Installment { get; set; } - public string Name { get; set; } - public decimal Commission { get; set; } -} - -public class CustomComponentSeedDto -{ - public string Name { get; set; } - public string Code { get; set; } - public string Props { get; set; } - public string Description { get; set; } - public bool IsActive { get; set; } - public List Dependencies { get; set; } = new(); -} - -public class ReportTemplateSeedDto -{ - public string Name { get; set; } - public string Description { get; set; } - public string CategoryName { get; set; } - public string HtmlContent { get; set; } - public string Status { get; set; } -} - -public class ReportCategorySeedDto -{ - public string Name { get; set; } - public string Description { get; set; } - public string Icon { get; set; } -} - -public class ServiceSeedDto -{ - public string Icon { get; set; } - public string Title { get; set; } - public string Description { get; set; } - public string Type { get; set; } - public string[] Features { get; set; } -} - -public class AboutSeedDto -{ - public List Stats { get; set; } - public List Descriptions { get; set; } - public List Sections { get; set; } -} - -public class WorkHourSeedDto -{ - public string Name { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public bool? IsFixed { get; set; } - public bool? Monday { get; set; } - public bool? Tuesday { get; set; } - public bool? Wednesday { get; set; } - public bool? Thursday { get; set; } - public bool? Friday { get; set; } - public bool? Saturday { get; set; } - public bool? Sunday { get; set; } -} - -public class ContactSeedDto -{ - public string Address { get; set; } - public string PhoneNumber { get; set; } - public string Email { get; set; } - public string Location { get; set; } - public long TaxNumber { get; set; } - public BankDto Bank { get; set; } - public WorkHoursDto WorkHour { get; set; } - public MapDto Map { get; set; } -} - -public class ProductSeedDto -{ - public string Name { get; set; } - public string Description { get; set; } - public string Category { get; set; } - public int Order { get; set; } - public decimal? MonthlyPrice { get; set; } - public decimal? YearlyPrice { get; set; } - public bool IsQuantityBased { get; set; } - public string ImageUrl { get; set; } -} \ No newline at end of file