sozsoft-platform/api/src/Sozsoft.Platform.Application/Public/PublicAppService.cs
2026-03-17 22:22:21 +03:00

731 lines
32 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sozsoft.Platform.Entities;
using Volo.Abp.Domain.Repositories;
using System.Text;
using Sozsoft.Platform.Data.Seeds;
using Sozsoft.Sender.Mail;
using Volo.Abp.Settings;
using Sozsoft.Platform.Demos;
using Volo.Abp.Domain.Entities;
using System.Linq;
using Volo.Abp.Application.Dtos;
using System.Text.Json;
using Volo.Abp.Identity;
using Sozsoft.Languages;
using Sozsoft.Languages.Entities;
namespace Sozsoft.Platform.Public;
public class PublicAppService : PlatformAppService
{
private readonly IRepository<Service, Guid> _serviceRepository;
private readonly ISettingProvider _settingProvider;
private readonly ISozsoftEmailSender _emailSender;
private readonly IRepository<Demo, Guid> _demoRepository;
private readonly IRepository<BlogPost, Guid> _postRepository;
private readonly IRepository<BlogCategory, Guid> _categoryRepository;
private readonly IRepository<Product, Guid> _productRepository;
private readonly IRepository<PaymentMethod, Guid> _paymentMethodRepository;
private readonly IRepository<InstallmentOption> _installmentOptionRepository;
private readonly IRepository<Order, Guid> _orderRepository;
private readonly IRepository<About, Guid> _aboutRepository;
private readonly IRepository<Home, Guid> _homeRepository;
private readonly IRepository<Contact, Guid> _contactRepository;
private readonly IIdentityUserRepository _identityUserRepository;
private readonly IRepository<LanguageKey, Guid> _languageKeyRepository;
private readonly IRepository<LanguageText, Guid> _languageTextRepository;
private readonly LanguageTextAppService _languageTextAppService;
public PublicAppService(
IRepository<Service, Guid> serviceRepository,
ISettingProvider settingProvider,
ISozsoftEmailSender emailSender,
IRepository<Demo, Guid> demoRepository,
IRepository<BlogPost, Guid> postRepository,
IRepository<BlogCategory, Guid> categoryRepository,
IRepository<Product, Guid> productRepository,
IRepository<PaymentMethod, Guid> paymentMethodRepository,
IRepository<InstallmentOption> installmentOptionRepository,
IRepository<Order, Guid> orderRepository,
IRepository<About, Guid> aboutRepository,
IRepository<Home, Guid> homeRepository,
IRepository<Contact, Guid> contactRepository,
IIdentityUserRepository identityUserRepository,
IRepository<LanguageKey, Guid> languageKeyRepository,
IRepository<LanguageText, Guid> languageTextRepository,
LanguageTextAppService languageTextAppService
)
{
_serviceRepository = serviceRepository;
_settingProvider = settingProvider;
_emailSender = emailSender;
_demoRepository = demoRepository;
_postRepository = postRepository;
_categoryRepository = categoryRepository;
_productRepository = productRepository;
_paymentMethodRepository = paymentMethodRepository;
_installmentOptionRepository = installmentOptionRepository;
_orderRepository = orderRepository;
_aboutRepository = aboutRepository;
_homeRepository = homeRepository;
_contactRepository = contactRepository;
_identityUserRepository = identityUserRepository;
_languageKeyRepository = languageKeyRepository;
_languageTextRepository = languageTextRepository;
_languageTextAppService = languageTextAppService;
}
public async Task<List<ServiceDto>> GetServicesListAsync()
{
var queryable = await _serviceRepository.GetQueryableAsync();
var entity = await AsyncExecuter.ToListAsync(queryable.OrderBy(a => a.CreationTime));
return ObjectMapper.Map<List<Service>, List<ServiceDto>>(entity);
}
public async Task SaveAboutPageAsync(SaveAboutPageInput input)
{
var entity = await _aboutRepository.FirstOrDefaultAsync() ?? throw new EntityNotFoundException(typeof(About));
entity.StatsJson = JsonSerializer.Serialize(input.Stats.Select(stat => new StatDto
{
Icon = stat.Icon,
Value = stat.Value,
LabelKey = stat.LabelKey,
UseCounter = stat.UseCounter,
CounterEnd = stat.CounterEnd,
CounterSuffix = stat.CounterSuffix,
CounterDuration = stat.CounterDuration,
}).ToList());
entity.DescriptionsJson = JsonSerializer.Serialize(input.Descriptions.Select(item => item.Key).ToList());
entity.SectionsJson = JsonSerializer.Serialize(input.Sections.Select(section => new SectionDto
{
Key = section.TitleKey,
DescKey = section.DescriptionKey,
}).ToList());
await UpsertLanguageTextAsync(input.CultureName, input.HeroTitleKey, input.HeroTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroSubtitleKey, input.HeroSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroImageKey, input.HeroImageValue);
foreach (var stat in input.Stats)
{
await UpsertLanguageTextAsync(input.CultureName, stat.LabelKey, stat.LabelValue);
}
foreach (var description in input.Descriptions)
{
await UpsertLanguageTextAsync(input.CultureName, description.Key, description.Value);
}
foreach (var section in input.Sections)
{
await UpsertLanguageTextAsync(input.CultureName, section.TitleKey, section.TitleValue);
await UpsertLanguageTextAsync(input.CultureName, section.DescriptionKey, section.DescriptionValue);
}
foreach (var styleText in input.StyleTexts)
{
await UpsertLanguageTextAsync(input.CultureName, styleText.Key, styleText.Value);
}
await _aboutRepository.UpdateAsync(entity, autoSave: true);
await _languageTextAppService.ClearRedisCacheAsync();
}
public async Task SaveServicesPageAsync(SaveServicesPageInput input)
{
var existingEntities = await _serviceRepository.GetListAsync();
foreach (var entity in existingEntities)
{
await _serviceRepository.DeleteAsync(entity, autoSave: false);
}
foreach (var item in input.ServiceItems.Concat(input.SupportItems))
{
var entity = new Service
{
Icon = item.Icon,
Title = item.TitleKey,
Description = item.DescriptionKey,
Type = item.Type,
Features = item.Features.Select(feature => feature.Key).ToArray(),
};
await _serviceRepository.InsertAsync(entity, autoSave: false);
await UpsertLanguageTextAsync(input.CultureName, item.TitleKey, item.TitleValue);
if (!item.DescriptionKey.IsNullOrWhiteSpace())
{
await UpsertLanguageTextAsync(input.CultureName, item.DescriptionKey!, item.DescriptionValue ?? string.Empty);
}
foreach (var feature in item.Features)
{
await UpsertLanguageTextAsync(input.CultureName, feature.Key, feature.Value);
}
}
await UpsertLanguageTextAsync(input.CultureName, input.HeroTitleKey, input.HeroTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroSubtitleKey, input.HeroSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroImageKey, input.HeroImageValue);
await UpsertLanguageTextAsync(input.CultureName, input.SupportTitleKey, input.SupportTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.SupportButtonLabelKey, input.SupportButtonLabelValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaTitleKey, input.CtaTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaDescriptionKey, input.CtaDescriptionValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaButtonLabelKey, input.CtaButtonLabelValue);
foreach (var styleText in input.StyleTexts)
{
await UpsertLanguageTextAsync(input.CultureName, styleText.Key, styleText.Value);
}
await CurrentUnitOfWork!.SaveChangesAsync();
await _languageTextAppService.ClearRedisCacheAsync();
}
public async Task<HomeDto> GetHomeAsync()
{
var entity = await _homeRepository.FirstOrDefaultAsync();
if (entity == null)
{
entity = await _homeRepository.InsertAsync(CreateDefaultHomeEntity(), autoSave: true);
}
return ObjectMapper.Map<Home, HomeDto>(entity);
}
public async Task SaveHomePageAsync(SaveHomePageInput input)
{
var entity = await _homeRepository.FirstOrDefaultAsync();
var isNewEntity = entity == null;
entity ??= CreateDefaultHomeEntity();
entity.HeroBackgroundImageKey = input.HeroBackgroundImageKey;
entity.HeroPrimaryCtaKey = input.HeroPrimaryCtaKey;
entity.HeroSecondaryCtaKey = input.HeroSecondaryCtaKey;
entity.FeaturesTitleKey = input.FeaturesTitleKey;
entity.FeaturesSubtitleKey = input.FeaturesSubtitleKey;
entity.SolutionsTitleKey = input.SolutionsTitleKey;
entity.SolutionsSubtitleKey = input.SolutionsSubtitleKey;
entity.CtaTitleKey = input.CtaTitleKey;
entity.CtaSubtitleKey = input.CtaSubtitleKey;
entity.CtaButtonLabelKey = input.CtaButtonLabelKey;
entity.SlidesJson = JsonSerializer.Serialize(input.Slides.Select(slide => new HomeSlideDto
{
TitleKey = slide.TitleKey,
SubtitleKey = slide.SubtitleKey,
StyleClass = slide.StyleClass,
Services = slide.Services.Select(service => new HomeSlideServiceDto
{
Icon = service.Icon,
TitleKey = service.TitleKey,
DescriptionKey = service.DescriptionKey,
StyleClass = service.StyleClass,
}).ToList(),
}).ToList());
entity.FeaturesJson = JsonSerializer.Serialize(input.Features.Select(feature => new HomeFeatureDto
{
Icon = feature.Icon,
TitleKey = feature.TitleKey,
DescriptionKey = feature.DescriptionKey,
StyleClass = feature.StyleClass,
}).ToList());
entity.SolutionsJson = JsonSerializer.Serialize(input.Solutions.Select(solution => new HomeSolutionDto
{
Icon = solution.Icon,
ColorClass = solution.ColorClass,
TitleKey = solution.TitleKey,
DescriptionKey = solution.DescriptionKey,
StyleClass = solution.StyleClass,
}).ToList());
if (isNewEntity)
{
await _homeRepository.InsertAsync(entity, autoSave: false);
}
else
{
await _homeRepository.UpdateAsync(entity, autoSave: false);
}
await UpsertLanguageTextAsync(input.CultureName, input.HeroBackgroundImageKey, input.HeroBackgroundImageValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroPrimaryCtaKey, input.HeroPrimaryCtaValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroPrimaryCtaStyleKey, input.HeroPrimaryCtaStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroSecondaryCtaKey, input.HeroSecondaryCtaValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroSecondaryCtaStyleKey, input.HeroSecondaryCtaStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.FeaturesTitleKey, input.FeaturesTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.FeaturesTitleStyleKey, input.FeaturesTitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.FeaturesSubtitleKey, input.FeaturesSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.FeaturesSubtitleStyleKey, input.FeaturesSubtitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.SolutionsTitleKey, input.SolutionsTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.SolutionsTitleStyleKey, input.SolutionsTitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.SolutionsSubtitleKey, input.SolutionsSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.SolutionsSubtitleStyleKey, input.SolutionsSubtitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaTitleKey, input.CtaTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaTitleStyleKey, input.CtaTitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaSubtitleKey, input.CtaSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaSubtitleStyleKey, input.CtaSubtitleStyleValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaButtonLabelKey, input.CtaButtonLabelValue);
await UpsertLanguageTextAsync(input.CultureName, input.CtaButtonStyleKey, input.CtaButtonStyleValue);
foreach (var slide in input.Slides)
{
await UpsertLanguageTextAsync(input.CultureName, slide.TitleKey, slide.TitleValue);
await UpsertLanguageTextAsync(input.CultureName, slide.SubtitleKey, slide.SubtitleValue);
foreach (var service in slide.Services)
{
await UpsertLanguageTextAsync(input.CultureName, service.TitleKey, service.TitleValue);
await UpsertLanguageTextAsync(input.CultureName, service.DescriptionKey, service.DescriptionValue);
}
}
foreach (var feature in input.Features)
{
await UpsertLanguageTextAsync(input.CultureName, feature.TitleKey, feature.TitleValue);
await UpsertLanguageTextAsync(input.CultureName, feature.DescriptionKey, feature.DescriptionValue);
}
foreach (var solution in input.Solutions)
{
await UpsertLanguageTextAsync(input.CultureName, solution.TitleKey, solution.TitleValue);
await UpsertLanguageTextAsync(input.CultureName, solution.DescriptionKey, solution.DescriptionValue);
}
await CurrentUnitOfWork!.SaveChangesAsync();
await _languageTextAppService.ClearRedisCacheAsync();
}
public async Task CreateDemoAsync(DemoDto input)
{
var demo = ObjectMapper.Map<DemoDto, Demo>(input);
await _demoRepository.InsertAsync(demo);
var bodyBuilder = new StringBuilder();
bodyBuilder.AppendLine($"Şirket: {input.OrganizationName}");
bodyBuilder.AppendLine($"Ad Soyad: {input.Name}");
bodyBuilder.AppendLine($"E-Posta: {input.Email}");
bodyBuilder.AppendLine($"Telefon: {input.PhoneNumber}");
bodyBuilder.AppendLine($"Adres: {input.Address}");
bodyBuilder.AppendLine($"Şube Sayısı: {input.NumberOfBranches}");
bodyBuilder.AppendLine($"Kullanıcı Sayısı: {input.NumberOfUsers}");
bodyBuilder.AppendLine($"Mesaj: {input.Message}");
var SenderName = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromDisplayName);
var SenderEmailAddress = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromAddress);
await _emailSender.QueueEmailAsync(
SenderEmailAddress ?? string.Empty,
new KeyValuePair<string, string>(SenderName ?? string.Empty, SenderEmailAddress ?? string.Empty),
null,
bodyBuilder.ToString(),
subject: PlatformConsts.AppName + " : Demo Talebi");
}
public async Task<BlogPostAndCategoriesDto> GetPostListAsync(GetBlogPostsInput input)
{
// IQueryable
var postQuery = await _postRepository.GetQueryableAsync();
// 🔎 Arama
if (!input.Search.IsNullOrWhiteSpace())
{
postQuery = postQuery.Where(p =>
p.ContentTr.Contains(input.Search) ||
p.ContentEn.Contains(input.Search));
}
// 📁 Kategori filtresi
if (input.CategoryId.HasValue)
{
postQuery = postQuery.Where(p => p.CategoryId == input.CategoryId.Value);
}
// Toplam adet (sayfalama öncesi)
var totalCount = await AsyncExecuter.CountAsync(postQuery);
// Sayfalama + sıralama
var pagedPosts = await AsyncExecuter.ToListAsync(
postQuery
.OrderByDescending(p => p.CreationTime)
.PageBy(input)
);
// Sayfadaki kategori kayıtları
var categoryIds = pagedPosts.Select(x => x.CategoryId).Distinct().ToList();
var pageCategories = await _categoryRepository.GetListAsync(x => categoryIds.Contains(x.Id));
var categoryDict = pageCategories.ToDictionary(x => x.Id, x => x);
// Post DTO mapping
var postDtos = pagedPosts.Select(post =>
{
var dto = ObjectMapper.Map<BlogPost, BlogPostListDto>(post);
if (categoryDict.TryGetValue(post.CategoryId, out var c))
{
dto.Category = ObjectMapper.Map<BlogCategory, BlogCategoryDto>(c);
}
return dto;
}).ToList();
// ----------- KATEGORİLER (PostCount ile) - Optimize edildi -----------
var categoryQueryable = await _categoryRepository.GetQueryableAsync();
var postQueryableForCount = await _postRepository.GetQueryableAsync();
// Kategori listesi ve post sayıları tek sorguda
var categoriesWithCounts = await AsyncExecuter.ToListAsync(
from category in categoryQueryable
join post in postQueryableForCount.Where(p => p.IsPublished)
on category.Id equals post.CategoryId into postGroup
select new
{
Category = category,
PostCount = postGroup.Count()
}
);
var categoryDtos = categoriesWithCounts.Select(x =>
{
var dto = ObjectMapper.Map<BlogCategory, BlogCategoryDto>(x.Category);
dto.PostCount = x.PostCount;
return dto;
}).ToList();
return new BlogPostAndCategoriesDto
{
Posts = new PagedResultDto<BlogPostListDto>(totalCount, postDtos),
Categories = categoryDtos
};
}
private async Task<BlogPostDto> GetPostAsync(Guid id)
{
// Tek sorguda post ve category'yi çek (N+1 önleme)
var queryable = await _postRepository.GetQueryableAsync();
var categoryQueryable = await _categoryRepository.GetQueryableAsync();
var result = await AsyncExecuter.FirstOrDefaultAsync(
from post in queryable.Where(p => p.Id == id)
join category in categoryQueryable on post.CategoryId equals category.Id
select new { Post = post, Category = category }
);
if (result == null)
throw new EntityNotFoundException(typeof(BlogPost));
var dto = ObjectMapper.Map<BlogPost, BlogPostDto>(result.Post);
dto.Category = ObjectMapper.Map<BlogCategory, BlogCategoryDto>(result.Category);
return dto;
}
public async Task<BlogPostDto> GetPostBySlugAsync(string slug)
{
var post = await _postRepository.FirstOrDefaultAsync(x => x.Slug == slug);
if (post == null)
{
throw new EntityNotFoundException(typeof(BlogPost));
}
return await GetPostAsync(post.Id);
}
public async Task<List<ProductDto>> GetProductListAsync()
{
// Performans: Sıralamayı database'de yap
var queryable = await _productRepository.GetQueryableAsync();
var products = await AsyncExecuter.ToListAsync(
queryable.OrderBy(p => p.Order)
);
return ObjectMapper.Map<List<Product>, List<ProductDto>>(products);
}
public async Task<List<PaymentMethodDto>> GetPaymentMethodListAsync()
{
var paymentMethods = await _paymentMethodRepository.GetListAsync();
return ObjectMapper.Map<List<PaymentMethod>, List<PaymentMethodDto>>(paymentMethods);
}
public async Task<List<InstallmentOptionDto>> GetInstallmentOptionListAsync()
{
var installmentOptions = await _installmentOptionRepository.GetListAsync();
return ObjectMapper.Map<List<InstallmentOption>, List<InstallmentOptionDto>>(installmentOptions);
}
public async Task<OrderDto> CreateOrderAsync(OrderDto input)
{
var entity = new Order()
{
Name = input.Tenant.Name,
IsActive = input.Tenant.IsActive,
OrganizationName = input.Tenant.OrganizationName,
Founder = input.Tenant.Founder,
VknTckn = input.Tenant.VknTckn,
TaxOffice = input.Tenant.TaxOffice,
Address1 = input.Tenant.Address1,
Address2 = input.Tenant.Address2,
District = input.Tenant.District,
Country = input.Tenant.Country,
City = input.Tenant.City,
PostalCode = input.Tenant.PostalCode,
MobileNumber = input.Tenant.MobileNumber,
PhoneNumber = input.Tenant.PhoneNumber,
FaxNumber = input.Tenant.FaxNumber,
Email = input.Tenant.Email,
Website = input.Tenant.Website,
MenuGroup = input.Tenant.MenuGroup,
Subtotal = input.Subtotal,
Commission = input.Commission,
Total = input.Total,
PaymentMethodId = input.PaymentMethodId,
Installment = input.Installment,
PaymentDataJson = JsonSerializer.Serialize(input.PaymentData),
};
foreach (var item in input.Items)
{
entity.Items.Add(new OrderItem
{
OrderId = entity.Id,
Order = entity,
ProductId = item.Product.Id,
ProductName = item.Product.Name,
BillingCycle = item.BillingCycle,
Quantity = item.Quantity,
TotalPrice = item.TotalPrice
});
}
await _orderRepository.InsertAsync(entity, autoSave: true);
return new OrderDto
{
Id = entity.Id,
Total = entity.Total,
PaymentMethodId = entity.PaymentMethodId
};
}
public async Task<AboutDto> GetAboutAsync()
{
var entity = await _aboutRepository.FirstOrDefaultAsync() ?? throw new EntityNotFoundException(typeof(About));
return ObjectMapper.Map<About, AboutDto>(entity);
}
public async Task<ContactDto> GetContactAsync()
{
var entity = await _contactRepository.FirstOrDefaultAsync() ?? throw new EntityNotFoundException(typeof(Contact));
return ObjectMapper.Map<Contact, ContactDto>(entity);
}
public async Task SaveContactPageAsync(SaveContactPageInput input)
{
var entity = await _contactRepository.FirstOrDefaultAsync() ?? throw new EntityNotFoundException(typeof(Contact));
entity.Address = input.AddressKey;
entity.PhoneNumber = input.PhoneNumber;
entity.Email = input.Email;
entity.Location = input.Location;
entity.TaxNumber = long.TryParse(input.TaxNumber, out var taxNumber) ? taxNumber : null;
entity.BankJson = JsonSerializer.Serialize(new BankDto
{
AccountHolder = input.BankAccountHolder,
Branch = input.BankBranch,
AccountNumber = input.BankAccountNumber,
Iban = input.BankIban,
StyleClass = input.BankStyleClass,
});
entity.WorkHoursJson = JsonSerializer.Serialize(new WorkHoursDto
{
Weekday = input.WorkWeekdayKey,
Weekend = input.WorkWeekendKey,
Whatsapp = input.WorkWhatsappKey,
StyleClass = input.WorkHoursStyleClass,
});
entity.MapJson = JsonSerializer.Serialize(new MapDto
{
Title = input.MapTitleKey,
Src = input.MapSrc,
Width = input.MapWidth,
Height = input.MapHeight,
AllowFullScreen = input.MapAllowFullScreen,
Loading = input.MapLoading,
ReferrerPolicy = input.MapReferrerPolicy,
ContainerStyleClass = input.MapContainerStyleClass,
FrameStyleClass = input.MapFrameStyleClass,
});
await _contactRepository.UpdateAsync(entity, autoSave: false);
await UpsertLanguageTextAsync(input.CultureName, input.HeroTitleKey, input.HeroTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroSubtitleKey, input.HeroSubtitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.HeroImageKey, input.HeroImageValue);
await UpsertLanguageTextAsync(input.CultureName, input.ContactInfoTitleKey, input.ContactInfoTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.AddressKey, input.AddressValue);
await UpsertLanguageTextAsync(input.CultureName, input.BankTitleKey, input.BankTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.WorkHoursTitleKey, input.WorkHoursTitleValue);
await UpsertLanguageTextAsync(input.CultureName, input.WorkWeekdayKey, input.WorkWeekdayValue);
await UpsertLanguageTextAsync(input.CultureName, input.WorkWeekendKey, input.WorkWeekendValue);
await UpsertLanguageTextAsync(input.CultureName, input.WorkWhatsappKey, input.WorkWhatsappValue);
await UpsertLanguageTextAsync(input.CultureName, input.MapTitleKey, input.MapTitleValue);
foreach (var styleText in input.StyleTexts)
{
await UpsertLanguageTextAsync(input.CultureName, styleText.Key, styleText.Value);
}
await CurrentUnitOfWork!.SaveChangesAsync();
await _languageTextAppService.ClearRedisCacheAsync();
}
private static Home CreateDefaultHomeEntity()
{
var slides = new List<HomeSlideDto>
{
new()
{
TitleKey = "Public.hero.slide1.title",
SubtitleKey = "Public.hero.slide1.subtitle",
Services = new List<HomeSlideServiceDto>
{
new() { Icon = "FaCalendarAlt", TitleKey = "Public.hero.slide1.service1.title", DescriptionKey = "Public.hero.slide1.service1.desc" },
new() { Icon = "FaUsers", TitleKey = "Public.hero.slide1.service2.title", DescriptionKey = "Public.hero.slide1.service2.desc" },
new() { Icon = "FaShieldAlt", TitleKey = "Public.hero.slide1.service3.title", DescriptionKey = "Public.hero.slide1.service3.desc" },
},
},
new()
{
TitleKey = "Public.hero.slide2.title",
SubtitleKey = "Public.hero.slide2.subtitle",
Services = new List<HomeSlideServiceDto>
{
new() { Icon = "FaChartBar", TitleKey = "Public.hero.slide2.service1.title", DescriptionKey = "Public.hero.slide2.service1.desc" },
new() { Icon = "FaCreditCard", TitleKey = "Public.hero.slide2.service2.title", DescriptionKey = "Public.hero.slide2.service2.desc" },
new() { Icon = "FaDatabase", TitleKey = "Public.hero.slide2.service3.title", DescriptionKey = "Public.hero.slide2.service3.desc" },
},
},
new()
{
TitleKey = "Public.hero.slide3.title",
SubtitleKey = "Public.hero.slide3.subtitle",
Services = new List<HomeSlideServiceDto>
{
new() { Icon = "FaDesktop", TitleKey = "Public.hero.slide3.service1.title", DescriptionKey = "Public.hero.slide3.service1.desc" },
new() { Icon = "FaServer", TitleKey = "Public.hero.slide3.service2.title", DescriptionKey = "Public.hero.slide3.service2.desc" },
new() { Icon = "FaMobileAlt", TitleKey = "Public.hero.slide3.service3.title", DescriptionKey = "Public.hero.slide3.service3.desc" },
},
},
};
var features = new List<HomeFeatureDto>
{
new() { Icon = "FaUsers", TitleKey = "Public.features.reliable", DescriptionKey = "Public.features.reliable.desc" },
new() { Icon = "FaCalendarAlt", TitleKey = "App.Coordinator.Classroom.Planning", DescriptionKey = "Public.features.rapid.desc" },
new() { Icon = "FaBookOpen", TitleKey = "Public.features.expert", DescriptionKey = "Public.features.expert.desc" },
new() { Icon = "FaCreditCard", TitleKey = "Public.features.muhasebe", DescriptionKey = "Public.features.muhasebe.desc" },
new() { Icon = "FaRegComment", TitleKey = "Public.features.iletisim", DescriptionKey = "Public.features.iletisim.desc" },
new() { Icon = "FaPhone", TitleKey = "Public.features.mobil", DescriptionKey = "Public.features.mobil.desc" },
new() { Icon = "FaChartBar", TitleKey = "Public.features.scalable", DescriptionKey = "Public.features.scalable.desc" },
new() { Icon = "FaShieldAlt", TitleKey = "Public.features.guvenlik", DescriptionKey = "Public.features.guvenlik.desc" },
};
var solutions = new List<HomeSolutionDto>
{
new() { Icon = "FaDesktop", ColorClass = "bg-blue-600", TitleKey = "Public.services.web.title", DescriptionKey = "Public.solutions.web.desc" },
new() { Icon = "FaMobileAlt", ColorClass = "bg-purple-600", TitleKey = "Public.services.mobile.title", DescriptionKey = "Public.solutions.mobile.desc" },
new() { Icon = "FaServer", ColorClass = "bg-green-600", TitleKey = "Public.solutions.custom.title", DescriptionKey = "Public.solutions.custom.desc" },
new() { Icon = "FaDatabase", ColorClass = "bg-red-600", TitleKey = "Public.solutions.database.title", DescriptionKey = "Public.solutions.database.desc" },
};
return new Home
{
HeroBackgroundImageKey = "Public.home.hero.backgroundImage",
HeroPrimaryCtaKey = "Public.hero.cta.consultation",
HeroSecondaryCtaKey = "Public.hero.cta.discover",
FeaturesTitleKey = "Public.features.title",
FeaturesSubtitleKey = "Public.features.subtitle",
SolutionsTitleKey = "Public.solutions.title",
SolutionsSubtitleKey = "Public.solutions.subtitle",
CtaTitleKey = "Public.common.getStarted",
CtaSubtitleKey = "Public.common.contact",
CtaButtonLabelKey = "Public.common.learnMore",
SlidesJson = JsonSerializer.Serialize(slides),
FeaturesJson = JsonSerializer.Serialize(features),
SolutionsJson = JsonSerializer.Serialize(solutions),
};
}
private async Task UpsertLanguageTextAsync(string cultureName, string key, string value)
{
if (key.IsNullOrWhiteSpace())
{
return;
}
var normalizedCultureName = NormalizeCultureName(cultureName);
var resourceName = PlatformConsts.AppName;
var languageKey = await _languageKeyRepository.FirstOrDefaultAsync(a => a.ResourceName == resourceName && a.Key == key);
if (languageKey == null)
{
languageKey = await _languageKeyRepository.InsertAsync(new LanguageKey
{
ResourceName = resourceName,
Key = key,
}, autoSave: false);
}
var languageText = await _languageTextRepository.FirstOrDefaultAsync(a =>
a.ResourceName == resourceName &&
a.Key == languageKey.Key &&
a.CultureName == normalizedCultureName);
if (languageText == null)
{
await _languageTextRepository.InsertAsync(new LanguageText
{
ResourceName = resourceName,
Key = languageKey.Key,
CultureName = normalizedCultureName,
Value = value ?? string.Empty,
}, autoSave: false);
return;
}
languageText.Value = value ?? string.Empty;
await _languageTextRepository.UpdateAsync(languageText, autoSave: false);
}
private static string NormalizeCultureName(string cultureName)
{
if (cultureName.IsNullOrWhiteSpace())
{
return PlatformConsts.DefaultLanguage;
}
return cultureName.Split('-')[0].ToLowerInvariant();
}
}