-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e10246c
commit 2d8aa50
Showing
114 changed files
with
7,498 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/Core/obj | ||
/.* | ||
/Core/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac" Version="8.0.0" /> | ||
<PackageReference Include="CsvHelper" Version="33.0.1" /> | ||
<PackageReference Include="Ensure.That" Version="10.1.0" /> | ||
<PackageReference Include="FuzzySharp" Version="2.0.2" /> | ||
<PackageReference Include="Humanizer.Core" Version="2.14.1" /> | ||
<PackageReference Include="Mapster" Version="7.4.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" /> | ||
<PackageReference Include="shortid" Version="4.0.0" /> | ||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" /> | ||
<PackageReference Include="TimeZoneConverter" Version="6.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Domains\Admin\Services\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Core.Interfaces.Data; | ||
|
||
namespace Core.Domains.Admin.Entities | ||
{ | ||
public class Asset : BaseEntity | ||
{ | ||
public override ContextNames Context => ContextNames.Partners; | ||
public AssetType Type { get; set; } | ||
public string Value { get; set; } | ||
public int TenantId { get; set; } | ||
public Tenant Tenant { get; set; } | ||
|
||
} | ||
|
||
//0 1 4 5 pada hai | ||
public enum AssetType | ||
{ | ||
Logo, | ||
Name, | ||
Icon, | ||
BackgroundColor, | ||
BrandNameLogo, | ||
[Obsolete("Use Currency.Logourl instead")] | ||
DigitalCurrencyLogo, | ||
DiscordSlashCommandName, | ||
StripeApiKey, | ||
DiscordServerInvite, | ||
OnMetaApiKey | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Core.Interfaces; | ||
using Core.Interfaces.Data; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Core.Domains.Admin.Entities | ||
{ | ||
public class Tenant : BaseEntity, INamed | ||
{ | ||
public override ContextNames Context => ContextNames.Partners; | ||
public List<Asset> Assets { get; set; } | ||
|
||
public Tenant(List<Asset> assets) | ||
{ | ||
Assets = assets; | ||
} | ||
|
||
public Tenant() | ||
{ | ||
|
||
} | ||
|
||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public int OwnerUserId { get; set; } | ||
public bool IsPublic { get; set; } | ||
public int CompanyId { get; set; } | ||
public int CurrencyId { get; set; } | ||
|
||
|
||
public SubscriptionTierType Tier { get; set; } | ||
|
||
|
||
public int DigitalCurrencyId { get; set; } | ||
|
||
public string GetAsset(AssetType type) | ||
{ | ||
var asset = Assets?.FirstOrDefault(a => a.Type == type); | ||
if (asset == null || string.IsNullOrEmpty(asset.Value)) | ||
{ | ||
return GetAssetDefaultValue(type); | ||
} | ||
return asset.Value; | ||
} | ||
|
||
public static string GetAssetDefaultValue(AssetType type) | ||
{ | ||
switch (type) | ||
{ | ||
case AssetType.Logo: | ||
return "https://tribalassets.blob.core.windows.net/partners/shared/emptyAssets/emptyBrandLogo.png"; | ||
case AssetType.Name: | ||
return ""; | ||
case AssetType.DiscordSlashCommandName: | ||
return "tr"; | ||
case AssetType.Icon: | ||
return "https://tribalassets.blob.core.windows.net/partners/shared/emptyAssets/emptyBrandLogo.png"; | ||
case AssetType.BrandNameLogo: | ||
return "https://tribalassets.blob.core.windows.net/partners/shared/emptyAssets/emptyBrandNameLogo.png"; | ||
case AssetType.DigitalCurrencyLogo: | ||
return "https://tribalassets.blob.core.windows.net/partners/shared/emptyAssets/emptyCurrencyLogo.png"; | ||
case AssetType.BackgroundColor: | ||
return "Dark"; | ||
case AssetType.DiscordServerInvite: | ||
return "https://discord.gg/hRcDzGnwhC"; | ||
} | ||
return ""; | ||
} | ||
|
||
|
||
|
||
[NotMapped] | ||
public bool IsUserTenantEmployee = false; | ||
} | ||
public enum SubscriptionTierType | ||
{ | ||
Free, | ||
Basic, | ||
Pro, | ||
Enterprise | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using Autofac; | ||
using Core.Domains.Admin.Entities; | ||
using Core.Interfaces.Data; | ||
using Core.Utilities; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Core.Domains.Admin | ||
{ | ||
public class TenantManager | ||
{ | ||
public TenantManager(ILifetimeScope scope, IMemoryCache cache) | ||
{ | ||
_db = scope.Resolve<IRepoReader>(); | ||
_cache = cache; | ||
|
||
} | ||
private int _tenantId = 1; | ||
private List<Tenant> _tenants = new(); | ||
private readonly IRepoReader _db; | ||
private readonly IMemoryCache _cache; | ||
|
||
public Tenant GetTenant() | ||
{ | ||
if(_tenants == null || _tenants.Empty()) | ||
{ | ||
LoadTenants(); | ||
} | ||
var tenant = _tenants.Where(t => t.Id == _tenantId).FirstOrDefault(); | ||
return tenant; | ||
|
||
} | ||
|
||
public void Reload() | ||
{ | ||
_tenants = LoadTenantsGraphFromDb(); | ||
_cache.Set("tenants", _tenants, TimeSpan.FromMinutes(1)); | ||
} | ||
|
||
private void LoadTenants() | ||
{ | ||
_tenants = _cache.Get<List<Tenant>>("tenants"); | ||
if (_tenants == null || _tenants.Empty()) | ||
{ | ||
Reload(); | ||
} | ||
} | ||
|
||
private List<Tenant> LoadTenantsGraphFromDb() | ||
{ | ||
var batch = _db.GetBatch("select * from admin.tenants;" + | ||
"select * from admin.assets;", null, | ||
new List<Type>() { typeof(Tenant), typeof(Asset) }.ToArray()); | ||
var tenants = batch[typeof(Tenant)].Cast<Tenant>().ToList(); | ||
|
||
var assets = batch[typeof(Asset)].Cast<Asset>().ToList(); | ||
foreach(var tenant in tenants) | ||
{ | ||
|
||
tenant.Assets = assets.Where(assets => assets.TenantId == tenant.Id).ToList(); | ||
tenant.Assets.ForEach(a => a.Tenant = tenant); | ||
} | ||
return tenants; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
public void SetTenant(int tenantId, bool refreshCache = false) | ||
{ | ||
var tenant = _tenants?.FirstOrDefault(a => a.Id == tenantId); | ||
if (refreshCache) | ||
Reload(); | ||
if (tenant == null) | ||
{ | ||
LoadTenants(); | ||
tenant = _tenants?.FirstOrDefault(a => a.Id == tenantId); | ||
} | ||
if (tenant == null) | ||
{ | ||
throw new Exception($"Cant find a suitable tenant for tenant id {tenantId}"); | ||
} | ||
_tenantId = tenant.Id; | ||
} | ||
|
||
public List<Tenant> GetTenants() | ||
{ | ||
LoadTenants(); | ||
return _tenants; | ||
} | ||
|
||
|
||
|
||
public Tenant GetTenant(int tenantId) | ||
{ | ||
LoadTenants(); | ||
var tenant = _tenants?.Find(t => t.Id == tenantId); | ||
return tenant; | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.