2025-05-06 06:45:49 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Kurs.Languages.Entities;
|
2025-06-16 19:45:49 +00:00
|
|
|
|
using Kurs.Notifications.Entities;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
using Kurs.Platform.Charts.Dto;
|
|
|
|
|
|
using Kurs.Platform.Entities;
|
2025-06-11 08:23:27 +00:00
|
|
|
|
using Kurs.Platform.Enums;
|
2025-06-23 14:58:13 +00:00
|
|
|
|
using Kurs.Platform.Forum;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
using Kurs.Platform.ListForms;
|
|
|
|
|
|
using Kurs.Platform.Seeds;
|
|
|
|
|
|
using Kurs.Settings.Entities;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Volo.Abp.Data;
|
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
2025-06-18 10:29:25 +00:00
|
|
|
|
using Volo.Abp.MultiTenancy;
|
2025-06-16 19:45:49 +00:00
|
|
|
|
using Volo.Abp.PermissionManagement;
|
2025-08-19 10:19:31 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using EFCore.BulkExtensions;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Kurs.Platform.Contacts;
|
2025-06-11 08:23:27 +00:00
|
|
|
|
using static Kurs.Settings.SettingsConsts;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Kurs.Platform.Data.Seeds;
|
|
|
|
|
|
|
|
|
|
|
|
public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepository<Language, Guid> _languages;
|
|
|
|
|
|
private readonly IRepository<LanguageKey, Guid> _languageKey;
|
|
|
|
|
|
private readonly IRepository<LanguageText, Guid> _languagesText;
|
|
|
|
|
|
private readonly IRepository<DataSource, Guid> _dataSources;
|
|
|
|
|
|
private readonly IRepository<SettingDefinition, Guid> _settings;
|
|
|
|
|
|
private readonly IRepository<Chart> _charts;
|
2025-06-16 19:45:49 +00:00
|
|
|
|
private readonly IRepository<GlobalSearch, int> _globalSearch;
|
|
|
|
|
|
private readonly IRepository<BackgroundWorker, Guid> _backgroundWorkerRepository;
|
|
|
|
|
|
private readonly IRepository<NotificationRule, Guid> _notificationRuleRepository;
|
|
|
|
|
|
private readonly IRepository<Menu, Guid> _menuRepository;
|
|
|
|
|
|
private readonly IRepository<PermissionGroupDefinitionRecord, Guid> _permissionGroupRepository;
|
|
|
|
|
|
private readonly IRepository<PermissionDefinitionRecord, Guid> _permissionRepository;
|
2025-06-18 10:29:25 +00:00
|
|
|
|
private readonly IRepository<Sector, Guid> _sectorRepository;
|
|
|
|
|
|
private readonly IRepository<UomCategory, Guid> _uomCategoryRepository;
|
|
|
|
|
|
private readonly IRepository<Uom, Guid> _uomRepository;
|
|
|
|
|
|
private readonly IRepository<Currency, Guid> _currencyRepository;
|
|
|
|
|
|
private readonly IRepository<CountryGroup, Guid> _countryGroupRepository;
|
|
|
|
|
|
private readonly IRepository<Country, Guid> _countryRepository;
|
2025-08-18 21:25:09 +00:00
|
|
|
|
private readonly IRepository<City, Guid> _cityRepository;
|
|
|
|
|
|
private readonly IRepository<District, Guid> _districtRepository;
|
2025-06-18 10:29:25 +00:00
|
|
|
|
private readonly IRepository<SkillType, Guid> _skillTypeRepository;
|
|
|
|
|
|
private readonly IRepository<Skill, Guid> _skillRepository;
|
|
|
|
|
|
private readonly IRepository<SkillLevel, Guid> _skillLevelRepository;
|
|
|
|
|
|
private readonly IRepository<ContactTag, Guid> _contactTagRepository;
|
|
|
|
|
|
private readonly IRepository<ContactTitle, Guid> _contactTitleRepository;
|
2025-06-19 21:42:16 +00:00
|
|
|
|
private readonly IRepository<BlogCategory, Guid> _blogCategoryRepository;
|
|
|
|
|
|
private readonly IRepository<BlogPost, Guid> _blogPostsRepository;
|
2025-06-23 14:58:13 +00:00
|
|
|
|
private readonly IRepository<ForumCategory, Guid> _forumCategoryRepository;
|
2025-06-25 06:48:40 +00:00
|
|
|
|
private readonly IRepository<AiBot, Guid> _aiBotRepository;
|
2025-07-27 20:52:31 +00:00
|
|
|
|
private readonly IRepository<Route, Guid> _routeRepository;
|
|
|
|
|
|
private readonly IRepository<CustomEndpoint, Guid> _customEndpointRepository;
|
2025-08-11 06:34:44 +00:00
|
|
|
|
private readonly IRepository<Product, Guid> _productRepository;
|
|
|
|
|
|
private readonly IRepository<PaymentMethod, String> _paymentMethodRepository;
|
|
|
|
|
|
private readonly IRepository<InstallmentOption, int> _installmentOptionRepository;
|
2025-08-11 21:35:35 +00:00
|
|
|
|
private readonly IRepository<CustomComponent, Guid> _customComponentRepository;
|
2025-08-15 13:01:24 +00:00
|
|
|
|
private readonly IRepository<ReportCategory, Guid> _reportCategoriesRepository;
|
2025-08-20 10:06:40 +00:00
|
|
|
|
private readonly IRepository<Service, Guid> _servicesRepository;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
public PlatformDataSeeder(
|
|
|
|
|
|
IRepository<Language, Guid> languages,
|
|
|
|
|
|
IRepository<LanguageKey, Guid> languageKey,
|
|
|
|
|
|
IRepository<LanguageText, Guid> languagesText,
|
|
|
|
|
|
IRepository<DataSource, Guid> dataSource,
|
|
|
|
|
|
IRepository<SettingDefinition, Guid> settings,
|
2025-06-16 19:45:49 +00:00
|
|
|
|
IRepository<Chart> charts,
|
|
|
|
|
|
IRepository<GlobalSearch, int> globalSearch,
|
|
|
|
|
|
IRepository<BackgroundWorker, Guid> backgroundWorkerRepository,
|
|
|
|
|
|
IRepository<NotificationRule, Guid> notificationRuleRepository,
|
|
|
|
|
|
IRepository<Menu, Guid> menuRepository,
|
|
|
|
|
|
IRepository<PermissionGroupDefinitionRecord, Guid> permissionGroupRepository,
|
2025-06-18 10:29:25 +00:00
|
|
|
|
IRepository<PermissionDefinitionRecord, Guid> permissionRepository,
|
|
|
|
|
|
IRepository<Sector, Guid> sectorRepository,
|
|
|
|
|
|
IRepository<UomCategory, Guid> uomCategoryRepository,
|
|
|
|
|
|
IRepository<Uom, Guid> uomRepository,
|
|
|
|
|
|
IRepository<Currency, Guid> currencyRepository,
|
|
|
|
|
|
IRepository<CountryGroup, Guid> countryGroupRepository,
|
|
|
|
|
|
IRepository<Country, Guid> countryRepository,
|
2025-08-18 21:25:09 +00:00
|
|
|
|
IRepository<City, Guid> cityRepository,
|
|
|
|
|
|
IRepository<District, Guid> districtRepository,
|
2025-06-18 10:29:25 +00:00
|
|
|
|
IRepository<SkillType, Guid> skillTypeRepository,
|
|
|
|
|
|
IRepository<Skill, Guid> skillRepository,
|
|
|
|
|
|
IRepository<SkillLevel, Guid> skillLevelRepository,
|
|
|
|
|
|
IRepository<ContactTag, Guid> contactTagRepository,
|
2025-06-19 21:42:16 +00:00
|
|
|
|
IRepository<ContactTitle, Guid> contactTitleRepository,
|
|
|
|
|
|
IRepository<BlogCategory, Guid> blogCategoryRepository,
|
2025-06-23 14:58:13 +00:00
|
|
|
|
IRepository<BlogPost, Guid> blogPostsRepository,
|
2025-06-25 06:48:40 +00:00
|
|
|
|
IRepository<ForumCategory, Guid> forumCategoryRepository,
|
2025-06-28 21:34:28 +00:00
|
|
|
|
IRepository<AiBot, Guid> aiBotRepository,
|
2025-07-27 20:52:31 +00:00
|
|
|
|
IRepository<Route, Guid> RouteRepository,
|
2025-08-11 06:34:44 +00:00
|
|
|
|
IRepository<CustomEndpoint, Guid> CustomEndpointRepository,
|
|
|
|
|
|
IRepository<Product, Guid> ProductRepository,
|
|
|
|
|
|
IRepository<PaymentMethod, String> PaymentMethodRepository,
|
2025-08-11 21:35:35 +00:00
|
|
|
|
IRepository<InstallmentOption, int> InstallmentOptionRepository,
|
2025-08-15 13:01:24 +00:00
|
|
|
|
IRepository<CustomComponent, Guid> CustomComponentRepository,
|
2025-08-20 10:06:40 +00:00
|
|
|
|
IRepository<ReportCategory, Guid> ReportCategoriesRepository,
|
|
|
|
|
|
IRepository<Service, Guid> ServicesRepository
|
2025-06-18 10:29:25 +00:00
|
|
|
|
)
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
_languages = languages;
|
|
|
|
|
|
_languageKey = languageKey;
|
|
|
|
|
|
_languagesText = languagesText;
|
|
|
|
|
|
_dataSources = dataSource;
|
|
|
|
|
|
_settings = settings;
|
|
|
|
|
|
_charts = charts;
|
2025-06-16 19:45:49 +00:00
|
|
|
|
_globalSearch = globalSearch;
|
|
|
|
|
|
_backgroundWorkerRepository = backgroundWorkerRepository;
|
|
|
|
|
|
_notificationRuleRepository = notificationRuleRepository;
|
|
|
|
|
|
_menuRepository = menuRepository;
|
|
|
|
|
|
_permissionGroupRepository = permissionGroupRepository;
|
|
|
|
|
|
_permissionRepository = permissionRepository;
|
2025-06-18 10:29:25 +00:00
|
|
|
|
_sectorRepository = sectorRepository;
|
|
|
|
|
|
_uomCategoryRepository = uomCategoryRepository;
|
|
|
|
|
|
_uomRepository = uomRepository;
|
|
|
|
|
|
_currencyRepository = currencyRepository;
|
|
|
|
|
|
_countryGroupRepository = countryGroupRepository;
|
|
|
|
|
|
_countryRepository = countryRepository;
|
2025-08-18 21:25:09 +00:00
|
|
|
|
_cityRepository = cityRepository;
|
|
|
|
|
|
_districtRepository = districtRepository;
|
2025-06-18 10:29:25 +00:00
|
|
|
|
_skillTypeRepository = skillTypeRepository;
|
|
|
|
|
|
_skillRepository = skillRepository;
|
|
|
|
|
|
_skillLevelRepository = skillLevelRepository;
|
|
|
|
|
|
_contactTagRepository = contactTagRepository;
|
|
|
|
|
|
_contactTitleRepository = contactTitleRepository;
|
2025-06-19 21:42:16 +00:00
|
|
|
|
_blogCategoryRepository = blogCategoryRepository;
|
|
|
|
|
|
_blogPostsRepository = blogPostsRepository;
|
2025-06-23 14:58:13 +00:00
|
|
|
|
_forumCategoryRepository = forumCategoryRepository;
|
2025-06-25 06:48:40 +00:00
|
|
|
|
_aiBotRepository = aiBotRepository;
|
2025-07-27 20:52:31 +00:00
|
|
|
|
_routeRepository = RouteRepository;
|
|
|
|
|
|
_customEndpointRepository = CustomEndpointRepository;
|
2025-08-11 06:34:44 +00:00
|
|
|
|
_productRepository = ProductRepository;
|
|
|
|
|
|
_paymentMethodRepository = PaymentMethodRepository;
|
|
|
|
|
|
_installmentOptionRepository = InstallmentOptionRepository;
|
2025-08-11 21:35:35 +00:00
|
|
|
|
_customComponentRepository = CustomComponentRepository;
|
2025-08-15 13:01:24 +00:00
|
|
|
|
_reportCategoriesRepository = ReportCategoriesRepository;
|
2025-08-20 10:06:40 +00:00
|
|
|
|
_servicesRepository = ServicesRepository;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-11 08:23:27 +00:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 06:45:49 +00:00
|
|
|
|
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 charts = await _charts.GetListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
|
|
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
|
|
|
|
.AddJsonFile(Path.Combine("Seeds", "SeederData.json"))
|
|
|
|
|
|
.AddJsonFile(Path.Combine("Seeds", $"SeederData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), true)
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
var items = configuration.Get<SeederDto>();
|
|
|
|
|
|
|
2025-08-19 10:19:31 +00:00
|
|
|
|
await SeedCountyGroupsAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await SeedCountriesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await SeedCitiesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await SeedDistrictsAsync();
|
|
|
|
|
|
|
2025-05-06 06:45:49 +00:00
|
|
|
|
foreach (var item in items.Charts)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!charts.Any(a => a.ChartCode == item.ChartCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
await _charts.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
ChartCode = item.ChartCode,
|
|
|
|
|
|
CultureName = item.CultureName,
|
|
|
|
|
|
DataSourceCode = item.DataSourceCode,
|
|
|
|
|
|
UserId = item.UserId,
|
|
|
|
|
|
RoleId = item.RoleId,
|
|
|
|
|
|
TitleJson = JsonSerializer.Serialize(new ChartTitleDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = item.Title.Text,
|
|
|
|
|
|
Subtitle = item.Title.Subtitle,
|
|
|
|
|
|
}),
|
|
|
|
|
|
DataSourceJson = JsonSerializer.Serialize(new ChartDataSourceDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Query = item.DataSource.Query
|
|
|
|
|
|
}),
|
|
|
|
|
|
SeriesJson = JsonSerializer.Serialize(item.Series),
|
|
|
|
|
|
CrosshairJson = JsonSerializer.Serialize(new ChartCrosshairDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
Enabled = item.Crosshair.Enabled,
|
|
|
|
|
|
Color = item.Crosshair.Color,
|
|
|
|
|
|
DashStyle = item.Crosshair.DashStyle,
|
|
|
|
|
|
HorizontalLine = new ChartCrosshairLineDto() { DashStyle = item.Crosshair.HorizontalLine.DashStyle }
|
|
|
|
|
|
}),
|
|
|
|
|
|
ArgumentAxisJson = JsonSerializer.Serialize(new ChartArgumentAxisDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
Label = item.ArgumentAxis.Label
|
|
|
|
|
|
}),
|
|
|
|
|
|
SizeJson = JsonSerializer.Serialize(new ChartSizeDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = item.Size.Width,
|
|
|
|
|
|
Height = item.Size.Height
|
|
|
|
|
|
}),
|
|
|
|
|
|
PermissionJson = JsonSerializer.Serialize(new PermissionCrudDto
|
|
|
|
|
|
{
|
|
|
|
|
|
C = item.Permission.C,
|
|
|
|
|
|
R = item.Permission.R,
|
|
|
|
|
|
U = item.Permission.U,
|
|
|
|
|
|
D = item.Permission.D
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Settings)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!settings.Any(a => a.Code == item.Code))
|
|
|
|
|
|
{
|
|
|
|
|
|
await _settings.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
|
NameKey = item.NameKey,
|
|
|
|
|
|
DescriptionKey = item.DescriptionKey,
|
|
|
|
|
|
DefaultValue = item.DefaultValue.Replace("\r\n", Environment.NewLine),
|
|
|
|
|
|
IsVisibleToClients = item.IsVisibleToClients,
|
|
|
|
|
|
IsInherited = item.IsInherited,
|
|
|
|
|
|
IsEncrypted = item.IsEncrypted,
|
|
|
|
|
|
MainGroupKey = item.MainGroupKey,
|
|
|
|
|
|
SubGroupKey = item.SubGroupKey,
|
|
|
|
|
|
RequiredPermissionName = item.RequiredPermissionName,
|
|
|
|
|
|
DataType = item.DataType,
|
|
|
|
|
|
Providers = item.Providers,
|
|
|
|
|
|
SelectOptions = item.SelectOptions,
|
|
|
|
|
|
Order = item.Order
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-11 08:23:27 +00:00
|
|
|
|
if (!dataSources.Any(a => a.Code == SeedConsts.DataSources.DefaultCode))
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-06-11 08:23:27 +00:00
|
|
|
|
var config = BuildConfiguration();
|
|
|
|
|
|
await _dataSources.InsertAsync(new()
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-06-11 08:23:27 +00:00
|
|
|
|
Code = SeedConsts.DataSources.DefaultCode,
|
|
|
|
|
|
DataSourceType = DefaultDatabaseProvider == DatabaseProvider.SqlServer ? DataSourceTypeEnum.Mssql : DataSourceTypeEnum.Postgresql,
|
|
|
|
|
|
ConnectionString = config.GetConnectionString(DefaultDatabaseProvider)
|
|
|
|
|
|
});
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2025-08-20 07:31:56 +00:00
|
|
|
|
try
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-08-20 07:31:56 +00:00
|
|
|
|
if (!keys.Any(a => a.Key == item.Key))
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-08-20 07:31:56 +00:00
|
|
|
|
await _languageKey.InsertAsync(new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Key = item.Key,
|
|
|
|
|
|
ResourceName = item.ResourceName,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key))
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-08-20 07:31:56 +00:00
|
|
|
|
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,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
2025-08-20 07:31:56 +00:00
|
|
|
|
catch (Exception ex)
|
2025-05-06 06:45:49 +00:00
|
|
|
|
{
|
2025-08-20 07:31:56 +00:00
|
|
|
|
throw new Exception($"Hata veren Kod:' ResourceName='{item.ResourceName}', Key='{item.Key}'.");
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-16 19:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.GlobalSearch)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!await _globalSearch.AnyAsync(x => x.System == item.System && x.Group == item.Group && x.Term == item.Term))
|
|
|
|
|
|
{
|
|
|
|
|
|
await _globalSearch.InsertAsync(new GlobalSearch
|
|
|
|
|
|
{
|
|
|
|
|
|
System = item.System,
|
|
|
|
|
|
Group = item.Group,
|
|
|
|
|
|
Term = item.Term,
|
|
|
|
|
|
Weight = item.Weight,
|
|
|
|
|
|
Url = item.Url
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.BackgroundWorkers)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!await _backgroundWorkerRepository.AnyAsync(x => x.Name == item.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
await _backgroundWorkerRepository.InsertAsync(new BackgroundWorker
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Cron = item.Cron,
|
|
|
|
|
|
WorkerType = Enum.Parse<WorkerTypeEnum>(item.WorkerType),
|
|
|
|
|
|
IsActive = item.IsActive,
|
|
|
|
|
|
DataSourceCode = item.DataSourceCode
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.NotificationRules)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _notificationRuleRepository.AnyAsync(x =>
|
|
|
|
|
|
x.NotificationType == item.NotificationType &&
|
|
|
|
|
|
x.RecipientType == item.RecipientType &&
|
|
|
|
|
|
x.RecipientId == item.RecipientId &&
|
|
|
|
|
|
x.Channel == item.Channel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _notificationRuleRepository.InsertAsync(new NotificationRule
|
|
|
|
|
|
{
|
|
|
|
|
|
NotificationType = item.NotificationType,
|
|
|
|
|
|
RecipientType = item.RecipientType,
|
|
|
|
|
|
RecipientId = item.RecipientId,
|
|
|
|
|
|
Channel = item.Channel,
|
|
|
|
|
|
IsActive = item.IsActive,
|
|
|
|
|
|
IsFixed = item.IsFixed,
|
|
|
|
|
|
IsCustomized = item.IsCustomized
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _permissionRepository.InsertAsync(new PermissionDefinitionRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
GroupName = item.GroupName,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
ParentName = string.IsNullOrWhiteSpace(item.ParentName) ? null : item.ParentName,
|
|
|
|
|
|
DisplayName = item.DisplayName,
|
2025-06-18 10:29:25 +00:00
|
|
|
|
IsEnabled = item.IsEnabled,
|
|
|
|
|
|
MultiTenancySide = (MultiTenancySides)item.MultiTenancySide
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _sectorRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sectorRepository.InsertAsync(new Sector
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
FullName = item.FullName
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.UomCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _uomCategoryRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
2025-08-19 21:01:24 +00:00
|
|
|
|
await _uomCategoryRepository.InsertAsync(new UomCategory(item.Id, item.Name));
|
2025-06-18 10:29:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Uoms)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _uomRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _uomRepository.InsertAsync(new Uom
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Type = item.Type,
|
|
|
|
|
|
Ratio = item.Ratio,
|
|
|
|
|
|
IsActive = item.IsActive,
|
|
|
|
|
|
Rounding = item.Rounding,
|
2025-08-19 21:01:24 +00:00
|
|
|
|
UomCategoryId = item.UomCategoryId
|
2025-06-18 10:29:25 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Currencies)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _currencyRepository.AnyAsync(x => x.Code == item.Code);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _currencyRepository.InsertAsync(new Currency
|
|
|
|
|
|
{
|
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
|
Symbol = item.Symbol,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
IsActive = item.IsActive
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.SkillTypes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _skillTypeRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _skillTypeRepository.InsertAsync(new SkillType
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Skills)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _skillRepository.AnyAsync(x => x.Name == item.Name && x.TypeName == item.TypeName);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _skillRepository.InsertAsync(new Skill
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
TypeName = item.TypeName
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.SkillLevels)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _skillLevelRepository.AnyAsync(x => x.Name == item.Name && x.TypeName == item.TypeName);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _skillLevelRepository.InsertAsync(new SkillLevel
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
TypeName = item.TypeName,
|
|
|
|
|
|
Progress = item.Progress,
|
|
|
|
|
|
IsDefault = item.IsDefault
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.ContactTags)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _contactTagRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _contactTagRepository.InsertAsync(new ContactTag
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Category = item.Category,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.ContactTitles)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _contactTitleRepository.AnyAsync(x => x.Title == item.Title);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _contactTitleRepository.InsertAsync(new ContactTitle
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = item.Title,
|
|
|
|
|
|
Abbreviation = item.Abbreviation,
|
2025-06-16 19:45:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-19 21:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.BlogCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _blogCategoryRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newCategory = new BlogCategory(
|
|
|
|
|
|
item.Id,
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Slug,
|
|
|
|
|
|
item.Description
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayOrder = item.DisplayOrder,
|
2025-06-23 14:58:13 +00:00
|
|
|
|
PostCount = item.PostCount
|
2025-06-19 21:42:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _blogCategoryRepository.InsertAsync(newCategory);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.BlogPosts)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _blogPostsRepository.AnyAsync(x => x.Title == item.Title);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _blogPostsRepository.InsertAsync(new BlogPost(
|
2025-08-20 10:06:40 +00:00
|
|
|
|
Guid.NewGuid(),
|
2025-06-19 21:42:16 +00:00
|
|
|
|
item.Title,
|
|
|
|
|
|
item.Slug,
|
2025-06-22 12:44:11 +00:00
|
|
|
|
item.ContentTr,
|
|
|
|
|
|
item.ContentEn,
|
2025-06-19 21:42:16 +00:00
|
|
|
|
item.Summary,
|
|
|
|
|
|
item.ReadTime,
|
|
|
|
|
|
item.CoverImage,
|
|
|
|
|
|
item.CategoryId,
|
2025-06-27 15:00:47 +00:00
|
|
|
|
item.AuthorId,
|
|
|
|
|
|
true,
|
|
|
|
|
|
DateTime.UtcNow
|
2025-06-19 21:42:16 +00:00
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-25 06:48:40 +00:00
|
|
|
|
|
2025-06-23 14:58:13 +00:00
|
|
|
|
foreach (var item in items.ForumCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _forumCategoryRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newCategory = new ForumCategory(
|
2025-08-20 10:06:40 +00:00
|
|
|
|
Guid.NewGuid(),
|
2025-06-23 14:58:13 +00:00
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Slug,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.Icon,
|
|
|
|
|
|
item.DisplayOrder
|
|
|
|
|
|
);
|
2025-06-25 06:48:40 +00:00
|
|
|
|
|
2025-06-23 14:58:13 +00:00
|
|
|
|
await _forumCategoryRepository.InsertAsync(newCategory);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-25 06:48:40 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.AiBots)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _aiBotRepository.AnyAsync(x => x.BotName == item.BotName);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _aiBotRepository.InsertAsync(new AiBot(
|
2025-08-20 10:06:40 +00:00
|
|
|
|
Guid.NewGuid(),
|
2025-06-25 06:48:40 +00:00
|
|
|
|
item.BotName
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-28 21:34:28 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Routes)
|
|
|
|
|
|
{
|
2025-07-27 20:52:31 +00:00
|
|
|
|
var exists = await _routeRepository.AnyAsync(x => x.Key == item.Key);
|
2025-06-28 21:34:28 +00:00
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
2025-07-27 20:52:31 +00:00
|
|
|
|
await _routeRepository.InsertAsync(new Route(
|
2025-06-28 21:34:28 +00:00
|
|
|
|
item.Key,
|
|
|
|
|
|
item.Path,
|
|
|
|
|
|
item.ComponentPath,
|
|
|
|
|
|
item.RouteType,
|
|
|
|
|
|
item.Authority ?? []
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-27 20:52:31 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.CustomEndpoints)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _customEndpointRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _customEndpointRepository.InsertAsync(new CustomEndpoint(
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.Url,
|
|
|
|
|
|
item.Method,
|
|
|
|
|
|
item.DataSourceCode,
|
|
|
|
|
|
item.Sql,
|
|
|
|
|
|
JsonSerializer.Serialize(item.ParametersJson),
|
|
|
|
|
|
JsonSerializer.Serialize(item.PermissionsJson)
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-11 06:34:44 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Products)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _productRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _productRepository.InsertAsync(new Product(
|
2025-08-20 10:06:40 +00:00
|
|
|
|
Guid.NewGuid(),
|
2025-08-11 06:34:44 +00:00
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.Category,
|
|
|
|
|
|
item.Order,
|
|
|
|
|
|
item.MonthlyPrice,
|
|
|
|
|
|
item.YearlyPrice,
|
|
|
|
|
|
item.IsQuantityBased,
|
|
|
|
|
|
item.ImageUrl
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.PaymentMethods)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _paymentMethodRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _paymentMethodRepository.InsertAsync(new PaymentMethod(
|
|
|
|
|
|
item.Id,
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Commission,
|
|
|
|
|
|
item.Logo
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.InstallmentOptions)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _installmentOptionRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _installmentOptionRepository.InsertAsync(new InstallmentOption(
|
|
|
|
|
|
item.Id,
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Commission));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-11 21:35:35 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.CustomComponents)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _customComponentRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _customComponentRepository.InsertAsync(new CustomComponent(
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Code,
|
|
|
|
|
|
item.Props,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.IsActive,
|
|
|
|
|
|
JsonSerializer.Serialize(item.Dependencies)));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-15 13:01:24 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.ReportCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _reportCategoriesRepository.AnyAsync(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _reportCategoriesRepository.InsertAsync(new ReportCategory(
|
2025-08-20 10:06:40 +00:00
|
|
|
|
Guid.NewGuid(),
|
2025-08-15 13:01:24 +00:00
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.Icon));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-20 10:06:40 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var item in items.Services)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exists = await _servicesRepository.AnyAsync(x => x.Title == item.Title);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _servicesRepository.InsertAsync(new Service(
|
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
|
item.Icon,
|
|
|
|
|
|
item.Title,
|
|
|
|
|
|
item.Description,
|
|
|
|
|
|
item.Type,
|
|
|
|
|
|
item.Features
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
2025-08-11 21:35:35 +00:00
|
|
|
|
|
2025-08-19 10:19:31 +00:00
|
|
|
|
public async Task SeedCountyGroupsAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _countryRepository.GetDbContextAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// DB’de mevcut kodları set olarak al
|
|
|
|
|
|
var existingCodes = (await dbCtx.Set<CountryGroup>()
|
|
|
|
|
|
.Select(c => c.Name)
|
|
|
|
|
|
.ToListAsync())
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
|
|
|
|
|
|
|
|
|
|
using var fs = File.OpenRead(Path.Combine("Seeds", "CountryGroups.json"));
|
|
|
|
|
|
|
|
|
|
|
|
var buffer = new List<CountryGroup>(capacity: 1000);
|
|
|
|
|
|
var seenCodes = new HashSet<string>(); // JSON içindeki duplicate’leri yakalamak için
|
|
|
|
|
|
|
|
|
|
|
|
await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<CountryGroupDto>(fs, options))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item == null) continue;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.Name)) continue; // boş kodları atla
|
|
|
|
|
|
|
|
|
|
|
|
// hem DB’de hem JSON içinde duplicate engelle
|
|
|
|
|
|
if (!seenCodes.Add(item.Name) || existingCodes.Contains(item.Name))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
buffer.Add(new CountryGroup(
|
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
|
item.Name
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count >= 1000)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCountryGroupInsertAsync(buffer);
|
|
|
|
|
|
buffer.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCountryGroupInsertAsync(buffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task BulkCountryGroupInsertAsync(List<CountryGroup> entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _countryGroupRepository.GetDbContextAsync();
|
|
|
|
|
|
await dbCtx.BulkInsertAsync(entities, new BulkConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
BatchSize = 1000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SeedCountriesAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _countryRepository.GetDbContextAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// DB’de mevcut kodları set olarak al
|
|
|
|
|
|
var existingCodes = (await dbCtx.Set<Country>()
|
|
|
|
|
|
.Select(c => c.Code)
|
|
|
|
|
|
.ToListAsync())
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
|
|
|
|
|
|
|
|
|
|
using var fs = File.OpenRead(Path.Combine("Seeds", "Countries.json"));
|
|
|
|
|
|
|
|
|
|
|
|
var buffer = new List<Country>(capacity: 1000);
|
|
|
|
|
|
var seenCodes = new HashSet<string>(); // JSON içindeki duplicate’leri yakalamak için
|
|
|
|
|
|
|
|
|
|
|
|
await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<CountryDto>(fs, options))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item == null) continue;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.Code)) continue; // boş kodları atla
|
|
|
|
|
|
|
|
|
|
|
|
// hem DB’de hem JSON içinde duplicate engelle
|
|
|
|
|
|
if (!seenCodes.Add(item.Code) || existingCodes.Contains(item.Code))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
buffer.Add(new Country(
|
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
|
item.Code,
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.GroupName,
|
|
|
|
|
|
item.CurrencyCode,
|
|
|
|
|
|
item.PhoneCode,
|
|
|
|
|
|
item.TaxLabel
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count >= 1000)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCountryInsertAsync(buffer);
|
|
|
|
|
|
buffer.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCountryInsertAsync(buffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task BulkCountryInsertAsync(List<Country> entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _countryRepository.GetDbContextAsync();
|
|
|
|
|
|
await dbCtx.BulkInsertAsync(entities, new BulkConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
BatchSize = 1000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SeedCitiesAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _cityRepository.GetDbContextAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Mevcut kayıtları çek (tek sorguda)
|
|
|
|
|
|
var existingCities = await dbCtx.Set<City>()
|
|
|
|
|
|
.Select(d => new { d.Code })
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var existingSet = existingCities
|
|
|
|
|
|
.Select(d => d.Code)
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
PropertyNameCaseInsensitive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 2. JSON’u stream et
|
|
|
|
|
|
using FileStream fs = File.OpenRead(Path.Combine("Seeds", "Cities.json"));
|
|
|
|
|
|
|
|
|
|
|
|
var buffer = new List<City>(capacity: 5000);
|
|
|
|
|
|
await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<CityDto>(fs, options))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
var key = $"{item.Code}";
|
|
|
|
|
|
if (existingSet.Contains(key)) continue; // duplicate kontrolü
|
|
|
|
|
|
|
|
|
|
|
|
buffer.Add(new City(
|
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
|
item.CountryCode,
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
$"{item.CountryCode}.{item.Code}",
|
|
|
|
|
|
item.PlateCode
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count >= 1000) // 3. Batch
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCityInsertAsync(buffer);
|
|
|
|
|
|
buffer.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkCityInsertAsync(buffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task BulkCityInsertAsync(List<City> entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _cityRepository.GetDbContextAsync();
|
|
|
|
|
|
await dbCtx.BulkInsertAsync(entities, new BulkConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
PreserveInsertOrder = true,
|
|
|
|
|
|
SetOutputIdentity = true,
|
|
|
|
|
|
BatchSize = 1000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SeedDistrictsAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _districtRepository.GetDbContextAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Mevcut kayıtları çek (tek sorguda)
|
|
|
|
|
|
var existingDistricts = await dbCtx.Set<District>()
|
|
|
|
|
|
.Select(d => new { d.CountryCode, d.CityCode, d.Name, d.Township, d.Street, d.ZipCode })
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var existingSet = existingDistricts
|
|
|
|
|
|
.Select(d => $"{d.CountryCode}:{d.CityCode}:{d.Name}:{d.Township}:{d.Street}:{d.ZipCode}")
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
PropertyNameCaseInsensitive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 2. JSON’u stream et
|
|
|
|
|
|
using FileStream fs = File.OpenRead(Path.Combine("Seeds", "Districts.json"));
|
|
|
|
|
|
|
|
|
|
|
|
var buffer = new List<District>(capacity: 5000);
|
|
|
|
|
|
await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<DistrictDto>(fs, options))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
var key = $"{item.CountryCode}:{item.CityCode}:{item.Name}:{item.Township}:{item.Street}:{item.ZipCode}";
|
|
|
|
|
|
if (existingSet.Contains(key)) continue; // duplicate kontrolü
|
|
|
|
|
|
|
|
|
|
|
|
buffer.Add(new District(
|
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
|
item.CountryCode,
|
|
|
|
|
|
$"{item.CountryCode}.{item.CityCode}",
|
|
|
|
|
|
item.Name,
|
|
|
|
|
|
item.Township,
|
|
|
|
|
|
item.Street,
|
|
|
|
|
|
item.ZipCode
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count >= 5000) // 3. Batch
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkDistrictInsertAsync(buffer);
|
|
|
|
|
|
buffer.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BulkDistrictInsertAsync(buffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task BulkDistrictInsertAsync(List<District> entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dbCtx = await _districtRepository.GetDbContextAsync();
|
|
|
|
|
|
await dbCtx.BulkInsertAsync(entities, new BulkConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
PreserveInsertOrder = true,
|
|
|
|
|
|
SetOutputIdentity = true,
|
|
|
|
|
|
BatchSize = 5000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|