From 81750f627b6422821fd89aef28dd6bde67e62c46 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 1 Jul 2021 12:19:27 +0300 Subject: [PATCH] Add Custom implementation to Create tenant --- .../SaasTenantAppService.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 services/saas/src/EShopOnAbp.SaasService.Application/SaasTenantAppService.cs diff --git a/services/saas/src/EShopOnAbp.SaasService.Application/SaasTenantAppService.cs b/services/saas/src/EShopOnAbp.SaasService.Application/SaasTenantAppService.cs new file mode 100644 index 00000000..b1cf4316 --- /dev/null +++ b/services/saas/src/EShopOnAbp.SaasService.Application/SaasTenantAppService.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; +using Volo.Abp.ObjectExtending; +using Volo.Abp.TenantManagement; + +namespace EShopOnAbp.SaasService +{ + [Dependency(ReplaceServices = true)] + public class SaasTenantAppService : TenantAppService, ITenantAppService + { + protected IDistributedEventBus DistributedEventBus { get; } + + public SaasTenantAppService( + ITenantRepository tenantRepository, + ITenantManager tenantManager, + IDataSeeder dataSeeder, + IDistributedEventBus distributedEventBus) : base(tenantRepository, tenantManager, dataSeeder) + { + DistributedEventBus = distributedEventBus; + } + + public override async Task CreateAsync(TenantCreateDto input) + { + var tenant = await TenantManager.CreateAsync(input.Name); + input.MapExtraPropertiesTo(tenant); + + await TenantRepository.InsertAsync(tenant); + + await CurrentUnitOfWork.SaveChangesAsync(); + + await DistributedEventBus.PublishAsync(new TenantCreatedEto + { + Id = tenant.Id, + Name = tenant.Name, + Properties = new Dictionary + { + { "AdminEmail", input.AdminEmailAddress }, + { "AdminPassword", input.AdminPassword } + } + }); + + return ObjectMapper.Map(tenant); + } + } +}