diff --git a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs index 4d19cb0..a2b93e8 100644 --- a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs @@ -71,7 +71,12 @@ namespace UniversityBusinessLogic.BusinessLogics return list; } - private void CheckModel(StudentBindingModel model, bool withParams = true) + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _studentStorage.GetNumberOfPages(userId, pageSize); + } + + private void CheckModel(StudentBindingModel model, bool withParams = true) { if (model == null) { @@ -83,9 +88,17 @@ namespace UniversityBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.Name)) { - throw new ArgumentNullException("Нет названия документа", nameof(model.Name)); + throw new ArgumentNullException("Нет имени студента", nameof(model.Name)); } - if (model.StudentCard <= 0) + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет фамилии студента", nameof(model.Name)); + } + if (model.DateOfBirth > DateTime.UtcNow) + { + throw new ArgumentNullException("Неверно указана дата рождения студента", nameof(model.Name)); + } + if (model.StudentCard <= 0) { throw new ArgumentNullException("Неверно указан номер студенческого билета", nameof(model.Name)); } @@ -96,7 +109,7 @@ namespace UniversityBusinessLogic.BusinessLogics }); if (student != null && student.Id != model.Id) { - throw new InvalidOperationException("Приказ с таким названием уже есть"); + throw new InvalidOperationException("Студент с таким номером студенческого билета уже есть"); } } } diff --git a/UniversityContracts/BindingModels/StudentBindingModel.cs b/UniversityContracts/BindingModels/StudentBindingModel.cs index f614eb3..7438b76 100644 --- a/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -14,7 +14,7 @@ namespace UniversityContracts.BindingModels public string Surname { get; set; } = string.Empty; public DateTime DateOfBirth { get; set; } public int StudentCard { get; set; } - public int EducationStatusId { get; set; } + public int? EducationStatusId { get; set; } public int UserId { get; set; } } } diff --git a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs index 13eef37..706106a 100644 --- a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs @@ -16,5 +16,6 @@ namespace UniversityContracts.BusinessLogicContracts bool Delete(StudentBindingModel model); List? ReadList(StudentSearchModel? model); StudentViewModel? ReadElement(StudentSearchModel model); - } + public int GetNumberOfPages(int userId, int pageSize = 10); + } } diff --git a/UniversityContracts/SearchModels/StudentSearchModel.cs b/UniversityContracts/SearchModels/StudentSearchModel.cs index 8b8b539..19649b1 100644 --- a/UniversityContracts/SearchModels/StudentSearchModel.cs +++ b/UniversityContracts/SearchModels/StudentSearchModel.cs @@ -14,5 +14,8 @@ namespace UniversityContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public bool? Disciplines { get; set; } - } + + public int? PageNumber { get; set; } + public int? PageSize { get; set; } + } } diff --git a/UniversityContracts/StoragesContracts/IStudentStorage.cs b/UniversityContracts/StoragesContracts/IStudentStorage.cs index 9de8945..81f35f2 100644 --- a/UniversityContracts/StoragesContracts/IStudentStorage.cs +++ b/UniversityContracts/StoragesContracts/IStudentStorage.cs @@ -17,5 +17,6 @@ namespace UniversityContracts.StoragesContracts StudentViewModel? Insert(StudentBindingModel model); StudentViewModel? Update(StudentBindingModel model); StudentViewModel? Delete(StudentBindingModel model); - } + public int GetNumberOfPages(int userId, int pageSize); + } } diff --git a/UniversityContracts/ViewModels/StudentViewModel.cs b/UniversityContracts/ViewModels/StudentViewModel.cs index 9370b5c..c890aef 100644 --- a/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/UniversityContracts/ViewModels/StudentViewModel.cs @@ -21,6 +21,6 @@ namespace UniversityContracts.ViewModels [DisplayName("Статус обучения")] public string EducationStatusName { get; set; } = string.Empty; public int StudentCard { get; set; } - public int EducationStatusId { get; set; } + public int? EducationStatusId { get; set; } } } diff --git a/UniversityDataBaseImplemet/Implements/StudentStorage.cs b/UniversityDataBaseImplemet/Implements/StudentStorage.cs index 5654655..d515b19 100644 --- a/UniversityDataBaseImplemet/Implements/StudentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StudentStorage.cs @@ -18,22 +18,38 @@ namespace UniversityDataBaseImplemet.Implements { public StudentViewModel? GetElement(StudentSearchModel model) { - if (!model.Id.HasValue && model.StudentCard <= 0) + using var context = new Database(); + if (model.Id.HasValue) { - return null; - } - using var context = new Database(); - return context.Students - .Include(record => record.User) - .Include(record => record.EducationStatus) - .FirstOrDefault(record => record.Id.Equals(model.Id) - || record.StudentCard.Equals(model.StudentCard)) - ?.GetViewModel; + return context.Students + .Include(record => record.User) + .Include(record => record.EducationStatus) + .FirstOrDefault(record => record.Id.Equals(model.Id)) + ?.GetViewModel; + } + else if (model.StudentCard.HasValue) + { + return context.Students + .Include(record => record.User) + .Include(record => record.EducationStatus) + .FirstOrDefault(record => record.StudentCard.Equals(model.StudentCard)) + ?.GetViewModel; + } + return null; } public List GetFilteredList(StudentSearchModel model) { using var context = new Database(); - if (model.Id.HasValue) + if (model.UserId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue) + { + return context.Students + .Where(x => x.UserId == model.UserId) + .Skip(model.PageSize.Value * (model.PageNumber.Value - 1)) + .Take(model.PageSize.Value) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Id.HasValue) { return context.Students .Include(record => record.User) @@ -117,5 +133,13 @@ namespace UniversityDataBaseImplemet.Implements context.SaveChanges(); return student.GetViewModel; } - } + + public int GetNumberOfPages(int userId, int pageSize) + { + using var context = new Database(); + int carsCount = context.Students.Where(c => c.UserId == userId).Count(); + int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize); + return numberOfpages != 0 ? numberOfpages : 1; + } + } } diff --git a/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.Designer.cs new file mode 100644 index 0000000..0f02645 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.Designer.cs @@ -0,0 +1,504 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDataBaseImplemet; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20230517093341_nullableEdStatusId")] + partial class nullableEdStatusId + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("MarkType") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("UserId"); + + b.ToTable("Discipline"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NumberOfStudent") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationGroups"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("EducationGroupId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationGroupId"); + + b.HasIndex("StreamId"); + + b.ToTable("EducationGroupsStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationStatuses"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Course") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Streams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateOfBirth") + .HasColumnType("timestamp with time zone"); + + b.Property("EducationStatusId") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StudentCard") + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationStatusId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany() + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("EducationGroupDocument") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupDocument") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("EducationGroup"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupStream") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("EducationGroupStream") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationGroup"); + + b.Navigation("Stream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationStatus", "EducationStatus") + .WithMany("Students") + .HasForeignKey("EducationStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("Students") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("DocumentStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("StreamStudents") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("StudentStream") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("EducationGroupStream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Navigation("EducationGroupStream"); + + b.Navigation("StreamStudents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Navigation("DocumentStudents"); + + b.Navigation("StudentStream"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.cs b/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.cs new file mode 100644 index 0000000..df3deff --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517093341_nullableEdStatusId.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class nullableEdStatusId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.Designer.cs new file mode 100644 index 0000000..0efbc8b --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.Designer.cs @@ -0,0 +1,505 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDataBaseImplemet; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20230517094848_nullableEdStatusId2")] + partial class nullableEdStatusId2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("MarkType") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("UserId"); + + b.ToTable("Discipline"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NumberOfStudent") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationGroups"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("EducationGroupId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationGroupId"); + + b.HasIndex("StreamId"); + + b.ToTable("EducationGroupsStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationStatuses"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Course") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Streams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateOfBirth") + .HasColumnType("timestamp with time zone"); + + b.Property("EducationStatusId") + .IsRequired() + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StudentCard") + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationStatusId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany() + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("EducationGroupDocument") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupDocument") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("EducationGroup"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupStream") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("EducationGroupStream") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationGroup"); + + b.Navigation("Stream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationStatus", "EducationStatus") + .WithMany("Students") + .HasForeignKey("EducationStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("Students") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("DocumentStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("StreamStudents") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("StudentStream") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("EducationGroupStream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Navigation("EducationGroupStream"); + + b.Navigation("StreamStudents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Navigation("DocumentStudents"); + + b.Navigation("StudentStream"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.cs b/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.cs new file mode 100644 index 0000000..cab117c --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517094848_nullableEdStatusId2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class nullableEdStatusId2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.Designer.cs new file mode 100644 index 0000000..c293972 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.Designer.cs @@ -0,0 +1,502 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDataBaseImplemet; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20230517095031_nullableEdStatusId3")] + partial class nullableEdStatusId3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("MarkType") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("UserId"); + + b.ToTable("Discipline"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NumberOfStudent") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationGroups"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("EducationGroupId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationGroupId"); + + b.HasIndex("StreamId"); + + b.ToTable("EducationGroupsStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationStatuses"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Course") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Streams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateOfBirth") + .HasColumnType("timestamp with time zone"); + + b.Property("EducationStatusId") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StudentCard") + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationStatusId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany() + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("EducationGroupDocument") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupDocument") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("EducationGroup"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupStream") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("EducationGroupStream") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationGroup"); + + b.Navigation("Stream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationStatus", "EducationStatus") + .WithMany("Students") + .HasForeignKey("EducationStatusId"); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("Students") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("DocumentStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("StreamStudents") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("StudentStream") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("EducationGroupStream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Navigation("EducationGroupStream"); + + b.Navigation("StreamStudents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Navigation("DocumentStudents"); + + b.Navigation("StudentStream"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.cs b/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.cs new file mode 100644 index 0000000..bbd95b9 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230517095031_nullableEdStatusId3.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class nullableEdStatusId3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Students_EducationStatuses_EducationStatusId", + table: "Students"); + + migrationBuilder.AlterColumn( + name: "EducationStatusId", + table: "Students", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AddForeignKey( + name: "FK_Students_EducationStatuses_EducationStatusId", + table: "Students", + column: "EducationStatusId", + principalTable: "EducationStatuses", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Students_EducationStatuses_EducationStatusId", + table: "Students"); + + migrationBuilder.AlterColumn( + name: "EducationStatusId", + table: "Students", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Students_EducationStatuses_EducationStatusId", + table: "Students", + column: "EducationStatusId", + principalTable: "EducationStatuses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs index c6f0e55..e52e8ac 100644 --- a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs +++ b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs @@ -209,7 +209,7 @@ namespace UniversityDataBaseImplemet.Migrations b.Property("DateOfBirth") .HasColumnType("timestamp with time zone"); - b.Property("EducationStatusId") + b.Property("EducationStatusId") .HasColumnType("integer"); b.Property("Name") @@ -410,9 +410,7 @@ namespace UniversityDataBaseImplemet.Migrations { b.HasOne("UniversityDataBaseImplemet.Models.EducationStatus", "EducationStatus") .WithMany("Students") - .HasForeignKey("EducationStatusId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("EducationStatusId"); b.HasOne("UniversityDataBaseImplemet.Models.User", "User") .WithMany() diff --git a/UniversityDataBaseImplemet/Models/Student.cs b/UniversityDataBaseImplemet/Models/Student.cs index f064152..9d46149 100644 --- a/UniversityDataBaseImplemet/Models/Student.cs +++ b/UniversityDataBaseImplemet/Models/Student.cs @@ -22,15 +22,15 @@ namespace UniversityDataBaseImplemet.Models public DateTime DateOfBirth { get; set; } [Required] public int StudentCard { get; set; } - [Required] - public int EducationStatusId { get; set; } + + public int? EducationStatusId { get; set; } [Required] public int UserId { get; set; } [ForeignKey("StudentId")] public virtual List DocumentStudents { get; set; } = new(); [ForeignKey("StudentId")] public virtual List StudentStream { get; set; } = new(); - public virtual EducationStatus EducationStatus { get; set; } + public virtual EducationStatus? EducationStatus { get; set; } public virtual User User { get; set; } public static Student Create(StudentBindingModel model) @@ -48,6 +48,9 @@ namespace UniversityDataBaseImplemet.Models } public void Update(StudentBindingModel model) { + Name = model.Name; + Surname = model.Surname; + DateOfBirth = model.DateOfBirth; StudentCard = model.StudentCard; EducationStatusId = model.EducationStatusId; } @@ -60,7 +63,7 @@ namespace UniversityDataBaseImplemet.Models StudentCard = StudentCard, EducationStatusId = EducationStatusId, UserId = UserId, - EducationStatusName = EducationStatus.Name + EducationStatusName = EducationStatus?.Name ?? "Не указан" }; } } diff --git a/UniversityModels/Models/IStudentModel.cs b/UniversityModels/Models/IStudentModel.cs index 01bbb55..52242e3 100644 --- a/UniversityModels/Models/IStudentModel.cs +++ b/UniversityModels/Models/IStudentModel.cs @@ -12,7 +12,7 @@ namespace UniversityModels.Models string Surname { get; } DateTime DateOfBirth { get; } int StudentCard { get; } - int EducationStatusId { get; } + int? EducationStatusId { get; } int UserId { get; } } } diff --git a/UniversityProvider/Controllers/HomeController.cs b/UniversityProvider/Controllers/HomeController.cs index bc9c706..9407dfd 100644 --- a/UniversityProvider/Controllers/HomeController.cs +++ b/UniversityProvider/Controllers/HomeController.cs @@ -62,7 +62,25 @@ namespace UniversityProvider.Controllers return; } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Students(int page) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + if (page == 0) + { + page = 1; + } + ViewBag.Students = APIClient.GetRequest> + ($"api/student/getmany?userId={APIClient.User.Id}&page={page}"); + ViewBag.Page = page; + ViewBag.NumberOfPages = APIClient.GetRequest + ($"api/student/getnumberofpages?userId={APIClient.User.Id}"); + return View(); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/UniversityProvider/Controllers/StudentController.cs b/UniversityProvider/Controllers/StudentController.cs new file mode 100644 index 0000000..d939b9b --- /dev/null +++ b/UniversityProvider/Controllers/StudentController.cs @@ -0,0 +1,85 @@ +using Microsoft.AspNetCore.Mvc; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; + +namespace UniversityProvider.Controllers +{ + public class StudentController : Controller + { + public IActionResult Create() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpPost] + public void Create([FromBody] StudentBindingModel studentModel) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + studentModel.UserId = APIClient.User.Id; + studentModel.EducationStatusId = null; + APIClient.PostRequest("api/student/create", studentModel); + Response.Redirect("/Home/Students"); + } + + public IActionResult Update(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Student = APIClient.GetRequest($"api/student/get?id={id}"); + return View(); + } + + [HttpPost] + public void Update([FromBody] StudentBindingModel studentModel) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + studentModel.UserId = APIClient.User.Id; + APIClient.PostRequest("api/student/update", studentModel); + Response.Redirect("/Home/Students"); + } + + [HttpPost] + public void Delete(int id) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + APIClient.PostRequest($"api/student/delete", new StudentBindingModel() { Id = id }); + Response.Redirect("/Home/Students"); + } + + public List GetAllByUser() + { + if (APIClient.User == null) + { + return new(); + } + List? students = APIClient.GetRequest>($"api/student/getallbyuser?userId={APIClient.User.Id}"); + return students ?? new(); + } + + + public StudentViewModel? Get(int id) + { + if (APIClient.User == null) + { + return new(); + } + StudentViewModel? student = APIClient.GetRequest($"api/student/get?id={id}"); + return student; + } + } +} diff --git a/UniversityProvider/Views/Home/Students.cshtml b/UniversityProvider/Views/Home/Students.cshtml index 8996d8e..8c99dc6 100644 --- a/UniversityProvider/Views/Home/Students.cshtml +++ b/UniversityProvider/Views/Home/Students.cshtml @@ -1,5 +1,4 @@ @using UniversityContracts.ViewModels -@model List @{ ViewData["Title"] = "Студенты"; @@ -12,17 +11,23 @@
@{ - if (Model == null) + if (ViewBag.Students == null) {

Войдите в аккаунт

return; } +
+
+ + / @ViewBag.NumberOfPages +
+ + Перейти + +
@@ -38,27 +43,41 @@ + + - @foreach (var item in Model) + @foreach (var item in ViewBag.Students) { - + + + }
Статус обучения + Изменить запись + + Удалить запись +
- @Html.DisplayFor(modelItem => item.Name + ' ' + item.Surname) + @item.Name @item.Surname - @Html.DisplayFor(modelItem => item.DateOfBirth) + @item.DateOfBirth.ToString("yyyy-MM-dd") - @Html.DisplayFor(modelItem => item.StudentCard) + @item.StudentCard - @Html.DisplayFor(modelItem => item.EducationStatusId) + @item.EducationStatusName + + Изменить + + Удалить
} -
\ No newline at end of file + + + diff --git a/UniversityProvider/Views/Shared/_Layout.cshtml b/UniversityProvider/Views/Shared/_Layout.cshtml index 681977a..5445c77 100644 --- a/UniversityProvider/Views/Shared/_Layout.cshtml +++ b/UniversityProvider/Views/Shared/_Layout.cshtml @@ -44,12 +44,6 @@ @RenderBody() - -
-
- © 2023 - UniversityProvider - Privacy -
-
diff --git a/UniversityProvider/Views/Student/Create.cshtml b/UniversityProvider/Views/Student/Create.cshtml new file mode 100644 index 0000000..ed303a1 --- /dev/null +++ b/UniversityProvider/Views/Student/Create.cshtml @@ -0,0 +1,26 @@ +@{ + ViewData["Title"] = "Студент"; +} + +

Добавление студента

+ +
+
+

+
+
+ +

Имя:

+ +

Фамилия:

+ +

Дата рождения:

+ +

Номер студенческого билета:

+ + + + + \ No newline at end of file diff --git a/UniversityProvider/Views/Student/Update.cshtml b/UniversityProvider/Views/Student/Update.cshtml new file mode 100644 index 0000000..0d71e66 --- /dev/null +++ b/UniversityProvider/Views/Student/Update.cshtml @@ -0,0 +1,36 @@ +@using UniversityContracts.ViewModels + +@{ + ViewData["Title"] = "Студент"; +} + +@{ + +

Изменение данных студента

+ + if (ViewBag.Student == null) + { +

Войдите в аккаунт

+ return; + } +
+
+

+
+
+ +

Имя:

+ +

Фамилия:

+ +

Дата рождения:

+ +

Номер студенческого билета:

+ + + +} + + \ No newline at end of file diff --git a/UniversityProvider/wwwroot/js/student/student-create.js b/UniversityProvider/wwwroot/js/student/student-create.js new file mode 100644 index 0000000..e394f13 --- /dev/null +++ b/UniversityProvider/wwwroot/js/student/student-create.js @@ -0,0 +1,42 @@ +const createBtn = document.getElementById("create-button"); +const nameInput = document.getElementById("name-input") +const surnameInput = document.getElementById("surname-input") +const dateInput = document.getElementById("date-input") +const studCardInput = document.getElementById("studcard-input") + +createBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } +}); + +const correctData = function () { + + return true; +}; + +const validate = function () { + + return true; +}; + +createBtn.addEventListener("click", () => { + let student = { + "Name": nameInput.value, + "Surname": surnameInput.value, + "DateOfBirth": new Date(dateInput.value), + "StudentCard": parseInt(studCardInput.value), + }; + console.log(student) + $.ajax({ + url: `/student/create`, + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(student) + }).done(() => { + window.location.href = "/Home/Students"; + }); +}); \ No newline at end of file diff --git a/UniversityProvider/wwwroot/js/student/student-update.js b/UniversityProvider/wwwroot/js/student/student-update.js new file mode 100644 index 0000000..b586bcc --- /dev/null +++ b/UniversityProvider/wwwroot/js/student/student-update.js @@ -0,0 +1,45 @@ +const updateBtn = document.getElementById("update-button"); +const nameInput = document.getElementById("name-input") +const surnameInput = document.getElementById("surname-input") +const dateInput = document.getElementById("date-input") +const studCardInput = document.getElementById("studcard-input") +const studId = document.getElementById("vb-id").dataset.id + +updateBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } + form.submit(); +}); + +const correctData = function () { + + return true; +}; + +const validate = function () { + + return true; +}; + +updateBtn.addEventListener("click", () => { + let student = { + "Id": parseInt(studId), + "Name": nameInput.value, + "Surname": surnameInput.value, + "DateOfBirth": new Date(dateInput.value), + "StudentCard": parseInt(studCardInput.value), + }; + console.log(student) + $.ajax({ + url: `/student/update`, + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(student) + }).done(() => { + window.location.href = "/Home/Students"; + }); +}); \ No newline at end of file diff --git a/UniversityProvider/wwwroot/js/student/students.js b/UniversityProvider/wwwroot/js/student/students.js new file mode 100644 index 0000000..b7bbb64 --- /dev/null +++ b/UniversityProvider/wwwroot/js/student/students.js @@ -0,0 +1,25 @@ +const goToPageBtn = document.getElementById("go-button"); +const pageInput = document.getElementById("page-input"); +const removeButtons = document.querySelectorAll('.remove-btn'); + +removeButtons.forEach(function (button) { + button.addEventListener('click', function (event) { + var id = this.dataset.id; + + var result = confirm("Вы уверены, что хотите удалить эту запись?"); + if (result) { + $.ajax({ + url: `/student/delete`, + type: 'POST', + data: { Id: id } + }).done(() => { + window.location.reload(); + }); + } + }); +}); + +pageInput.addEventListener("input", () => { + const pageNumber = parseInt(pageInput.value); + goToPageBtn.href = `/Home/Students?page=${pageNumber}`; +}); diff --git a/UniversityRestAPI/Controllers/DocumentController.cs b/UniversityRestAPI/Controllers/DocumentController.cs new file mode 100644 index 0000000..5ae0e71 --- /dev/null +++ b/UniversityRestAPI/Controllers/DocumentController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace UniversityRestAPI.Controllers +{ + public class DocumentController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} diff --git a/UniversityRestAPI/Controllers/EducationStatusController.cs b/UniversityRestAPI/Controllers/EducationStatusController.cs new file mode 100644 index 0000000..1bfbcf2 --- /dev/null +++ b/UniversityRestAPI/Controllers/EducationStatusController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace UniversityRestAPI.Controllers +{ + public class EducationStatusController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} diff --git a/UniversityRestAPI/Controllers/StudentController.cs b/UniversityRestAPI/Controllers/StudentController.cs new file mode 100644 index 0000000..b8a6ac0 --- /dev/null +++ b/UniversityRestAPI/Controllers/StudentController.cs @@ -0,0 +1,111 @@ +using Microsoft.AspNetCore.Mvc; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityRestAPI.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class StudentController : Controller + { + private readonly IStudentLogic _studentLogic; + + public StudentController(IStudentLogic studentLogic) + { + _studentLogic = studentLogic; + } + + [HttpGet] + public StudentViewModel? Get(int id) + { + try + { + return _studentLogic.ReadElement(new StudentSearchModel { Id = id }); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUser(int userId) + { + try + { + return _studentLogic.ReadList(null); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List? GetMany(int userId, int page) + { + try + { + return _studentLogic.ReadList(new StudentSearchModel { UserId = userId, PageNumber = page, PageSize = 10 }); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public int GetNumberOfPages(int userId) + { + try + { + return _studentLogic.GetNumberOfPages(userId); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Create(StudentBindingModel model) + { + try + { + _studentLogic.Create(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Update(StudentBindingModel model) + { + try + { + _studentLogic.Update(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Delete(StudentBindingModel model) + { + try + { + _studentLogic.Delete(new() { Id = model.Id }); + } + catch (Exception ex) + { + throw; + } + } + } +} diff --git a/UniversityRestAPI/Program.cs b/UniversityRestAPI/Program.cs index bb3555b..da817c9 100644 --- a/UniversityRestAPI/Program.cs +++ b/UniversityRestAPI/Program.cs @@ -8,8 +8,14 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers();