2025-11-11 19:49:52 +00:00
|
|
|
|
using System;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
using Volo.Abp.Domain.Services;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
2025-11-11 19:49:52 +00:00
|
|
|
|
using Erp.Platform.Entities;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-11 19:49:52 +00:00
|
|
|
|
namespace Erp.Platform.Branchs;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
|
|
|
|
|
public class BranchSeedManager : DomainService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepository<Branch, Guid> _branchRepository;
|
|
|
|
|
|
private readonly IRepository<RegistrationType, Guid> _registrationTypeRepository;
|
|
|
|
|
|
private readonly IRepository<RegistrationMethod, Guid> _registrationMethodRepository;
|
|
|
|
|
|
private readonly IRepository<ClassType, Guid> _classTypeRepository;
|
|
|
|
|
|
private readonly IRepository<Class, Guid> _classRepository;
|
|
|
|
|
|
private readonly IRepository<Level, Guid> _levelRepository;
|
|
|
|
|
|
private readonly IRepository<LessonPeriod, Guid> _lessonPeriodRepository;
|
|
|
|
|
|
private readonly IRepository<Schedule, Guid> _scheduleRepository;
|
2025-10-24 15:00:36 +00:00
|
|
|
|
private readonly IRepository<Meal, Guid> _mealRepository;
|
2025-11-25 19:55:52 +00:00
|
|
|
|
private readonly IRepository<Bank, Guid> _bankRepository;
|
|
|
|
|
|
private readonly IRepository<Cash, Guid> _cashRepository;
|
|
|
|
|
|
private readonly IRepository<CurrentAccount, Guid> _currentAccountRepository;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
|
|
|
|
|
public BranchSeedManager(
|
|
|
|
|
|
IRepository<Branch, Guid> branchRepository,
|
|
|
|
|
|
IRepository<RegistrationType, Guid> registrationTypeRepository,
|
|
|
|
|
|
IRepository<RegistrationMethod, Guid> registrationMethodRepository,
|
|
|
|
|
|
IRepository<ClassType, Guid> classTypeRepository,
|
|
|
|
|
|
IRepository<Class, Guid> classRepository,
|
|
|
|
|
|
IRepository<Level, Guid> levelRepository,
|
|
|
|
|
|
IRepository<LessonPeriod, Guid> lessonPeriodRepository,
|
2025-10-24 15:00:36 +00:00
|
|
|
|
IRepository<Schedule, Guid> scheduleRepository,
|
2025-11-25 19:55:52 +00:00
|
|
|
|
IRepository<Meal, Guid> mealRepository,
|
|
|
|
|
|
IRepository<Bank, Guid> bankRepository,
|
|
|
|
|
|
IRepository<Cash, Guid> cashRepository,
|
|
|
|
|
|
IRepository<CurrentAccount, Guid> currentAccountRepository
|
2025-10-24 15:00:36 +00:00
|
|
|
|
)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
_branchRepository = branchRepository;
|
|
|
|
|
|
_registrationTypeRepository = registrationTypeRepository;
|
|
|
|
|
|
_registrationMethodRepository = registrationMethodRepository;
|
|
|
|
|
|
_classTypeRepository = classTypeRepository;
|
|
|
|
|
|
_classRepository = classRepository;
|
|
|
|
|
|
_levelRepository = levelRepository;
|
|
|
|
|
|
_lessonPeriodRepository = lessonPeriodRepository;
|
|
|
|
|
|
_scheduleRepository = scheduleRepository;
|
2025-10-24 15:00:36 +00:00
|
|
|
|
_mealRepository = mealRepository;
|
2025-11-25 19:55:52 +00:00
|
|
|
|
_bankRepository = bankRepository;
|
|
|
|
|
|
_cashRepository = cashRepository;
|
|
|
|
|
|
_currentAccountRepository = currentAccountRepository;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<BranchSeedResult> SeedRecordsAsync(Guid? tenantId, Guid branchId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = new BranchSeedResult();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var assemblyPath = Path.GetDirectoryName(typeof(BranchSeedManager).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<BranchSeederDto>();
|
|
|
|
|
|
|
|
|
|
|
|
if (items == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Success = false;
|
2025-11-12 12:59:31 +00:00
|
|
|
|
result.Message = "BranchData.json okunamadı veya format hatalı.";
|
2025-10-09 21:13:38 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 12:59:31 +00:00
|
|
|
|
// Yardımcı fonksiyon: kolay log ekleme
|
2025-10-09 21:13:38 +00:00
|
|
|
|
BranchSeedDetail CreateLog(string entity) =>
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityName = entity,
|
|
|
|
|
|
InsertedCount = 0,
|
|
|
|
|
|
InsertedItems = []
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.RegistrationTypes.Count > 0)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var registrationTypeLog = CreateLog(nameof(RegistrationType));
|
|
|
|
|
|
foreach (var item in items.RegistrationTypes)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var exists = await _registrationTypeRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (!exists)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
await _registrationTypeRepository.InsertAsync(new RegistrationType
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Status = item.Status
|
2025-11-04 08:15:42 +00:00
|
|
|
|
}, autoSave: true);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
registrationTypeLog.InsertedCount++;
|
|
|
|
|
|
registrationTypeLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\" " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-04 08:15:42 +00:00
|
|
|
|
result.Details.Add(registrationTypeLog);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.RegistrationMethods.Count > 0)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
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(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\", " +
|
|
|
|
|
|
$"\"registrationType\": \"{item.RegistrationTypeName}\" " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(registrationMethodLog);
|
|
|
|
|
|
}
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.ClassTypes.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var classTypeLog = CreateLog(nameof(ClassType));
|
|
|
|
|
|
foreach (var item in items.ClassTypes)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var exists = await _classTypeRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var registrationType = await _registrationTypeRepository.FirstOrDefaultAsync(x => x.Name == item.RegistrationTypeName && x.BranchId == branchId);
|
|
|
|
|
|
if (registrationType != null)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
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(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\", " +
|
|
|
|
|
|
$"\"registrationType\": \"{item.RegistrationTypeName}\", " +
|
|
|
|
|
|
$"\"minStudentCount\": {item.MinStudentCount}, " +
|
|
|
|
|
|
$"\"maxStudentCount\": {item.MaxStudentCount} " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(classTypeLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (items.Classes.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var classLog = CreateLog(nameof(Class));
|
|
|
|
|
|
foreach (var item in items.Classes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _classRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
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(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\", " +
|
|
|
|
|
|
$"\"classType\": \"{item.ClassTypeName}\" " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-04 08:15:42 +00:00
|
|
|
|
result.Details.Add(classLog);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.Levels.Count > 0)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
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,
|
|
|
|
|
|
LevelType = item.LevelType,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Order = item.Order,
|
|
|
|
|
|
LessonCount = item.LessonCount,
|
|
|
|
|
|
LessonDuration = item.LessonDuration,
|
|
|
|
|
|
Status = item.Status,
|
|
|
|
|
|
MonthlyPaymentRate = item.MonthlyPaymentRate
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
levelLog.InsertedCount++;
|
|
|
|
|
|
levelLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\", " +
|
|
|
|
|
|
$"\"classType\": \"{item.ClassTypeName}\", " +
|
|
|
|
|
|
$"\"levelType\": \"{item.LevelType}\", " +
|
|
|
|
|
|
$"\"order\": {item.Order}, " +
|
|
|
|
|
|
$"\"lessonCount\": {item.LessonCount}, " +
|
|
|
|
|
|
$"\"lessonDuration\": {item.LessonDuration}, " +
|
|
|
|
|
|
$"\"monthlyPaymentRate\": {item.MonthlyPaymentRate} " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(levelLog);
|
|
|
|
|
|
}
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.LessonPeriods.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var lessonPeriodLog = CreateLog(nameof(LessonPeriod));
|
|
|
|
|
|
foreach (var item in items.LessonPeriods)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var exists = await _lessonPeriodRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
await _lessonPeriodRepository.InsertAsync(new()
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Name = item.Name,
|
2025-11-04 08:15:42 +00:00
|
|
|
|
Day = item.Day,
|
|
|
|
|
|
Lesson1 = item.Lesson1,
|
|
|
|
|
|
Lesson2 = item.Lesson2,
|
|
|
|
|
|
Lesson3 = item.Lesson3,
|
|
|
|
|
|
Lesson4 = item.Lesson4,
|
2025-10-09 21:13:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
lessonPeriodLog.InsertedCount++;
|
|
|
|
|
|
lessonPeriodLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"day\": \"{item.Day}\", " +
|
|
|
|
|
|
$"\"lesson1\": \"{item.Lesson1}\", " +
|
|
|
|
|
|
$"\"lesson2\": \"{item.Lesson2}\", " +
|
|
|
|
|
|
$"\"lesson3\": \"{item.Lesson3}\", " +
|
|
|
|
|
|
$"\"lesson4\": \"{item.Lesson4}\" " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-04 08:15:42 +00:00
|
|
|
|
result.Details.Add(lessonPeriodLog);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.Schedules.Count > 0)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var scheduleLog = CreateLog(nameof(Schedule));
|
|
|
|
|
|
foreach (var item in items.Schedules)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var exists = await _scheduleRepository.AnyAsync(x => x.Name == item.Name && x.BranchId == branchId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
await _scheduleRepository.InsertAsync(new()
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
2025-10-10 07:11:32 +00:00
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Status = item.Status,
|
2025-11-04 08:15:42 +00:00
|
|
|
|
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,
|
2025-10-09 21:13:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
scheduleLog.InsertedCount++;
|
|
|
|
|
|
scheduleLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ \"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"\"status\": \"{item.Status}\", " +
|
|
|
|
|
|
$"\"startTime\": \"{item.StartTime:HH\\:mm}\", " +
|
|
|
|
|
|
$"\"endTime\": \"{item.EndTime:HH\\:mm}\", " +
|
|
|
|
|
|
$"\"lessonMinute\": {item.LessonMinute}, " +
|
|
|
|
|
|
$"\"lessonBreakMinute\": {item.LessonBreakMinute}, " +
|
|
|
|
|
|
$"\"lessonCount\": {item.LessonCount}, " +
|
|
|
|
|
|
$"\"lunchTime\": \"{item.LunchTime:HH\\:mm}\", " +
|
|
|
|
|
|
$"\"lunchMinute\": {item.LunchMinute}, " +
|
|
|
|
|
|
$"\"includeLunch\": {item.IncludeLunch.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"monday\": {item.Monday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"tuesday\": {item.Tuesday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"wednesday\": {item.Wednesday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"thursday\": {item.Thursday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"friday\": {item.Friday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"saturday\": {item.Saturday.ToString().ToLower()}, " +
|
|
|
|
|
|
$"\"sunday\": {item.Sunday.ToString().ToLower()} }}"
|
|
|
|
|
|
);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-04 08:15:42 +00:00
|
|
|
|
result.Details.Add(scheduleLog);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
if (items.Meals.Count > 0)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var mealLog = CreateLog(nameof(Meal));
|
|
|
|
|
|
foreach (var item in items.Meals)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
var exists = await _mealRepository.AnyAsync(x => x.Date == item.Date && x.BranchId == branchId);
|
|
|
|
|
|
if (!exists)
|
2025-10-09 21:13:38 +00:00
|
|
|
|
{
|
2025-11-04 08:15:42 +00:00
|
|
|
|
await _mealRepository.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Date = item.Date,
|
|
|
|
|
|
TotalCalorie = item.TotalCalorie,
|
|
|
|
|
|
Materials = item.Materials,
|
|
|
|
|
|
}, autoSave: true);
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
mealLog.InsertedCount++;
|
2025-10-09 21:13:38 +00:00
|
|
|
|
|
2025-11-04 08:15:42 +00:00
|
|
|
|
mealLog.InsertedItems.Add($"{{ \"date\": \"{item.Date:yyyy-MM-dd}\", \"type\": \"{item.Type}\", \"materials\": \"{item.Materials.Replace("|", ", ")}\" }}");
|
|
|
|
|
|
}
|
2025-10-24 15:00:36 +00:00
|
|
|
|
}
|
2025-11-04 08:15:42 +00:00
|
|
|
|
result.Details.Add(mealLog);
|
2025-10-24 15:00:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-25 19:55:52 +00:00
|
|
|
|
if (items.Banks.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var bankLog = CreateLog(nameof(Bank));
|
|
|
|
|
|
foreach (var item in items.Banks)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _bankRepository.AnyAsync(x => x.Code == item.Code && x.BranchId == branchId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _bankRepository.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Address1 = item.Address1,
|
|
|
|
|
|
Address2 = item.Address2,
|
|
|
|
|
|
Country = item.Country,
|
|
|
|
|
|
City = item.City,
|
|
|
|
|
|
District = item.District,
|
|
|
|
|
|
PostalCode = item.PostalCode,
|
|
|
|
|
|
PhoneNumber = item.PhoneNumber,
|
|
|
|
|
|
Email = item.Email
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
bankLog.InsertedCount++;
|
|
|
|
|
|
bankLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"code\": \"{item.Code}\", " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(bankLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (items.Cashes.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var cashLog = CreateLog(nameof(Cash));
|
|
|
|
|
|
foreach (var item in items.Cashes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _cashRepository.AnyAsync(x => x.Code == item.Code && x.BranchId == branchId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _cashRepository.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Description = item.Description,
|
|
|
|
|
|
Currency = item.Currency,
|
|
|
|
|
|
Balance = item.Balance,
|
|
|
|
|
|
IsActive = item.IsActive
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
cashLog.InsertedCount++;
|
|
|
|
|
|
cashLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"code\": \"{item.Code}\", " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(cashLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (items.CurrentAccounts.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var currentAccountLog = CreateLog(nameof(CurrentAccount));
|
|
|
|
|
|
foreach (var item in items.CurrentAccounts)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _currentAccountRepository.AnyAsync(x => x.Code == item.Code && x.BranchId == branchId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _currentAccountRepository.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
|
BranchId = branchId,
|
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Description = item.Description,
|
|
|
|
|
|
TaxNumber = item.TaxNumber,
|
|
|
|
|
|
TaxOffice = item.TaxOffice,
|
|
|
|
|
|
CreditLimit = item.CreditLimit,
|
|
|
|
|
|
Balance = item.Balance,
|
|
|
|
|
|
Currency = item.Currency,
|
|
|
|
|
|
Risk = item.Risk,
|
|
|
|
|
|
IsActive = item.IsActive
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
currentAccountLog.InsertedCount++;
|
|
|
|
|
|
currentAccountLog.InsertedItems.Add(
|
|
|
|
|
|
$"{{ " +
|
|
|
|
|
|
$"\"code\": \"{item.Code}\", " +
|
|
|
|
|
|
$"\"name\": \"{item.Name}\", " +
|
|
|
|
|
|
$"}}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Details.Add(currentAccountLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-09 21:13:38 +00:00
|
|
|
|
result.Success = true;
|
2025-11-12 12:59:31 +00:00
|
|
|
|
result.Message = $"Seed işlemi başarıyla tamamlandı. Toplam {result.TotalInsertedCount} kayıt eklendi.";
|
2025-10-09 21:13:38 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Success = false;
|
|
|
|
|
|
result.Message = $"Hata: {ex.Message}";
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-11 19:49:52 +00:00
|
|
|
|
|