94 lines
4.1 KiB
C#
94 lines
4.1 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);
|
|
|
|
modelBuilder.Entity<Post>().HasIndex(s => s.PostName).IsUnique();
|
|
|
|
modelBuilder.Entity<Employee>().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique();
|
|
|
|
modelBuilder.Entity<Classroom>().HasIndex(d => new { d.Number }).IsUnique();
|
|
|
|
modelBuilder.Entity<DisciplineBlock>().HasIndex(d => new { d.Title }).IsUnique();
|
|
|
|
modelBuilder.Entity<Discipline>().HasIndex(d => new { d.DisciplineName }).IsUnique();
|
|
|
|
modelBuilder.Entity<LecturerAcademicDegree>().HasIndex(d => new { d.LecturerAcademicDegreeName }).IsUnique();
|
|
|
|
modelBuilder.Entity<LecturerAcademicRank>().HasIndex(d => new { d.LecturerAcademicRankName }).IsUnique();
|
|
|
|
modelBuilder.Entity<Lecturer>().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique();
|
|
|
|
modelBuilder.Entity<EducationDirection>().HasIndex(d => new { d.Title, d.Profile }).IsUnique();
|
|
|
|
modelBuilder.Entity<TimeNorm>().HasIndex(d => new { d.TimeNormName, d.TimeNormShortName }).IsUnique();
|
|
|
|
modelBuilder.Entity<AcademicPlan>().HasIndex(d => new { d.EducationDirectionId, d.YearEntrance }).IsUnique();
|
|
|
|
modelBuilder.Entity<AcademicPlanRecord>().HasIndex(d => new { d.AcademicPlanId, d.DisciplineId, d.Semester }).IsUnique();
|
|
|
|
modelBuilder.Entity<AcademicPlanRecordTimeNormHour>().HasIndex(d => new { d.AcademicPlanRecordId, d.TimeNormId }).IsUnique();
|
|
|
|
modelBuilder.Entity<StudentGroup>().HasIndex(d => new { d.AcademicPlanId, d.EnrollmentYear, d.GroupNumber }).IsUnique();
|
|
|
|
modelBuilder.Entity<Student>().HasIndex(d => new { d.NumberOfBook }).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<Post> Posts { set; get; }
|
|
public virtual DbSet<Employee> Employees { set; get; }
|
|
public virtual DbSet<EmployeePost> EmployeePosts { set; get; }
|
|
public virtual DbSet<Classroom> Classrooms { set; get; }
|
|
public virtual DbSet<DisciplineBlock> DisciplineBlocks { set; get; }
|
|
public virtual DbSet<Discipline> Disciplines { set; get; }
|
|
public virtual DbSet<LecturerAcademicDegree> LecturerAcademicDegrees { set; get; }
|
|
public virtual DbSet<LecturerAcademicRank> LecturerAcademicRanks { set; get; }
|
|
public virtual DbSet<LecturerPost> LecturerPosts { set; get; }
|
|
public virtual DbSet<Lecturer> Lecturers { set; get; }
|
|
public virtual DbSet<EducationDirection> EducationDirections { set; get; }
|
|
public virtual DbSet<TimeNorm> TimeNorms { set; get; }
|
|
public virtual DbSet<AcademicPlan> AcademicPlans { set; get; }
|
|
public virtual DbSet<AcademicPlanRecord> AcademicPlanRecords { set; get; }
|
|
public virtual DbSet<AcademicPlanRecordTimeNormHour> AcademicPlanRecordTimeNormHours { set; get; }
|
|
public virtual DbSet<StudentGroup> StudentGroups { set; get; }
|
|
public virtual DbSet<Student> Students { set; get; }
|
|
#endregion
|
|
}
|
|
} |