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().HasIndex(s => s.Key).IsUnique(); modelBuilder.Entity().HasIndex(s => s.RoleName).IsUnique(); modelBuilder.Entity().HasIndex(s => s.UserName); modelBuilder.Entity().HasIndex(s => s.EmployeePostName).IsUnique(); modelBuilder.Entity().HasIndex(p => new { p.FirstName, p.LastName, p.Patronymic }).IsUnique(); modelBuilder.Entity().HasIndex(p => new { p.Number }).IsUnique(); modelBuilder.Entity().HasIndex(p => new { p.Title }).IsUnique(); modelBuilder.Entity().HasIndex(p => new { p.DisciplineName }).IsUnique(); } #region Security public virtual DbSet Accesses { set; get; } public virtual DbSet EnviromentSettings { set; get; } public virtual DbSet Roles { set; get; } public virtual DbSet Users { set; get; } public virtual DbSet UserRoles { set; get; } #endregion #region Department public virtual DbSet EmployeePosts { set; get; } public virtual DbSet Employees { set; get; } public virtual DbSet EmployeeEmployeePosts { set; get; } public virtual DbSet Classrooms { set; get; } public virtual DbSet DisciplineBlocks { set; get; } public virtual DbSet Disciplines { set; get; } #endregion } }