using Application.Abstractions.Data; using Domain.Entities.Common; using MediatR; using Microsoft.EntityFrameworkCore; using DomainConfig = Domain.Entities.Common.Config; namespace Application.Features.Config.Commands; public sealed class UpdateConfigCommandHandler(IAppDbContext db) : IRequestHandler { public async Task Handle(UpdateConfigCommand request, CancellationToken cancellationToken) { var config = await db.Config.OrderByDescending(x => x.ID).FirstOrDefaultAsync(cancellationToken); if (config is null) { config = DomainConfig.Create(); db.Config.Add(config); } var basic = new BasicConfig { SiteName = request.Basic.SiteName, DefaultFeeAmount = request.Basic.DefaultFeeAmount, DefaultFeeRate = request.Basic.DefaultFeeRate }; var meta = new MetaConfig { Keywords = request.Meta.Keywords, Description = request.Meta.Description, Author = request.Meta.Author, Viewport = request.Meta.Viewport, ApplicationName = request.Meta.ApplicationName, Generator = request.Meta.Generator, Robots = request.Meta.Robots, Adds = request.Meta.Adds }; var company = new CompanyConfig { Name = request.Company.Name, RegNo = request.Company.RegNo, Owner = request.Company.Owner, Tel = request.Company.Tel, Fax = request.Company.Fax, RetailSaleNo = request.Company.RetailSaleNo, AddedSaleNo = request.Company.AddedSaleNo, ZipCode = request.Company.ZipCode, Hosting = request.Company.Hosting, AdminName = request.Company.AdminName, AdminEmail = request.Company.AdminEmail, SiteUrl = request.Company.SiteUrl, BankCode = request.Company.BankCode, BankOwner = request.Company.BankOwner, BankNumber = request.Company.BankNumber }; var account = new AccountConfig { IsRegisterBlock = request.Account.IsRegisterBlock, IsRegisterEmailAuth = request.Account.IsRegisterEmailAuth, PasswordMinLength = request.Account.PasswordMinLength, PasswordUppercaseLength = request.Account.PasswordUppercaseLength, PasswordNumbersLength = request.Account.PasswordNumbersLength, PasswordSpecialcharsLength = request.Account.PasswordSpecialcharsLength, DeniedEmailList = request.Account.DeniedEmailList, DeniedNameList = request.Account.DeniedNameList, ChangeEmailDay = request.Account.ChangeEmailDay, ChangeNameDay = request.Account.ChangeNameDay, ChangeSummaryDay = request.Account.ChangeSummaryDay, ChangeIntroDay = request.Account.ChangeIntroDay, ChangePasswordDay = request.Account.ChangePasswordDay, MaxLoginTryCount = request.Account.MaxLoginTryCount, MaxLoginTryLimitSecond = request.Account.MaxLoginTryLimitSecond }; var emailTemplate = new EmailTemplateConfig { RegisterEmailFormTitle = request.EmailTemplate.RegisterEmailFormTitle, RegisterEmailFormContent = request.EmailTemplate.RegisterEmailFormContent, RegistrationEmailFormTitle = request.EmailTemplate.RegistrationEmailFormTitle, RegistrationEmailFormContent = request.EmailTemplate.RegistrationEmailFormContent, ResetPasswordEmailFormTitle = request.EmailTemplate.ResetPasswordEmailFormTitle, ResetPasswordEmailFormContent = request.EmailTemplate.ResetPasswordEmailFormContent, ChangedPasswordEmailFormTitle = request.EmailTemplate.ChangedPasswordEmailFormTitle, ChangedPasswordEmailFormContent = request.EmailTemplate.ChangedPasswordEmailFormContent, WithdrawEmailFormTitle = request.EmailTemplate.WithdrawEmailFormTitle, WithdrawEmailFormContent = request.EmailTemplate.WithdrawEmailFormContent, EmailVerifyFormTitle = request.EmailTemplate.EmailVerifyFormTitle, EmailVerifyFormContent = request.EmailTemplate.EmailVerifyFormContent, ChangedEmailFormTitle = request.EmailTemplate.ChangedEmailFormTitle, ChangedEmailFormContent = request.EmailTemplate.ChangedEmailFormContent }; var external = new ExternalApiConfig { YouTubeApiKeyEnc = request.External.YouTubeApiKeyEnc, YouTubeApiName = request.External.YouTubeApiName, GoogleClientId = request.External.GoogleClientId, GoogleClientSecretEnc = request.External.GoogleClientSecretEnc, GoogleAppId = request.External.GoogleAppId }; var payment = new PaymentConfig { }; config.Update( basic, meta, company, account, emailTemplate, external, payment ); await db.SaveChangesAsync(cancellationToken); } }