54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using DatabaseCore.Models.Department;
|
|
using DatabaseCore.Models.Security;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DatabaseCore
|
|
{
|
|
public class DatabaseContext : DbContext
|
|
{
|
|
public DatabaseContext() : base() { }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (optionsBuilder.IsConfigured == false)
|
|
{
|
|
#if RELEASE
|
|
var connectionString = ModuleTools.ServiceProvider.ServiceProviderLoader.GetConfigData("connectionString");
|
|
optionsBuilder.UseSqlServer(connectionString);
|
|
#endif
|
|
|
|
#if DEBUG
|
|
optionsBuilder.UseSqlServer(@"Data Source=CHESHIR\SQLEXPRESS;Initial Catalog=DepartmentDatabasePortal;persist security info=True;user id=admin;password=cheshirSA123;MultipleActiveResultSets=True;");
|
|
#endif
|
|
}
|
|
base.OnConfiguring(optionsBuilder);
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<EnviromentSetting>().HasIndex(s => s.Key).IsUnique();
|
|
|
|
modelBuilder.Entity<Role>().HasIndex(s => s.RoleName).IsUnique();
|
|
|
|
modelBuilder.Entity<User>().HasIndex(s => s.UserName).IsUnique();
|
|
|
|
modelBuilder.Entity<EmployeePost>().HasIndex(s => s.EmployeePostName).IsUnique();
|
|
|
|
modelBuilder.Entity<Employee>().HasIndex(p => new { p.FirstName, p.LastName, p.Patronymic }).IsUnique();
|
|
}
|
|
|
|
#region Security
|
|
public virtual DbSet<Access> Accesses { set; get; }
|
|
public virtual DbSet<EnviromentSetting> EnviromentSettings { set; get; }
|
|
public virtual DbSet<Role> Roles { set; get; }
|
|
public virtual DbSet<User> Users { set; get; }
|
|
public virtual DbSet<UserRole> UserRoles { set; get; }
|
|
#endregion
|
|
|
|
#region Department
|
|
public virtual DbSet<EmployeePost> EmployeePosts { set; get; }
|
|
public virtual DbSet<Employee> Employees { set; get; }
|
|
public virtual DbSet<EmployeeEmployeePost> EmployeeEmployeePosts { set; get; }
|
|
#endregion
|
|
}
|
|
} |