protected virtual async Task <TenantCacheItem> GetCacheItemAsync(Guid?id, string name) { var cacheKey = CalculateCacheKey(id, name); var cacheItem = await Cache.GetAsync(cacheKey, considerUow : true); if (cacheItem != null) { return(cacheItem); } if (id.HasValue) { using (CurrentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities! { var tenant = await TenantRepository.FindAsync(id.Value); return(await SetCacheAsync(cacheKey, tenant)); } } if (!name.IsNullOrWhiteSpace()) { using (CurrentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities! { var tenant = await TenantRepository.FindByNameAsync(name); return(await SetCacheAsync(cacheKey, tenant)); } } throw new AbpException("Both id and name can't be invalid."); }
public virtual async Task <TenantDto> GetAsync(Guid id) { var tenant = await TenantRepository.FindAsync(id, false); if (tenant == null) { throw new UserFriendlyException(L["TenantNotFoundById", id]); } return(ObjectMapper.Map <Tenant, TenantDto>(tenant)); }
public virtual async Task DeleteAsync(Guid id) { var tenant = await TenantRepository.FindAsync(id); if (tenant == null) { return; } await TenantRepository.DeleteAsync(tenant); }
public virtual async Task <TenantConfiguration> FindAsync(Guid id) { using (CurrentTenant.Change(null)) { var tenant = await TenantRepository.FindAsync(id); if (tenant == null) { return(null); } return(ObjectMapper.Map <Tenant, TenantConfiguration> (tenant)); } }
public virtual async Task <TenantConfiguration> FindAsync(Guid id) { using (CurrentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities! { var tenant = await TenantRepository.FindAsync(id); if (tenant == null) { return(null); } return(ObjectMapper.Map <Tenant, TenantConfiguration>(tenant)); } }
/// <summary> /// Validate tenant /// </summary> /// <param name="tenantId"></param> /// <param name="expectedId"></param> /// <returns></returns> protected virtual async Task ValidateTenantAsync(Guid tenantId, Guid?expectedId = null) { var tenant = await TenantRepository.FindAsync(tenantId, false); if (tenant == null) { throw new AbpException($"Can't find any tenant by '{tenantId}'."); } var mapTenant = await MapTenantRepository.FindExpectedTenantIdAsync(tenantId, expectedId); if (mapTenant != null) { throw new AbpException($"Duplicate 'MapTenant' tenantId: '{tenantId}'."); } }
public virtual async Task DeleteAsync(Guid id) { var tenant = await TenantRepository.FindAsync(id); if (tenant == null) { return; } var deleteEventData = new DeleteEventData { Id = id }; await TenantRepository.DeleteAsync(tenant); await EventBus.PublishAsync(deleteEventData); }
/// <summary> /// Validate tenant /// </summary> /// <param name="tenantId"></param> /// <param name="expectedId"></param> /// <returns></returns> public virtual async Task ValidateTenantAsync(Guid tenantId, Guid?expectedId = null) { var tenant = await TenantRepository.FindAsync(tenantId, false); if (tenant == null) { throw new AbpException($"MapTenant tenant: {tenantId} was not exist."); } var mapTenant = await MapTenantRepository.FindExpectedTenantIdAsync(tenantId, expectedId); if (mapTenant != null) { throw new AbpException($"Duplicate tenant id: {tenantId}."); } }