From 94b0d17c26f752edb64dec5c7effe3b8c7cc6d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Thu, 9 Oct 2025 22:53:36 +0300 Subject: [PATCH] Branch Seeder Dialog --- .../Branch/BranchAppService.cs | 338 ++++++++++++++++++ .../Branch}/BranchSeederDto.cs | 0 .../Branch}/Seeds/BranchData.Dev.json | 0 .../Branch}/Seeds/BranchData.Production.json | 0 .../Branch}/Seeds/BranchData.json | 140 ++++---- .../Kurs.Platform.Application.csproj | 17 +- .../Kurs.Platform.DbMigrator.csproj | 13 - .../Seeds/PlatformBranchDataSeeder.cs | 221 ------------ .../Seeds/PlatformListFormsSeeder.cs | 14 +- ui/src/proxy/branch/seed.ts | 14 + ui/src/services/branch.ts | 13 + .../admin/role-management/RolesPermission.tsx | 1 - ui/src/views/branch/BranchSeed.tsx | 143 ++++++++ .../DialogContext/DialogShowComponent.tsx | 39 +- 14 files changed, 626 insertions(+), 327 deletions(-) create mode 100644 api/src/Kurs.Platform.Application/Branch/BranchAppService.cs rename api/src/{Kurs.Platform.DbMigrator/Seeds => Kurs.Platform.Application/Branch}/BranchSeederDto.cs (100%) rename api/src/{Kurs.Platform.DbMigrator => Kurs.Platform.Application/Branch}/Seeds/BranchData.Dev.json (100%) rename api/src/{Kurs.Platform.DbMigrator => Kurs.Platform.Application/Branch}/Seeds/BranchData.Production.json (100%) rename api/src/{Kurs.Platform.DbMigrator => Kurs.Platform.Application/Branch}/Seeds/BranchData.json (89%) delete mode 100644 api/src/Kurs.Platform.DbMigrator/Seeds/PlatformBranchDataSeeder.cs create mode 100644 ui/src/proxy/branch/seed.ts create mode 100644 ui/src/services/branch.ts create mode 100644 ui/src/views/branch/BranchSeed.tsx diff --git a/api/src/Kurs.Platform.Application/Branch/BranchAppService.cs b/api/src/Kurs.Platform.Application/Branch/BranchAppService.cs new file mode 100644 index 00000000..3233895e --- /dev/null +++ b/api/src/Kurs.Platform.Application/Branch/BranchAppService.cs @@ -0,0 +1,338 @@ +using System; +using System.IO; +using System.Text.Json; +using System.Threading.Tasks; +using Kurs.Platform.Entities; +using Kurs.Platform.Seeds; +using Microsoft.Extensions.Configuration; +using Volo.Abp.Data; +using Volo.Abp.Domain.Repositories; +using Microsoft.EntityFrameworkCore; +using Kurs.Languages.Entities; +using Kurs.Settings.Entities; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Authorization; + +namespace Kurs.Platform.Branchs; + +public class BranchSeedResultDto +{ + public bool Success { get; set; } + public string Message { get; set; } + public int TotalInsertedCount => Details.Sum(x => x.InsertedCount); + public List Details { get; set; } = new(); +} + +public class SeedDetailDto +{ + public string EntityName { get; set; } = string.Empty; // Örn: "RegistrationType" + public int InsertedCount { get; set; } + public List InsertedItems { get; set; } = new(); // Eklenen kayıtların isimleri + public List Warnings { get; set; } = new(); // Varsa uyarılar + public List Errors { get; set; } = new(); // Varsa hatalar +} + +[Authorize] +public class BranchAppService : PlatformAppService +{ + private readonly IRepository _branchRepository; + private readonly IRepository _languages; + private readonly IRepository _languageKey; + private readonly IRepository _languagesText; + private readonly IRepository _dataSources; + private readonly IRepository _settings; + private readonly IRepository _registrationTypeRepository; + private readonly IRepository _registrationMethodRepository; + private readonly IRepository _classTypeRepository; + private readonly IRepository _classRepository; + private readonly IRepository _levelRepository; + private readonly IRepository _lessonPeriodRepository; + private readonly IRepository _scheduleRepository; + + public BranchAppService( + IRepository branchRepository, + IRepository languages, + IRepository languageKey, + IRepository languagesText, + IRepository dataSource, + IRepository settings, + IRepository scheduleRepository, + IRepository lessonPeriodRepository, + IRepository registrationTypeRepository, + IRepository registrationMethodRepository, + IRepository classTypeRepository, + IRepository classRepository, + IRepository levelRepository + ) + { + _branchRepository = branchRepository; + _languages = languages; + _languageKey = languageKey; + _languagesText = languagesText; + _dataSources = dataSource; + _settings = settings; + _registrationTypeRepository = registrationTypeRepository; + _registrationMethodRepository = registrationMethodRepository; + _classTypeRepository = classTypeRepository; + _classRepository = classRepository; + _levelRepository = levelRepository; + _lessonPeriodRepository = lessonPeriodRepository; + _scheduleRepository = scheduleRepository; + } + + public async Task SeedAsync(Guid branchId) + { + 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 result = new BranchSeedResultDto(); + var context = new DataSeedContext(branchId); + + try + { + var branch = await _branchRepository.FirstOrDefaultAsync(x => x.Id == branchId); + if (branch == null) + { + result.Success = false; + result.Message = "Branch not found."; + return result; + } + + var tenantId = branch.TenantId; + var assemblyPath = Path.GetDirectoryName(typeof(BranchAppService).Assembly.Location)!; + var basePath = Path.Combine(assemblyPath, "Branch", "Seeds"); + + var configuration = new ConfigurationBuilder() + .SetBasePath(basePath) + .AddJsonFile("BranchData.json") + .AddJsonFile($"BranchData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json", optional: true) + .Build(); + + var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; + var items = configuration.Get(); + + if (items == null) + { + result.Success = false; + result.Message = "BranchData.json okunamadı veya format hatalı."; + return result; + } + + // Yardımcı fonksiyon: kolay log ekleme + SeedDetailDto CreateLog(string entity) => + new() + { + EntityName = entity, + InsertedCount = 0, + InsertedItems = [] + }; + + + var registrationTypeLog = CreateLog(nameof(RegistrationType)); + foreach (var item in items.RegistrationTypes) + { + var exists = await _registrationTypeRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + await _registrationTypeRepository.InsertAsync(new RegistrationType + { + TenantId = tenantId, + BranchId = branchId, + Name = item.Name, + Status = item.Status + }, autoSave: true); + + registrationTypeLog.InsertedCount++; + registrationTypeLog.InsertedItems.Add(item.Name); + } + } + result.Details.Add(registrationTypeLog); + + var registrationMethodLog = CreateLog(nameof(RegistrationMethod)); + foreach (var item in items.RegistrationMethods) + { + var exists = await _registrationMethodRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + var registrationType = await _registrationTypeRepository.FirstOrDefaultAsync(x => x.Name == item.RegistrationTypeName); + if (registrationType != null) + { + await _registrationMethodRepository.InsertAsync(new RegistrationMethod + { + TenantId = tenantId, + BranchId = branchId, + RegistrationTypeId = registrationType.Id, + Name = item.Name, + Status = item.Status + }); + + registrationMethodLog.InsertedCount++; + registrationMethodLog.InsertedItems.Add(item.Name); + } + } + } + result.Details.Add(registrationMethodLog); + + var classTypeLog = CreateLog(nameof(ClassType)); + foreach (var item in items.ClassTypes) + { + var exists = await _classTypeRepository.AnyAsync(x => x.Name == item.Name); + + if (!exists) + { + var registrationType = await _registrationTypeRepository.FirstOrDefaultAsync(x => x.Name == item.RegistrationTypeName && x.BranchId == branchId); + if (registrationType != null) + { + await _classTypeRepository.InsertAsync(new ClassType + { + TenantId = tenantId, + BranchId = branchId, + RegistrationTypeId = registrationType.Id, + Name = item.Name, + MinStudentCount = item.MinStudentCount, + MaxStudentCount = item.MaxStudentCount, + Status = item.Status + }, autoSave: true); + + classTypeLog.InsertedCount++; + classTypeLog.InsertedItems.Add(item.Name); + } + } + } + result.Details.Add(classTypeLog); + + var classLog = CreateLog(nameof(Class)); + foreach (var item in items.Classes) + { + var exists = await _classRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + var classType = await _classTypeRepository.FirstOrDefaultAsync(x => x.Name == item.ClassTypeName); + if (classType != null) + { + await _classRepository.InsertAsync(new() + { + TenantId = tenantId, + BranchId = branchId, + ClassTypeId = classType.Id, + Name = item.Name, + Status = item.Status, + }); + + classLog.InsertedCount++; + classLog.InsertedItems.Add(item.Name); + } + } + } + result.Details.Add(classLog); + + var levelLog = CreateLog(nameof(Level)); + foreach (var item in items.Levels) + { + var exists = await _levelRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + var classType = await _classTypeRepository.FirstOrDefaultAsync(x => x.Name == item.ClassTypeName); + if (classType != null) + { + await _levelRepository.InsertAsync(new Level + { + TenantId = tenantId, + BranchId = branchId, + ClassTypeId = classType.Id, + Name = item.Name, + LevelType = item.LevelType, + LessonCount = item.LessonCount, + Status = item.Status, + LessonDuration = item.LessonDuration, + MonthlyPaymentRate = item.MonthlyPaymentRate + }); + + levelLog.InsertedCount++; + levelLog.InsertedItems.Add(item.Name); + } + } + } + result.Details.Add(levelLog); + + var lessonPeriodLog = CreateLog(nameof(LessonPeriod)); + foreach (var item in items.LessonPeriods) + { + var exists = await _lessonPeriodRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + await _lessonPeriodRepository.InsertAsync(new() + { + TenantId = tenantId, + BranchId = branchId, + Name = item.Name, + Day = item.Day, + Lesson1 = item.Lesson1, + Lesson2 = item.Lesson2, + Lesson3 = item.Lesson3, + Lesson4 = item.Lesson4, + }); + + lessonPeriodLog.InsertedCount++; + lessonPeriodLog.InsertedItems.Add(item.Name); + } + } + result.Details.Add(lessonPeriodLog); + + var scheduleLog = CreateLog(nameof(Schedule)); + foreach (var item in items.Schedules) + { + var exists = await _scheduleRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId); + + if (!exists) + { + await _scheduleRepository.InsertAsync(new() + { + TenantId = tenantId, + BranchId = branchId, + Name = item.Name, + Status = item.Status, + StartTime = item.StartTime, + EndTime = item.EndTime, + LessonMinute = item.LessonMinute, + LessonBreakMinute = item.LessonBreakMinute, + LessonCount = item.LessonCount, + LunchTime = item.LunchTime, + LunchMinute = item.LunchMinute, + IncludeLunch = item.IncludeLunch, + Monday = item.Monday, + Tuesday = item.Tuesday, + Wednesday = item.Wednesday, + Thursday = item.Thursday, + Friday = item.Friday, + Saturday = item.Saturday, + Sunday = item.Sunday, + }); + + scheduleLog.InsertedCount++; + scheduleLog.InsertedItems.Add(item.Name); + } + } + result.Details.Add(scheduleLog); + + result.Success = true; + result.Message = $"Seed işlemi başarıyla tamamlandı. Toplam {result.TotalInsertedCount} kayıt eklendi."; + return result; + } + catch (Exception ex) + { + result.Success = false; + result.Message = $"Hata: {ex.Message}"; + return result; + } + } +} diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/BranchSeederDto.cs b/api/src/Kurs.Platform.Application/Branch/BranchSeederDto.cs similarity index 100% rename from api/src/Kurs.Platform.DbMigrator/Seeds/BranchSeederDto.cs rename to api/src/Kurs.Platform.Application/Branch/BranchSeederDto.cs diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.Dev.json b/api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.Dev.json similarity index 100% rename from api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.Dev.json rename to api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.Dev.json diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.Production.json b/api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.Production.json similarity index 100% rename from api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.Production.json rename to api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.Production.json diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.json b/api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.json similarity index 89% rename from api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.json rename to api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.json index 280de31e..66a84d39 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/BranchData.json +++ b/api/src/Kurs.Platform.Application/Branch/Seeds/BranchData.json @@ -79,8 +79,8 @@ "Levels": [ { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "A1", + "Name": "A1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": 2, @@ -88,8 +88,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "A2", + "Name": "A2", + "LevelType": "Seviye", "LessonCount": 90, "Status": "Aktif", "LessonDuration": 3, @@ -97,8 +97,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "B1", + "Name": "B1", + "LevelType": "Seviye", "LessonCount": 90, "Status": "Aktif", "LessonDuration": null, @@ -106,8 +106,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "B2", + "Name": "B2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -115,8 +115,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "C1", + "Name": "C1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -124,8 +124,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Seviye", - "LevelType": "C2", + "Name": "C2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -133,8 +133,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "BULATS", + "Name": "BULATS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -142,8 +142,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "GMAT", + "Name": "GMAT", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -151,8 +151,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "YDS", + "Name": "YDS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -160,8 +160,8 @@ }, { "ClassTypeName": "3-6 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "ÜDS", + "Name": "ÜDS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -169,8 +169,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "A1", + "Name": "A1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": 3, @@ -178,8 +178,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "A2", + "Name": "A2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -187,8 +187,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "B1", + "Name": "B1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -196,8 +196,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "B2", + "Name": "B2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -205,8 +205,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "C1", + "Name": "C1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -214,8 +214,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Seviye", - "LevelType": "C2", + "Name": "C2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -223,8 +223,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "IELTS", + "Name": "IELTS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -232,8 +232,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "TOEFL", + "Name": "TOEFL", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -241,8 +241,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "BULATS", + "Name": "BULATS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -250,8 +250,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "GMAT", + "Name": "GMAT", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -259,8 +259,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "YDS", + "Name": "YDS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -268,8 +268,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "PROFICIENCY", + "Name": "PROFICIENCY", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -277,8 +277,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "SAT", + "Name": "SAT", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -286,8 +286,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "TOEIC", + "Name": "TOEIC", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -295,8 +295,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "ÜDS", + "Name": "ÜDS", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -304,8 +304,8 @@ }, { "ClassTypeName": "5-8 Kişilik", - "Name": "Sınav Eğitimi", - "LevelType": "SAT2", + "Name": "SAT2", + "LevelType": "Sınav Eğitimi", "LessonCount": 50, "Status": "Aktif", "LessonDuration": null, @@ -313,8 +313,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "A1", + "Name": "A1", + "LevelType": "Seviye", "LessonCount": 60, "Status": "Aktif", "LessonDuration": null, @@ -322,8 +322,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "A2", + "Name": "A2", + "LevelType": "Seviye", "LessonCount": 70, "Status": "Aktif", "LessonDuration": null, @@ -331,8 +331,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "B1", + "Name": "B1", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -340,8 +340,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "B2", + "Name": "B2", + "LevelType": "Seviye", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -349,8 +349,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "C1", + "Name": "C1", + "LevelType": "Seviye", "LessonCount": 90, "Status": "Aktif", "LessonDuration": null, @@ -358,8 +358,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Seviye", - "LevelType": "C2", + "Name": "C2", + "LevelType": "Seviye", "LessonCount": 90, "Status": "Aktif", "LessonDuration": null, @@ -367,8 +367,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Sınav Eğitimi", - "LevelType": "BULATS", + "Name": "BULATS", + "LevelType": "Sınav Eğitimi", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -376,8 +376,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Sınav Eğitimi", - "LevelType": "GMAT", + "Name": "GMAT", + "LevelType": "Sınav Eğitimi", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, @@ -385,8 +385,8 @@ }, { "ClassTypeName": "ÖZEL", - "Name": "Sınav Eğitimi", - "LevelType": "ÜDS", + "Name": "ÜDS", + "LevelType": "Sınav Eğitimi", "LessonCount": 80, "Status": "Aktif", "LessonDuration": null, diff --git a/api/src/Kurs.Platform.Application/Kurs.Platform.Application.csproj b/api/src/Kurs.Platform.Application/Kurs.Platform.Application.csproj index edf965f9..71dbda54 100644 --- a/api/src/Kurs.Platform.Application/Kurs.Platform.Application.csproj +++ b/api/src/Kurs.Platform.Application/Kurs.Platform.Application.csproj @@ -1,17 +1,24 @@  - + - + net9.0 enable Kurs.Platform - + + + + Always + PreserveNewest + + + @@ -19,7 +26,7 @@ - + @@ -27,5 +34,5 @@ - + diff --git a/api/src/Kurs.Platform.DbMigrator/Kurs.Platform.DbMigrator.csproj b/api/src/Kurs.Platform.DbMigrator/Kurs.Platform.DbMigrator.csproj index 83e046e4..bb4374d5 100644 --- a/api/src/Kurs.Platform.DbMigrator/Kurs.Platform.DbMigrator.csproj +++ b/api/src/Kurs.Platform.DbMigrator/Kurs.Platform.DbMigrator.csproj @@ -42,19 +42,6 @@ PreserveNewest Always - - - PreserveNewest - Always - - - PreserveNewest - Always - - - PreserveNewest - Always - PreserveNewest diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformBranchDataSeeder.cs b/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformBranchDataSeeder.cs deleted file mode 100644 index 3f6a125d..00000000 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformBranchDataSeeder.cs +++ /dev/null @@ -1,221 +0,0 @@ -using System; -using System.IO; -using System.Text.Json; -using System.Threading.Tasks; -using Kurs.Platform.Entities; -using Kurs.Platform.Seeds; -using Microsoft.Extensions.Configuration; -using Volo.Abp.Data; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Repositories; -using Microsoft.EntityFrameworkCore; -using Kurs.Languages.Entities; -using Kurs.Settings.Entities; - -namespace Kurs.Platform.Data.Seeds; - -public class PlatformBranchDataSeeder : ITransientDependency -{ - private readonly IRepository _languages; - private readonly IRepository _languageKey; - private readonly IRepository _languagesText; - private readonly IRepository _dataSources; - private readonly IRepository _settings; - private readonly IRepository _registrationTypeRepository; - private readonly IRepository _registrationMethodRepository; - private readonly IRepository _classTypeRepository; - private readonly IRepository _classRepository; - private readonly IRepository _levelRepository; - private readonly IRepository _lessonPeriodRepository; - private readonly IRepository _scheduleRepository; - - public PlatformBranchDataSeeder( - IRepository languages, - IRepository languageKey, - IRepository languagesText, - IRepository dataSource, - IRepository settings, - IRepository scheduleRepository, - IRepository lessonPeriodRepository, - IRepository registrationTypeRepository, - IRepository registrationMethodRepository, - IRepository classTypeRepository, - IRepository classRepository, - IRepository levelRepository - ) - { - _languages = languages; - _languageKey = languageKey; - _languagesText = languagesText; - _dataSources = dataSource; - _settings = settings; - _registrationTypeRepository = registrationTypeRepository; - _registrationMethodRepository = registrationMethodRepository; - _classTypeRepository = classTypeRepository; - _classRepository = classRepository; - _levelRepository = levelRepository; - _lessonPeriodRepository = lessonPeriodRepository; - _scheduleRepository = scheduleRepository; - } - - public async Task SeedAsync(DataSeedContext context) - { - 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", "BranchData.json")) - .AddJsonFile(Path.Combine("Seeds", $"BranchData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), true) - .Build(); - var items = configuration.Get(); - - var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; - - foreach (var item in items.RegistrationTypes) - { - var exists = await _registrationTypeRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - await _registrationTypeRepository.InsertAsync(new RegistrationType - { - Name = item.Name, - Status = item.Status - }, autoSave: true); - } - } - - foreach (var item in items.RegistrationMethods) - { - var exists = await _registrationMethodRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - var registrationType = await _registrationTypeRepository.FirstOrDefaultAsync(x => x.Name == item.RegistrationTypeName); - if (registrationType != null) - { - await _registrationMethodRepository.InsertAsync(new RegistrationMethod - { - RegistrationTypeId = registrationType.Id, - Name = item.Name, - Status = item.Status - }); - } - } - } - - foreach (var item in items.ClassTypes) - { - var exists = await _classTypeRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - var registrationType = await _registrationTypeRepository.FirstOrDefaultAsync(x => x.Name == item.RegistrationTypeName); - if (registrationType != null) - { - await _classTypeRepository.InsertAsync(new ClassType - { - RegistrationTypeId = registrationType.Id, - Name = item.Name, - MinStudentCount = item.MinStudentCount, - MaxStudentCount = item.MaxStudentCount, - Status = item.Status - }, autoSave: true); - } - } - } - - foreach (var item in items.Classes) - { - var exists = await _classRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - var classType = await _classTypeRepository.FirstOrDefaultAsync(x => x.Name == item.ClassTypeName); - if (classType != null) - { - await _classRepository.InsertAsync(new() - { - ClassTypeId = classType.Id, - Name = item.Name, - Status = item.Status, - }); - } - } - } - - foreach (var item in items.Levels) - { - var exists = await _levelRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - var classType = await _classTypeRepository.FirstOrDefaultAsync(x => x.Name == item.ClassTypeName); - if (classType != null) - { - await _levelRepository.InsertAsync(new Level - { - ClassTypeId = classType.Id, - Name = item.Name, - LevelType = item.LevelType, - LessonCount = item.LessonCount, - Status = item.Status, - LessonDuration = item.LessonDuration, - MonthlyPaymentRate = item.MonthlyPaymentRate - }); - } - } - } - - foreach (var item in items.LessonPeriods) - { - var exists = await _lessonPeriodRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - await _lessonPeriodRepository.InsertAsync(new() - { - Name = item.Name, - Day = item.Day, - Lesson1 = item.Lesson1, - Lesson2 = item.Lesson2, - Lesson3 = item.Lesson3, - Lesson4 = item.Lesson4, - }); - } - } - - foreach (var item in items.Schedules) - { - var exists = await _scheduleRepository.AnyAsync(x => x.Name == item.Name); - - if (!exists) - { - await _scheduleRepository.InsertAsync(new() - { - Name = item.Name, - Status = item.Status, - StartTime = item.StartTime, - EndTime = item.EndTime, - LessonMinute = item.LessonMinute, - LessonBreakMinute = item.LessonBreakMinute, - LessonCount = item.LessonCount, - LunchTime = item.LunchTime, - LunchMinute = item.LunchMinute, - IncludeLunch = item.IncludeLunch, - Monday = item.Monday, - Tuesday = item.Tuesday, - Wednesday = item.Wednesday, - Thursday = item.Thursday, - Friday = item.Friday, - Saturday = item.Saturday, - Sunday = item.Sunday, - }); - } - } - } -} diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformListFormsSeeder.cs b/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformListFormsSeeder.cs index 18d97836..ba94bb1e 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformListFormsSeeder.cs +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformListFormsSeeder.cs @@ -3068,8 +3068,18 @@ public class PlatformListFormsSeeder : IDataSeedContributor, ITransientDependenc FieldDbType = DbType.Boolean, Value = "true", CustomValueType = FieldCustomValueTypeEnum.Value } - }) - + }), + CommandColumnJson = JsonSerializer.Serialize(new CommandColumnDto[] { + new() { + Hint = "Seed", + Text = "Seed", + AuthName = AppCodes.Branches + ".Update", + DialogName = "BranchSeed", + DialogParameters = JsonSerializer.Serialize(new { + name = "@Id", + }) + }, + }), } ); diff --git a/ui/src/proxy/branch/seed.ts b/ui/src/proxy/branch/seed.ts new file mode 100644 index 00000000..49f9233c --- /dev/null +++ b/ui/src/proxy/branch/seed.ts @@ -0,0 +1,14 @@ +export interface BranchSeedResultDto { + success: boolean + message: string + totalInsertedCount: number // backend'de => TotalInsertedCount + details: SeedDetailDto[] +} + +export interface SeedDetailDto { + entityName: string // Örn: "RegistrationType", "Class" + insertedCount: number // Kaç kayıt eklendi + insertedItems: string[] // Eklenen kayıtların isimleri + warnings: string[] // Uyarı mesajları (örneğin eksik referans) + errors: string[] // Hatalar (örneğin ekleme başarısızlığı) +} diff --git a/ui/src/services/branch.ts b/ui/src/services/branch.ts new file mode 100644 index 00000000..c17044ad --- /dev/null +++ b/ui/src/services/branch.ts @@ -0,0 +1,13 @@ +import apiService from './api.service' +import { BranchSeedResultDto } from '@/proxy/branch/seed' + +export async function runBranchSeed(branchId: string): Promise { + const response = await apiService.fetchData( + { + method: 'POST', + url: `/api/app/branch/seed/${branchId}`, + }, + { apiName: 'Default' }, + ) + return response.data +} diff --git a/ui/src/views/admin/role-management/RolesPermission.tsx b/ui/src/views/admin/role-management/RolesPermission.tsx index d0a2bed5..73a12c13 100644 --- a/ui/src/views/admin/role-management/RolesPermission.tsx +++ b/ui/src/views/admin/role-management/RolesPermission.tsx @@ -1,4 +1,3 @@ -import AdaptableCard from '@/components/shared/AdaptableCard' import Container from '@/components/shared/Container' import { Button, Checkbox, Dialog, Input, Menu, toast } from '@/components/ui' import { useConfig } from '@/components/ui/ConfigProvider' diff --git a/ui/src/views/branch/BranchSeed.tsx b/ui/src/views/branch/BranchSeed.tsx new file mode 100644 index 00000000..b962ce9a --- /dev/null +++ b/ui/src/views/branch/BranchSeed.tsx @@ -0,0 +1,143 @@ +import { useState } from 'react' +import { Button } from '@/components/ui' +import { Container } from '@/components/shared' +import { Dialog, Notification, toast } from '@/components/ui' +import type { BranchSeedResultDto } from '@/proxy/branch/seed' +import { runBranchSeed } from '@/services/branch' + +function BranchSeed({ + open, + onDialogClose, + name, +}: { + open: boolean + onDialogClose: () => void + name: string +}) { + const [isLoading, setIsLoading] = useState(false) + const [result, setResult] = useState(null) + + const handleRunSeed = async () => { + if (!name) return + setIsLoading(true) + try { + const data = await runBranchSeed(name) + setResult(data) + + if (data.success) { + toast.push(, { + placement: 'top-end', + }) + } else { + toast.push(, { + placement: 'top-end', + }) + } + } catch (error) { + console.error(error) + setResult({ + success: false, + message: 'Seed işlemi sırasında hata oluştu.', + totalInsertedCount: 0, + details: [], + }) + toast.push(, { + placement: 'top-end', + }) + } finally { + setIsLoading(false) + } + } + + return ( + + +
Branch Seed - {name}
+
+ + {/* Başlat butonu */} +
+ +
+ + {/* Sonuç */} + {result && ( +
+
+ {result.success ? ( + ✅ Seed İşlemi Başarılı + ) : ( + ❌ Seed İşlemi Başarısız + )} +
+ +

{result.message}

+ +

+ Toplam eklenen kayıt:{' '} + {result.totalInsertedCount} +

+ + {/* Detay Tablosu */} + {result.details.length > 0 && ( +
+ + + + + + + + + + + {result.details.map((d) => ( + + + + {/* Eklenen kolonunu tek satır formatında göster */} + + + + + + + ))} + +
EntityEklenenUyarılarHatalar
+ {d.entityName} + + {d.insertedCount > 0 + ? `${d.insertedCount} - { ${d.insertedItems.join(', ')} }` + : '—'} + + {d.warnings.length > 0 + ? `${d.warnings.length} - { ${d.warnings.join(', ')} }` + : '—'} + + {d.errors.length > 0 + ? `${d.errors.length} - { ${d.errors.join(', ')} }` + : '—'} +
+
+ )} + + {!result.details.length && ( +

Hiç detay bilgisi bulunamadı.

+ )} +
+ )} +
+
+ ) +} + +export default BranchSeed diff --git a/ui/src/views/shared/DialogContext/DialogShowComponent.tsx b/ui/src/views/shared/DialogContext/DialogShowComponent.tsx index 04d48f11..6ae7095b 100644 --- a/ui/src/views/shared/DialogContext/DialogShowComponent.tsx +++ b/ui/src/views/shared/DialogContext/DialogShowComponent.tsx @@ -4,6 +4,7 @@ import CreateNotification from '@/views/admin/notification/CreateNotification' import AuditLogDetail from '@/views/admin/auditLog/AuditLogDetail' import RolesPermission from '@/views/admin/role-management/RolesPermission' import UsersPermission from '@/views/admin/user-management/UsersPermission' +import BranchSeed from '@/views/branch/BranchSeed' const DialogShowComponent = (): JSX.Element => { const dialogContext: any = useDialogContext() @@ -35,21 +36,29 @@ const DialogShowComponent = (): JSX.Element => { > ) case 'CreateNotification': - return ( - dialogContext.setConfig({})} - {...dialogContext.config?.props} - > - ) - case 'AuditLogDetail': - return ( - dialogContext.setConfig({})} - {...dialogContext.config?.props} - > - ) + return ( + dialogContext.setConfig({})} + {...dialogContext.config?.props} + > + ) + case 'AuditLogDetail': + return ( + dialogContext.setConfig({})} + {...dialogContext.config?.props} + > + ) + case 'BranchSeed': + return ( + dialogContext.setConfig({})} + {...dialogContext.config?.props} + > + ) default: return <> }