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.PostName).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.Number }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.Title }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.DisciplineName }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.LecturerAcademicDegreeName }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.LecturerAcademicRankName }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.Title, d.Profile }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.TimeNormName, d.TimeNormShortName }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.EducationDirectionId, d.YearEntrance }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.AcademicPlanId, d.DisciplineId, d.Semester }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.AcademicPlanRecordId, d.TimeNormId }).IsUnique(); modelBuilder.Entity().HasIndex(d => new { d.AcademicPlanId, d.EnrollmentYear, d.GroupNumber }).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 Posts { set; get; } public virtual DbSet Employees { set; get; } public virtual DbSet EmployeePosts { set; get; } public virtual DbSet Classrooms { set; get; } public virtual DbSet DisciplineBlocks { set; get; } public virtual DbSet Disciplines { set; get; } public virtual DbSet LecturerAcademicDegrees { set; get; } public virtual DbSet LecturerAcademicRanks { set; get; } public virtual DbSet LecturerPosts { set; get; } public virtual DbSet Lecturers { set; get; } public virtual DbSet EducationDirections { set; get; } public virtual DbSet TimeNorms { set; get; } public virtual DbSet AcademicPlans { set; get; } public virtual DbSet AcademicPlanRecords { set; get; } public virtual DbSet AcademicPlanRecordTimeNormHours { set; get; } public virtual DbSet StudentGroups { set; get; } #endregion } }