2019-12-03 15:20:21 +00:00
|
|
|
|
using ASC.Core.Common.EF.Model;
|
2019-12-10 14:47:48 +00:00
|
|
|
|
|
2019-12-03 15:20:21 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Core.Common.EF.Context
|
|
|
|
|
{
|
|
|
|
|
public class TenantDbContext : BaseDbContext
|
|
|
|
|
{
|
|
|
|
|
public DbSet<DbTenant> Tenants { get; set; }
|
|
|
|
|
public DbSet<User> Users { get; set; }
|
|
|
|
|
public DbSet<UserSecurity> UserSecurity { get; set; }
|
|
|
|
|
public DbSet<DbTenantVersion> TenantVersion { get; set; }
|
|
|
|
|
public DbSet<DbTenantPartner> TenantPartner { get; set; }
|
|
|
|
|
public DbSet<DbTenantForbiden> TenantForbiden { get; set; }
|
2019-12-10 14:47:48 +00:00
|
|
|
|
public DbSet<TenantIpRestrictions> TenantIpRestrictions { get; set; }
|
2019-12-03 15:20:21 +00:00
|
|
|
|
public DbSet<DbCoreSettings> CoreSettings { get; set; }
|
|
|
|
|
|
2019-12-17 08:27:38 +00:00
|
|
|
|
public TenantDbContext() { }
|
|
|
|
|
public TenantDbContext(DbContextOptions<TenantDbContext> options)
|
|
|
|
|
: base(options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 15:20:21 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.AddUser();
|
|
|
|
|
|
|
|
|
|
modelBuilder.AddCoreSettings();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<DbTenant>()
|
|
|
|
|
.HasOne(r => r.Partner)
|
|
|
|
|
.WithOne(r => r.Tenant)
|
|
|
|
|
.HasForeignKey<DbTenantPartner>(r => new { r.TenantId })
|
|
|
|
|
.HasPrincipalKey<DbTenant>(r => new { r.Id });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TenantDbExtension
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddTenantDbContextService(this IServiceCollection services)
|
|
|
|
|
{
|
2019-12-10 15:06:51 +00:00
|
|
|
|
return services.AddDbContextManagerService<TenantDbContext>();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|