using System; using System.Threading.Tasks; using Kurs.Platform.Extensions; using Kurs.Platform.ListForms.DynamicApi; using Kurs.Platform.Localization; using Microsoft.AspNetCore.Authorization; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Local; using Volo.Abp.Identity; using Volo.Abp.TenantManagement; namespace Kurs.Platform.Tenants; [Authorize(TenantManagementPermissions.Tenants.Default)] [Dependency(ReplaceServices = true)] public class PlatformTenantAppService : TenantAppService, IPlatformTenantAppService { private readonly ITenantRepository tenantRepository; private readonly IDistributedEventBus distributedEventBus; private readonly ILocalEventBus localEventBus; public PlatformTenantAppService( ITenantRepository tenantRepository, ITenantManager tenantManager, IDataSeeder dataSeeder, IDistributedEventBus distributedEventBus, ILocalEventBus localEventBus) : base(tenantRepository, tenantManager, dataSeeder, distributedEventBus, localEventBus) { this.tenantRepository = tenantRepository; this.distributedEventBus = distributedEventBus; this.localEventBus = localEventBus; LocalizationResource = typeof(PlatformResource); } public override Task GetAsync(Guid id) { return base.GetAsync(id); } [AllowAnonymous] public async Task GetByNameAsync(string name) { return ObjectMapper.Map( await TenantRepository.FindByNameAsync(name) ); } [AllowAnonymous] public override Task> GetListAsync(GetTenantsInput input) => base.GetListAsync(input); [RemoteService(false)] public override Task CreateAsync(TenantCreateDto input) => throw new NotImplementedException(); [RemoteService(false)] public override Task UpdateAsync(Guid id, TenantUpdateDto input) => base.UpdateAsync(id, input); //TODO: Update ve Delete ConnectionString: Validation vt varsa değiştireceği zaman uyarı verilmeli [AllowAnonymous] public async Task GetByNameDetailAsync(string name) { var tenant = await TenantRepository.FindByNameAsync(name); if (tenant == null) { return null; //throw new EntityNotFoundException($"Tenant bulunamadı: {name}"); } var dto = ObjectMapper.Map(tenant); dto.IsActive = tenant.GetIsActive(); dto.OrganizationName = tenant.GetOrganizationName(); dto.Founder = tenant.GetFounder(); dto.VknTckn = tenant.GetVknTckn(); dto.TaxOffice = tenant.GetTaxOffice(); dto.Country = tenant.GetCountry(); dto.City = tenant.GetCity(); dto.District = tenant.GetDistrict(); dto.Street = tenant.GetStreet(); dto.Address1 = tenant.GetAddress1(); dto.Address2 = tenant.GetAddress2(); dto.PostalCode = tenant.GetPostalCode(); dto.PhoneNumber = tenant.GetPhoneNumber(); dto.MobileNumber = tenant.GetMobileNumber(); dto.FaxNumber = tenant.GetFaxNumber(); dto.Email = tenant.GetEmail(); dto.Website = tenant.GetWebsite(); dto.MenuGroup = tenant.GetMenuGroup(); return dto; } [Authorize(TenantManagementPermissions.Tenants.Update)] public async Task PostSeedTenantDataAsync(CreateUpdateTenantInput input) { var tenant = await tenantRepository.FindAsync(input.Id.Value) ?? throw new EntityNotFoundException(); await distributedEventBus.PublishAsync( new ApplyDatabaseMigrationsEto { TenantId = tenant.Id, DatabaseName = tenant.Name, Properties = { { IdentityDataSeedContributor.AdminEmailPropertyName, input.AdminEmail }, { IdentityDataSeedContributor.AdminPasswordPropertyName, input.AdminPassword }, { IdentityDataSeedContributor.AdminUserNamePropertyName, input.AdminEmail } } }); } }