erp-platform/api/src/Kurs.Platform.Application/Tenants/PlatformTenantAppService.cs

117 lines
4.2 KiB
C#
Raw Normal View History

2025-05-06 06:45:49 +00:00
using System;
using System.Threading.Tasks;
2025-08-11 06:34:44 +00:00
using Kurs.Platform.Extensions;
2025-05-06 06:45:49 +00:00
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<TenantDto> GetAsync(Guid id)
{
return base.GetAsync(id);
}
[AllowAnonymous]
public async Task<TenantDto> GetByNameAsync(string name)
{
return ObjectMapper.Map<Tenant, TenantDto>(
await TenantRepository.FindByNameAsync(name)
);
}
2025-05-06 06:45:49 +00:00
[AllowAnonymous]
public override Task<PagedResultDto<TenantDto>> GetListAsync(GetTenantsInput input) => base.GetListAsync(input);
[RemoteService(false)]
public override Task<TenantDto> CreateAsync(TenantCreateDto input) => throw new NotImplementedException();
[RemoteService(false)]
public override Task<TenantDto> UpdateAsync(Guid id, TenantUpdateDto input) => base.UpdateAsync(id, input);
//TODO: Update ve Delete ConnectionString: Validation vt varsa değiştireceği zaman uyarı verilmeli
2025-08-11 06:34:44 +00:00
[AllowAnonymous]
public async Task<CustomTenantDto> 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, CustomTenantDto>(tenant);
dto.IsActive = tenant.GetIsActive();
2025-08-23 17:56:54 +00:00
dto.OrganizationName = tenant.GetOrganizationName();
2025-08-11 06:34:44 +00:00
dto.Founder = tenant.GetFounder();
dto.VknTckn = tenant.GetVknTckn();
dto.TaxOffice = tenant.GetTaxOffice();
dto.Country = tenant.GetCountry();
dto.City = tenant.GetCity();
2025-08-19 19:26:50 +00:00
dto.District = tenant.GetDistrict();
dto.Street = tenant.GetStreet();
2025-10-21 14:47:16 +00:00
dto.Address1 = tenant.GetAddress1();
2025-08-19 19:26:50 +00:00
dto.Address2 = tenant.GetAddress2();
2025-08-11 06:34:44 +00:00
dto.PostalCode = tenant.GetPostalCode();
2025-11-03 20:31:28 +00:00
dto.PhoneNumber = tenant.GetPhoneNumber();
dto.MobileNumber = tenant.GetMobileNumber();
dto.FaxNumber = tenant.GetFaxNumber();
2025-08-11 06:34:44 +00:00
dto.Email = tenant.GetEmail();
dto.Website = tenant.GetWebsite();
dto.MenuGroup = tenant.GetMenuGroup();
2025-08-11 06:34:44 +00:00
return dto;
}
2025-05-06 06:45:49 +00:00
[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 }
}
});
}
}