2021-04-03 09:45:22 +04:00
|
|
|
|
using DatabaseCore.Models.Department;
|
|
|
|
|
using DatabaseCore.Models.Security;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace DatabaseCore
|
|
|
|
|
{
|
|
|
|
|
public class DatabaseContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
public DatabaseContext() : base() { }
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
if (optionsBuilder.IsConfigured == false)
|
|
|
|
|
{
|
|
|
|
|
#if RELEASE
|
2021-03-28 19:15:55 +04:00
|
|
|
|
var connectionString = ModuleTools.ServiceProvider.ServiceProviderLoader.GetConfigData("connectionString");
|
2021-03-26 20:09:52 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 21:30:29 +04:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.Entity<EnviromentSetting>().HasIndex(s => s.Key).IsUnique();
|
2021-04-02 22:21:34 +04:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
modelBuilder.Entity<Post>().HasIndex(s => s.PostName).IsUnique();
|
2021-04-03 09:45:22 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<Employee>().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique();
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<Classroom>().HasIndex(d => new { d.Number }).IsUnique();
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<DisciplineBlock>().HasIndex(d => new { d.Title }).IsUnique();
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<Discipline>().HasIndex(d => new { d.DisciplineName }).IsUnique();
|
2021-04-03 22:04:11 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<LecturerAcademicDegree>().HasIndex(d => new { d.LecturerAcademicDegreeName }).IsUnique();
|
2021-04-03 22:04:11 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<LecturerAcademicRank>().HasIndex(d => new { d.LecturerAcademicRankName }).IsUnique();
|
2021-04-03 22:04:11 +04:00
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
modelBuilder.Entity<Lecturer>().HasIndex(d => new { d.FirstName, d.LastName, d.Patronymic }).IsUnique();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<EducationDirection>().HasIndex(d => new { d.Title, d.Profile }).IsUnique();
|
2021-04-06 22:07:11 +04:00
|
|
|
|
|
|
|
|
|
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();
|
2021-04-12 10:01:42 +04:00
|
|
|
|
|
2021-04-13 12:52:45 +04:00
|
|
|
|
// ругается на циклическое каскадное удаление, так что по нормам времени убираем ее
|
|
|
|
|
modelBuilder.Entity<AcademicPlanRecordTimeNormHour>()
|
|
|
|
|
.HasOne(x => x.TimeNorm)
|
|
|
|
|
.WithMany(x => x.AcademicPlanRecordTimeNormHours)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
2021-04-12 10:01:42 +04:00
|
|
|
|
modelBuilder.Entity<StudentGroup>().HasIndex(d => new { d.AcademicPlanId, d.EnrollmentYear, d.GroupNumber }).IsUnique();
|
2021-04-12 16:57:29 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Student>().HasIndex(d => new { d.NumberOfBook }).IsUnique();
|
2021-04-13 12:52:45 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Order>().HasIndex(d => new { d.OrderNumber }).IsUnique();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderStudentRecord>().HasIndex(d => new { d.StudentId, d.OrderId }).IsUnique();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderStudentRecord>()
|
|
|
|
|
.HasOne(x => x.StudentGroupFrom)
|
|
|
|
|
.WithMany(p => p.OrderStudentRecordFroms)
|
|
|
|
|
.HasForeignKey(pt => pt.StudentGroupFromId)
|
|
|
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderStudentRecord>()
|
|
|
|
|
.HasOne(x => x.StudentGroupTo)
|
|
|
|
|
.WithMany(p => p.OrderStudentRecordTos)
|
|
|
|
|
.HasForeignKey(pt => pt.StudentGroupToId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
// ругается на циклическое каскадное удаление, так что по нормам времени убираем ее
|
|
|
|
|
modelBuilder.Entity<OrderStudentRecord>()
|
|
|
|
|
.HasOne(x => x.Student)
|
|
|
|
|
.WithMany(x => x.OrderStudentRecords)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
2021-04-03 09:45:22 +04:00
|
|
|
|
}
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-03 09:45:22 +04:00
|
|
|
|
#region Security
|
2021-03-26 20:09:52 +04:00
|
|
|
|
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
|
2021-04-05 12:25:10 +04:00
|
|
|
|
public virtual DbSet<Post> Posts { set; get; }
|
2021-04-03 09:45:22 +04:00
|
|
|
|
public virtual DbSet<Employee> Employees { set; get; }
|
2021-04-05 12:25:10 +04:00
|
|
|
|
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; }
|
2021-04-03 22:04:11 +04:00
|
|
|
|
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-05 14:20:07 +04:00
|
|
|
|
public virtual DbSet<EducationDirection> EducationDirections { set; get; }
|
2021-04-06 22:07:11 +04:00
|
|
|
|
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; }
|
2021-04-12 10:01:42 +04:00
|
|
|
|
public virtual DbSet<StudentGroup> StudentGroups { set; get; }
|
2021-04-12 16:57:29 +04:00
|
|
|
|
public virtual DbSet<Student> Students { set; get; }
|
2021-04-13 12:52:45 +04:00
|
|
|
|
public virtual DbSet<Order> Orders { set; get; }
|
|
|
|
|
public virtual DbSet<OrderStudentRecord> OrderStudentRecords { set; get; }
|
2021-04-27 15:14:35 +04:00
|
|
|
|
public virtual DbSet<OrderSyncHistory> OrderSyncHistories { set; get; }
|
|
|
|
|
public virtual DbSet<OrderSyncHistoryRecord> OrderSyncHistoryRecords { set; get; }
|
2021-04-03 09:45:22 +04:00
|
|
|
|
#endregion
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|