DepartmentProject/DepartmentPortal/Common/DatabaseCore/DatabaseContext.cs

73 lines
2.8 KiB
C#
Raw Normal View History

2021-04-03 09:45:22 +04:00
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();
2021-04-03 10:58:34 +04:00
modelBuilder.Entity<User>().HasIndex(s => s.UserName);
2021-04-03 10:57:40 +04:00
modelBuilder.Entity<Post>().HasIndex(s => s.PostName).IsUnique();
2021-04-03 09:45:22 +04:00
modelBuilder.Entity<Employee>().HasIndex(p => new { p.FirstName, p.LastName, p.Patronymic }).IsUnique();
2021-04-03 13:41:19 +04:00
modelBuilder.Entity<Classroom>().HasIndex(p => new { p.Number }).IsUnique();
2021-04-03 19:03:56 +04:00
modelBuilder.Entity<DisciplineBlock>().HasIndex(p => new { p.Title }).IsUnique();
modelBuilder.Entity<Discipline>().HasIndex(p => new { p.DisciplineName }).IsUnique();
modelBuilder.Entity<LecturerAcademicDegree>().HasIndex(p => new { p.LecturerAcademicDegreeName }).IsUnique();
modelBuilder.Entity<LecturerAcademicRank>().HasIndex(p => new { p.LecturerAcademicRankName }).IsUnique();
modelBuilder.Entity<Lecturer>().HasIndex(p => new { p.FirstName, p.LastName, p.Patronymic }).IsUnique();
2021-04-03 09:45:22 +04:00
}
2021-04-03 09:45:22 +04:00
#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; }
2021-04-03 09:45:22 +04:00
#endregion
#region Department
public virtual DbSet<Post> Posts { set; get; }
2021-04-03 09:45:22 +04:00
public virtual DbSet<Employee> Employees { set; get; }
public virtual DbSet<EmployeePost> EmployeePosts { set; get; }
2021-04-03 13:41:19 +04:00
public virtual DbSet<Classroom> Classrooms { set; get; }
2021-04-03 19:03:56 +04:00
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; }
2021-04-03 09:45:22 +04:00
#endregion
}
}