diff --git a/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs new file mode 100644 index 0000000..0c9cae7 --- /dev/null +++ b/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs @@ -0,0 +1,135 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicsContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StorageContracts; +using UniversityContracts.ViewModels; +using UniversityDataModels.Enums; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class WorkerLogic : IWorkerLogic + { + private readonly ILogger _logger; + private readonly IWorkerStorage _workerStorage; + public WorkerLogic(ILogger logger, IWorkerStorage + workerStorage) + { + _logger = logger; + _workerStorage = workerStorage; + } + public List? ReadList(WorkerSearchModel? model) + { + _logger.LogInformation("ReadList. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: {PhoneNumber}" + + "Email: {Email}.Id:{Id} ", + model?.FirstName, model?.LastName, model?.PhoneNumber, model?.Email, model?.Id); + var list = model == null ? _workerStorage.GetFullList() : + _workerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public WorkerViewModel? ReadElement(WorkerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadList. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: {PhoneNumber}" + + "Email: {Email}.Id:{Id} ", + model?.FirstName, model?.LastName, model?.PhoneNumber, model?.Email, model?.Id); + var element = _workerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(WorkerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_workerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(WorkerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FirstName)) + { + throw new ArgumentNullException("Нет имени пользователя", + nameof(model.FirstName)); + } + if (string.IsNullOrEmpty(model.LastName)) + { + throw new ArgumentNullException("Нет фамилии пользователя", + nameof(model.LastName)); + } + if (string.IsNullOrEmpty(model.PhoneNumber)) + { + throw new ArgumentNullException("Должен быть номер телефона", nameof(model.PhoneNumber)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Не указана почта", + nameof(model.Email)); + } + _logger.LogInformation("Worker. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: " + + "{PhoneNumber}.Email: {Email}.Id:{Id}", + model.FirstName, model.LastName, model.PhoneNumber, model.Email, model.Id); + var element = _workerStorage.GetElement(new WorkerSearchModel + { + FirstName = model.FirstName, + LastName = model.LastName, + PhoneNumber = model.PhoneNumber, + Email = model.Email + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Данный пользователь уже существует"); + } + } + } +} diff --git a/University/UniversityContracts/SearchModels/WorkerSearchModel.cs b/University/UniversityContracts/SearchModels/WorkerSearchModel.cs index f9160a5..e103afe 100644 --- a/University/UniversityContracts/SearchModels/WorkerSearchModel.cs +++ b/University/UniversityContracts/SearchModels/WorkerSearchModel.cs @@ -11,7 +11,6 @@ namespace UniversityContracts.SearchModels public int? Id { get; set; } public string? FirstName { get; set; } public string? LastName { get; set; } - public string? MiddleName { get; set; } public string? PhoneNumber { get; set; } public string? Email { get; set; } } diff --git a/University/UniversityDataModels/UniversityDataModels.csproj b/University/UniversityDataModels/UniversityDataModels.csproj index 502233c..fa71b7a 100644 --- a/University/UniversityDataModels/UniversityDataModels.csproj +++ b/University/UniversityDataModels/UniversityDataModels.csproj @@ -6,11 +6,4 @@ enable - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs new file mode 100644 index 0000000..9ae693c --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs @@ -0,0 +1,442 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + [Migration("20240429094924_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfEvaluation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.ToTable("Attestations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfStudy") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Profile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("PlanOfStudys"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("TeacherId"); + + b.ToTable("PlanOfStudyTeachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Storekeepers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AcademicDegree") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StorekeeperId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StorekeeperId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("Attestations") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Disciplines") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Worker", "Worker") + .WithMany("PlanOfStudys") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Teachers") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("PlanOfStudyTeachers") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Statements") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Students") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("Students") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentDiscipline") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Storekeeper", "Storekeeper") + .WithMany("Teachers") + .HasForeignKey("StorekeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Storekeeper"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => + { + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("Attestations"); + + b.Navigation("StudentDiscipline"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudyTeachers"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => + { + b.Navigation("PlanOfStudys"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs new file mode 100644 index 0000000..c55372c --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs @@ -0,0 +1,312 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Storekeepers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FirstName = table.Column(type: "nvarchar(max)", nullable: false), + LastName = table.Column(type: "nvarchar(max)", nullable: false), + MiddleName = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Storekeepers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Workers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FirstName = table.Column(type: "nvarchar(max)", nullable: false), + LastName = table.Column(type: "nvarchar(max)", nullable: false), + MiddleName = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Workers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Teachers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + StorekeeperId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + AcademicDegree = table.Column(type: "nvarchar(max)", nullable: false), + Position = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Teachers", x => x.Id); + table.ForeignKey( + name: "FK_Teachers_Storekeepers_StorekeeperId", + column: x => x.StorekeeperId, + principalTable: "Storekeepers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlanOfStudys", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + WorkerId = table.Column(type: "int", nullable: false), + Profile = table.Column(type: "nvarchar(max)", nullable: false), + FormOfStudy = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlanOfStudys", x => x.Id); + table.ForeignKey( + name: "FK_PlanOfStudys_Workers_WorkerId", + column: x => x.WorkerId, + principalTable: "Workers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Disciplines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TeacherId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Disciplines", x => x.Id); + table.ForeignKey( + name: "FK_Disciplines_Teachers_TeacherId", + column: x => x.TeacherId, + principalTable: "Teachers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Statements", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TeacherId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Date = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Statements", x => x.Id); + table.ForeignKey( + name: "FK_Statements_Teachers_TeacherId", + column: x => x.TeacherId, + principalTable: "Teachers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlanOfStudyTeachers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanOfStudyId = table.Column(type: "int", nullable: false), + TeacherId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlanOfStudyTeachers", x => x.Id); + table.ForeignKey( + name: "FK_PlanOfStudyTeachers_PlanOfStudys_PlanOfStudyId", + column: x => x.PlanOfStudyId, + principalTable: "PlanOfStudys", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PlanOfStudyTeachers_Teachers_TeacherId", + column: x => x.TeacherId, + principalTable: "Teachers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanOfStudyId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.Id); + table.ForeignKey( + name: "FK_Students_PlanOfStudys_PlanOfStudyId", + column: x => x.PlanOfStudyId, + principalTable: "PlanOfStudys", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Attestations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + StudentId = table.Column(type: "int", nullable: false), + FormOfEvaluation = table.Column(type: "nvarchar(max)", nullable: false), + Score = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Attestations", x => x.Id); + table.ForeignKey( + name: "FK_Attestations_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "StudentDisciplines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + StudentId = table.Column(type: "int", nullable: false), + DisciplineId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StudentDisciplines", x => x.Id); + table.ForeignKey( + name: "FK_StudentDisciplines_Disciplines_DisciplineId", + column: x => x.DisciplineId, + principalTable: "Disciplines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_StudentDisciplines_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Attestations_StudentId", + table: "Attestations", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_Disciplines_TeacherId", + table: "Disciplines", + column: "TeacherId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanOfStudys_WorkerId", + table: "PlanOfStudys", + column: "WorkerId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanOfStudyTeachers_PlanOfStudyId", + table: "PlanOfStudyTeachers", + column: "PlanOfStudyId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanOfStudyTeachers_TeacherId", + table: "PlanOfStudyTeachers", + column: "TeacherId"); + + migrationBuilder.CreateIndex( + name: "IX_Statements_TeacherId", + table: "Statements", + column: "TeacherId"); + + migrationBuilder.CreateIndex( + name: "IX_StudentDisciplines_DisciplineId", + table: "StudentDisciplines", + column: "DisciplineId"); + + migrationBuilder.CreateIndex( + name: "IX_StudentDisciplines_StudentId", + table: "StudentDisciplines", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_Students_PlanOfStudyId", + table: "Students", + column: "PlanOfStudyId"); + + migrationBuilder.CreateIndex( + name: "IX_Teachers_StorekeeperId", + table: "Teachers", + column: "StorekeeperId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attestations"); + + migrationBuilder.DropTable( + name: "PlanOfStudyTeachers"); + + migrationBuilder.DropTable( + name: "Statements"); + + migrationBuilder.DropTable( + name: "StudentDisciplines"); + + migrationBuilder.DropTable( + name: "Disciplines"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "Teachers"); + + migrationBuilder.DropTable( + name: "PlanOfStudys"); + + migrationBuilder.DropTable( + name: "Storekeepers"); + + migrationBuilder.DropTable( + name: "Workers"); + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs new file mode 100644 index 0000000..f4e7517 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs @@ -0,0 +1,439 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + partial class UniversityDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfEvaluation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.ToTable("Attestations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfStudy") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Profile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("PlanOfStudys"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("TeacherId"); + + b.ToTable("PlanOfStudyTeachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Storekeepers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AcademicDegree") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StorekeeperId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StorekeeperId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("Attestations") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Disciplines") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Worker", "Worker") + .WithMany("PlanOfStudys") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Teachers") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("PlanOfStudyTeachers") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Statements") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Students") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("Students") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentDiscipline") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Storekeeper", "Storekeeper") + .WithMany("Teachers") + .HasForeignKey("StorekeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Storekeeper"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => + { + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("Attestations"); + + b.Navigation("StudentDiscipline"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudyTeachers"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => + { + b.Navigation("PlanOfStudys"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 63cef12..fd1fbaf 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR - optionsBuilder.UseSqlServer(@"Data Source=(localdb)\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=(localdb)\UniversityDatabase;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj index 06b233b..de381dd 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj +++ b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj @@ -7,9 +7,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive