diff --git a/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs b/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs index 5e028f2..eb00d6c 100644 --- a/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs @@ -69,6 +69,11 @@ namespace UniversityBusinessLogic.BusinessLogics return list; } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _documentStorage.GetNumberOfPages(userId, pageSize); + } + private void CheckModel(DocumentBindingModel model, bool withParams = true) { if (model == null) diff --git a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs index 4762fad..75c4986 100644 --- a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs @@ -61,7 +61,7 @@ namespace UniversityBusinessLogic.BusinessLogics DateFrom = model.DateFrom, DateTo = model.DateTo, }) - .Any(document => document.StudentDocument.ContainsKey(student.Value.Id)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени + .Any(document => document.DocumentStudents.Contains(student.Value)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени .Join(_documentStorage.GetFullList(), t1 => t1.Value.Id, t2 => t2.UserId, diff --git a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs index dcd0899..9ad3b15 100644 --- a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs @@ -77,7 +77,7 @@ namespace UniversityBusinessLogic.BusinessLogics DateFrom = model.DateFrom, DateTo = model.DateTo, }) - .Any(document => document.StudentDocument.ContainsKey(student.Value.Id)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени + .Any(document => document.DocumentStudents.Any(x => x.Id == student.Value.Id)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени .Select(student => ( StudentFIO: $"{student.Value.Name} {student.Value.Surname}", EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = student.Value.EducationStatusId })?.Name ?? "не удалось получить")) diff --git a/UniversityContracts/BindingModels/DocumentBindingModel.cs b/UniversityContracts/BindingModels/DocumentBindingModel.cs index edcd72c..3856cba 100644 --- a/UniversityContracts/BindingModels/DocumentBindingModel.cs +++ b/UniversityContracts/BindingModels/DocumentBindingModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityContracts.ViewModels; using UniversityModels.Models; namespace UniversityContracts.BindingModels @@ -13,6 +14,6 @@ namespace UniversityContracts.BindingModels public string Name { get; set; } = string.Empty; public DateTime Date { get; set; } = DateTime.Now; public int UserId { get; set; } - public Dictionary StudentDocument { get; set; } = new(); + public List DocumentStudents { get; set; } = new(); } } diff --git a/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs b/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs index c153311..96c7330 100644 --- a/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; namespace UniversityContracts.BusinessLogicContracts @@ -16,5 +17,6 @@ namespace UniversityContracts.BusinessLogicContracts bool Delete(DocumentBindingModel model); List? ReadList(DocumentSearchModel? model); DocumentViewModel? ReadElement(DocumentSearchModel model); + int GetNumberOfPages(int userId, int pageSize = 10); } } diff --git a/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs b/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs index 32078d2..5c5a1a5 100644 --- a/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs @@ -16,6 +16,6 @@ namespace UniversityContracts.BusinessLogicContracts bool Delete(EducationStatusBindingModel model); List? ReadList(EducationStatusSearchModel? model); EducationStatusViewModel? ReadElement(EducationStatusSearchModel model); - public int GetNumberOfPages(int userId, int pageSize = 10); + int GetNumberOfPages(int userId, int pageSize = 10); } } diff --git a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs index 706106a..974dbde 100644 --- a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs @@ -16,6 +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); + int GetNumberOfPages(int userId, int pageSize = 10); } } diff --git a/UniversityContracts/SearchModels/DocumentSearchModel.cs b/UniversityContracts/SearchModels/DocumentSearchModel.cs index 4304caa..1fc02f3 100644 --- a/UniversityContracts/SearchModels/DocumentSearchModel.cs +++ b/UniversityContracts/SearchModels/DocumentSearchModel.cs @@ -13,5 +13,7 @@ namespace UniversityContracts.SearchModels public int? UserId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? PageNumber { get; set; } + public int? PageSize { get; set; } } } diff --git a/UniversityContracts/StoragesContracts/IDocumentStorage.cs b/UniversityContracts/StoragesContracts/IDocumentStorage.cs index 86c718b..ca5917b 100644 --- a/UniversityContracts/StoragesContracts/IDocumentStorage.cs +++ b/UniversityContracts/StoragesContracts/IDocumentStorage.cs @@ -17,5 +17,6 @@ namespace UniversityContracts.StoragesContracts DocumentViewModel? Insert(DocumentBindingModel model); DocumentViewModel? Update(DocumentBindingModel model); DocumentViewModel? Delete(DocumentBindingModel model); + int GetNumberOfPages(int userId, int pageSize); } } diff --git a/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs b/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs index 14c90f6..7d1661f 100644 --- a/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs +++ b/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs @@ -17,6 +17,6 @@ namespace UniversityContracts.StoragesContracts EducationStatusViewModel? Insert(EducationStatusBindingModel model); EducationStatusViewModel? Update(EducationStatusBindingModel model); EducationStatusViewModel? Delete(EducationStatusBindingModel model); - public int GetNumberOfPages(int userId, int pageSize = 10); + int GetNumberOfPages(int userId, int pageSize = 10); } } diff --git a/UniversityContracts/StoragesContracts/IStudentStorage.cs b/UniversityContracts/StoragesContracts/IStudentStorage.cs index 81f35f2..369ff95 100644 --- a/UniversityContracts/StoragesContracts/IStudentStorage.cs +++ b/UniversityContracts/StoragesContracts/IStudentStorage.cs @@ -17,6 +17,6 @@ namespace UniversityContracts.StoragesContracts StudentViewModel? Insert(StudentBindingModel model); StudentViewModel? Update(StudentBindingModel model); StudentViewModel? Delete(StudentBindingModel model); - public int GetNumberOfPages(int userId, int pageSize); + int GetNumberOfPages(int userId, int pageSize); } } diff --git a/UniversityContracts/ViewModels/DocumentViewModel.cs b/UniversityContracts/ViewModels/DocumentViewModel.cs index b65f686..1c0c1fc 100644 --- a/UniversityContracts/ViewModels/DocumentViewModel.cs +++ b/UniversityContracts/ViewModels/DocumentViewModel.cs @@ -17,6 +17,6 @@ namespace UniversityContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Дата создания документа")] public DateTime Date { get; set; } = DateTime.Now; - public Dictionary StudentDocument { get; set; } = new(); + public List DocumentStudents { get; set; } = new(); } } diff --git a/UniversityContracts/ViewModels/StudentViewModel.cs b/UniversityContracts/ViewModels/StudentViewModel.cs index c890aef..7b5ab7c 100644 --- a/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/UniversityContracts/ViewModels/StudentViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,5 +23,18 @@ namespace UniversityContracts.ViewModels public string EducationStatusName { get; set; } = string.Empty; public int StudentCard { get; set; } public int? EducationStatusId { get; set; } + + public StudentViewModel() { } + + public StudentViewModel(IStudentModel model) + { + Id = model.Id; + UserId = model.UserId; + Name = model.Name; + Surname = model.Surname; + DateOfBirth = model.DateOfBirth; + StudentCard = model.StudentCard; + EducationStatusId = model.EducationStatusId; + } } } diff --git a/UniversityDataBaseImplemet/Database.cs b/UniversityDataBaseImplemet/Database.cs index 1986d22..3f2fa38 100644 --- a/UniversityDataBaseImplemet/Database.cs +++ b/UniversityDataBaseImplemet/Database.cs @@ -14,7 +14,34 @@ namespace UniversityDataBaseImplemet } base.OnConfiguring(optionsBuilder); } - public virtual DbSet User { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasKey(x => new { x.StudentId, x.DocumentId }); + modelBuilder.Entity() + .HasKey(x => new { x.EducationGroupId, x.DocumentId }); + modelBuilder.Entity() + .HasKey(x => new { x.EducationGroupId, x.StreamId }); + modelBuilder.Entity() + .HasKey(x => new { x.StudentId, x.StreamId }); + + modelBuilder.Entity() + .HasOne(b => b.User) + .WithMany(a => a.Documents) + .OnDelete(DeleteBehavior.NoAction); + modelBuilder.Entity() + .HasOne(b => b.User) + .WithMany(a => a.EducationStatuses) + .OnDelete(DeleteBehavior.NoAction); + modelBuilder.Entity() + .HasOne(b => b.User) + .WithMany(a => a.Students) + .OnDelete(DeleteBehavior.NoAction); + } + + + public virtual DbSet User { get; set; } public virtual DbSet Documents { get; set; } public virtual DbSet Discipline { get; set; } public virtual DbSet EducationStatuses { get; set; } diff --git a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs index a5a0379..02cc16a 100644 --- a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs @@ -86,12 +86,13 @@ namespace UniversityDataBaseImplemet.Implements } public DocumentViewModel? Insert(DocumentBindingModel model) { - var newDocument = Document.Create(model); + + using var context = new Database(); + var newDocument = Document.Create(context, model); if(newDocument == null) { return null; } - using var context = new Database(); context.Documents.Add(newDocument); context.SaveChanges(); return newDocument.GetViewModel; @@ -135,5 +136,13 @@ namespace UniversityDataBaseImplemet.Implements context.SaveChanges(); return document.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/20230518002601_nullableEdStatusId4.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230518002601_nullableEdStatusId4.Designer.cs new file mode 100644 index 0000000..6a20f8f --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518002601_nullableEdStatusId4.Designer.cs @@ -0,0 +1,497 @@ +// +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("20230518002601_nullableEdStatusId4")] + partial class nullableEdStatusId4 + { + /// + 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("EducationGroupId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "StreamId"); + + 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("StudentId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("StudentId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("StudentId", "StreamId"); + + b.HasIndex("StreamId"); + + 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("Disciplines") + .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("Documents") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("EducationGroups") + .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("EducationStatuses") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Streams") + .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("Students") + .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"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Navigation("Disciplines"); + + b.Navigation("Documents"); + + b.Navigation("EducationGroups"); + + b.Navigation("EducationStatuses"); + + b.Navigation("Streams"); + + b.Navigation("Students"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230518002601_nullableEdStatusId4.cs b/UniversityDataBaseImplemet/Migrations/20230518002601_nullableEdStatusId4.cs new file mode 100644 index 0000000..d149ece --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518002601_nullableEdStatusId4.cs @@ -0,0 +1,222 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class nullableEdStatusId4 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Documents_User_UserId", + table: "Documents"); + + migrationBuilder.DropPrimaryKey( + name: "PK_StudentStreams", + table: "StudentStreams"); + + migrationBuilder.DropIndex( + name: "IX_StudentStreams_StudentId", + table: "StudentStreams"); + + migrationBuilder.DropPrimaryKey( + name: "PK_StudentDocuments", + table: "StudentDocuments"); + + migrationBuilder.DropIndex( + name: "IX_StudentDocuments_StudentId", + table: "StudentDocuments"); + + migrationBuilder.DropPrimaryKey( + name: "PK_EducationGroupsStreams", + table: "EducationGroupsStreams"); + + migrationBuilder.DropIndex( + name: "IX_EducationGroupsStreams_EducationGroupId", + table: "EducationGroupsStreams"); + + migrationBuilder.DropPrimaryKey( + name: "PK_EducationGroupsDocuments", + table: "EducationGroupsDocuments"); + + migrationBuilder.DropIndex( + name: "IX_EducationGroupsDocuments_EducationGroupId", + table: "EducationGroupsDocuments"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "StudentStreams", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "StudentDocuments", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "EducationGroupsStreams", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "EducationGroupsDocuments", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_StudentStreams", + table: "StudentStreams", + columns: new[] { "StudentId", "StreamId" }); + + migrationBuilder.AddPrimaryKey( + name: "PK_StudentDocuments", + table: "StudentDocuments", + columns: new[] { "StudentId", "DocumentId" }); + + migrationBuilder.AddPrimaryKey( + name: "PK_EducationGroupsStreams", + table: "EducationGroupsStreams", + columns: new[] { "EducationGroupId", "StreamId" }); + + migrationBuilder.AddPrimaryKey( + name: "PK_EducationGroupsDocuments", + table: "EducationGroupsDocuments", + columns: new[] { "EducationGroupId", "DocumentId" }); + + migrationBuilder.AddForeignKey( + name: "FK_Documents_User_UserId", + table: "Documents", + column: "UserId", + principalTable: "User", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Documents_User_UserId", + table: "Documents"); + + migrationBuilder.DropPrimaryKey( + name: "PK_StudentStreams", + table: "StudentStreams"); + + migrationBuilder.DropPrimaryKey( + name: "PK_StudentDocuments", + table: "StudentDocuments"); + + migrationBuilder.DropPrimaryKey( + name: "PK_EducationGroupsStreams", + table: "EducationGroupsStreams"); + + migrationBuilder.DropPrimaryKey( + name: "PK_EducationGroupsDocuments", + table: "EducationGroupsDocuments"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "StudentStreams", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "StudentDocuments", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "EducationGroupsStreams", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "EducationGroupsDocuments", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_StudentStreams", + table: "StudentStreams", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_StudentDocuments", + table: "StudentDocuments", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_EducationGroupsStreams", + table: "EducationGroupsStreams", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_EducationGroupsDocuments", + table: "EducationGroupsDocuments", + column: "Id"); + + migrationBuilder.CreateIndex( + name: "IX_StudentStreams_StudentId", + table: "StudentStreams", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_StudentDocuments_StudentId", + table: "StudentDocuments", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_EducationGroupsStreams_EducationGroupId", + table: "EducationGroupsStreams", + column: "EducationGroupId"); + + migrationBuilder.CreateIndex( + name: "IX_EducationGroupsDocuments_EducationGroupId", + table: "EducationGroupsDocuments", + column: "EducationGroupId"); + + migrationBuilder.AddForeignKey( + name: "FK_Documents_User_UserId", + table: "Documents", + column: "UserId", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.Designer.cs new file mode 100644 index 0000000..77220e7 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.Designer.cs @@ -0,0 +1,497 @@ +// +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("20230518002727_nullableEdStatusId5")] + partial class nullableEdStatusId5 + { + /// + 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("EducationGroupId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "StreamId"); + + 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("StudentId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("StudentId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.HasKey("StudentId", "StreamId"); + + b.HasIndex("StreamId"); + + 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("Disciplines") + .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("Documents") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("EducationGroups") + .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("EducationStatuses") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Streams") + .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("Students") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .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"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Navigation("Disciplines"); + + b.Navigation("Documents"); + + b.Navigation("EducationGroups"); + + b.Navigation("EducationStatuses"); + + b.Navigation("Streams"); + + b.Navigation("Students"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.cs b/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.cs new file mode 100644 index 0000000..c1a0dd2 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518002727_nullableEdStatusId5.cs @@ -0,0 +1,64 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class nullableEdStatusId5 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_EducationStatuses_User_UserId", + table: "EducationStatuses"); + + migrationBuilder.DropForeignKey( + name: "FK_Students_User_UserId", + table: "Students"); + + migrationBuilder.AddForeignKey( + name: "FK_EducationStatuses_User_UserId", + table: "EducationStatuses", + column: "UserId", + principalTable: "User", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Students_User_UserId", + table: "Students", + column: "UserId", + principalTable: "User", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_EducationStatuses_User_UserId", + table: "EducationStatuses"); + + migrationBuilder.DropForeignKey( + name: "FK_Students_User_UserId", + table: "Students"); + + migrationBuilder.AddForeignKey( + name: "FK_EducationStatuses_User_UserId", + table: "EducationStatuses", + column: "UserId", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Students_User_UserId", + table: "Students", + column: "UserId", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs index e52e8ac..0d0cd3e 100644 --- a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs +++ b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs @@ -107,44 +107,34 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => { - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("EducationGroupId") .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("DocumentId") .HasColumnType("integer"); - b.Property("EducationGroupId") + b.Property("Id") .HasColumnType("integer"); - b.HasKey("Id"); + b.HasKey("EducationGroupId", "DocumentId"); 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.Property("Id") + .HasColumnType("integer"); - b.HasIndex("EducationGroupId"); + b.HasKey("EducationGroupId", "StreamId"); b.HasIndex("StreamId"); @@ -237,47 +227,37 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => { - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("StudentId") .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("DocumentId") .HasColumnType("integer"); - b.Property("StudentId") + b.Property("Id") .HasColumnType("integer"); - b.HasKey("Id"); + b.HasKey("StudentId", "DocumentId"); b.HasIndex("DocumentId"); - b.HasIndex("StudentId"); - b.ToTable("StudentDocuments"); }); modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => { - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("StudentId") .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("StreamId") .HasColumnType("integer"); - b.Property("StudentId") + b.Property("Id") .HasColumnType("integer"); - b.HasKey("Id"); + b.HasKey("StudentId", "StreamId"); b.HasIndex("StreamId"); - b.HasIndex("StudentId"); - b.ToTable("StudentStreams"); }); @@ -314,7 +294,7 @@ namespace UniversityDataBaseImplemet.Migrations .IsRequired(); b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("Disciplines") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -327,9 +307,9 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => { b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("Documents") .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.NoAction) .IsRequired(); b.Navigation("User"); @@ -338,7 +318,7 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => { b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("EducationGroups") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -387,9 +367,9 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => { b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("EducationStatuses") .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.NoAction) .IsRequired(); b.Navigation("User"); @@ -398,7 +378,7 @@ namespace UniversityDataBaseImplemet.Migrations modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => { b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("Streams") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -413,9 +393,9 @@ namespace UniversityDataBaseImplemet.Migrations .HasForeignKey("EducationStatusId"); b.HasOne("UniversityDataBaseImplemet.Models.User", "User") - .WithMany() + .WithMany("Students") .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.NoAction) .IsRequired(); b.Navigation("EducationStatus"); @@ -493,6 +473,21 @@ namespace UniversityDataBaseImplemet.Migrations b.Navigation("StudentStream"); }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Navigation("Disciplines"); + + b.Navigation("Documents"); + + b.Navigation("EducationGroups"); + + b.Navigation("EducationStatuses"); + + b.Navigation("Streams"); + + b.Navigation("Students"); + }); #pragma warning restore 612, 618 } } diff --git a/UniversityDataBaseImplemet/Models/Document.cs b/UniversityDataBaseImplemet/Models/Document.cs index bfeedcd..98b24c3 100644 --- a/UniversityDataBaseImplemet/Models/Document.cs +++ b/UniversityDataBaseImplemet/Models/Document.cs @@ -25,27 +25,35 @@ namespace UniversityDataBaseImplemet.Models [ForeignKey("DocumentId")] public virtual List EducationGroupDocument { get; set; } = new(); public virtual User User { get; set; } - private Dictionary? _studentDocument = null; + private List? _documentStudents = null; [NotMapped] - public Dictionary StudentDocument + public List DocumentStudents { get { - if (_studentDocument == null) + if (_documentStudents == null) { - _studentDocument = Students.ToDictionary(rec => rec.StudentId, rec => rec.Student as IStudentModel); + _documentStudents = Students.Select(x => new StudentViewModel(x.Student)).ToList(); } - return _studentDocument; + return _documentStudents; } } - public static Document? Create(DocumentBindingModel model) + public static Document? Create(Database context, DocumentBindingModel? model) { + if (model == null) + { + return null; + } return new Document() { Id = model.Id, Name = model.Name, Date = model.Date, UserId = model.UserId, + Students = model.DocumentStudents.Select(x => new StudentDocument() + { + Student = context.Students.First(y => y.Id == x.Id), + }).ToList() }; } public void Update(DocumentBindingModel model) @@ -60,42 +68,34 @@ namespace UniversityDataBaseImplemet.Models } public void UpdateStudents(Database context, DocumentBindingModel model) { - var studentDocument = context.StudentDocuments - .Where(rec => rec.DocumentId == model.Id) - .ToList(); - if (studentDocument != null) + var documentStudents = context.StudentDocuments.Where(x => x.DocumentId == model.Id).ToList(); + List currentStudents = documentStudents.Select(x => x.StudentId).ToList(); + List modelStudents = model.DocumentStudents.Select(x => x.Id).ToList(); + if (documentStudents != null && documentStudents.Count > 0) { - context.StudentDocuments - .RemoveRange(studentDocument - .Where(rec => !model.StudentDocument - .ContainsKey(rec.StudentId)) - ); + context.StudentDocuments.RemoveRange(documentStudents.Where(x => !modelStudents.Contains(x.StudentId))); + model.DocumentStudents.RemoveAll(x => currentStudents.Contains(x.Id)); context.SaveChanges(); - var document = context.Documents - .First(x => x.Id == Id); - foreach (var sd in studentDocument) - { - model.StudentDocument.Remove(sd.StudentId); - } - foreach (var sd in model.StudentDocument) - { - context.StudentDocuments.Add(new StudentDocument - { - Document = document, - Student = context.Students.First(x => x.Id == sd.Key), - }); - context.SaveChanges(); - } - _studentDocument = null; } + var document = context.Documents.First(x => x.Id == Id); + foreach (var record in model.DocumentStudents) + { + context.StudentDocuments.Add(new StudentDocument + { + Document = document, + Student = context.Students.First(x => x.Id == record.Id), + }); + context.SaveChanges(); + } + _documentStudents = null; } public DocumentViewModel GetViewModel => new() { Id = Id, Name = Name, Date = Date, - UserId = UserId, - StudentDocument = StudentDocument + UserId = UserId, + DocumentStudents = DocumentStudents }; } } diff --git a/UniversityDataBaseImplemet/Models/User.cs b/UniversityDataBaseImplemet/Models/User.cs index dff5b81..a4aaaf5 100644 --- a/UniversityDataBaseImplemet/Models/User.cs +++ b/UniversityDataBaseImplemet/Models/User.cs @@ -9,6 +9,7 @@ using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; using UniversityModels.Models; using UniversityModels.Enums; +using System.Runtime.ConstrainedExecution; namespace UniversityDataBaseImplemet.Models { @@ -21,7 +22,19 @@ namespace UniversityDataBaseImplemet.Models public string Password { get; set; } = string.Empty; [Required] public Role Role { get; set; } - public static User Create(UserBindingModel model) + [ForeignKey("UserId")] + public virtual List Students { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List Documents { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List EducationStatuses { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List Disciplines { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List EducationGroups { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List Streams { get; set; } = new(); + public static User Create(UserBindingModel model) { return new User() { diff --git a/UniversityModels/Models/IDocumentModel.cs b/UniversityModels/Models/IDocumentModel.cs index ad58bb5..408b787 100644 --- a/UniversityModels/Models/IDocumentModel.cs +++ b/UniversityModels/Models/IDocumentModel.cs @@ -11,6 +11,5 @@ namespace UniversityModels.Models string Name { get; } DateTime Date { get; } int UserId { get; } - Dictionary StudentDocument { get; } } } diff --git a/UniversityProvider/Controllers/DocumentController.cs b/UniversityProvider/Controllers/DocumentController.cs new file mode 100644 index 0000000..8ed6157 --- /dev/null +++ b/UniversityProvider/Controllers/DocumentController.cs @@ -0,0 +1,103 @@ +using Microsoft.AspNetCore.Mvc; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; + +namespace UniversityProvider.Controllers +{ + public class DocumentController : Controller + { + public IActionResult Create() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpPost] + public void Create([FromBody] DocumentBindingModel documentModel) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + documentModel.UserId = APIClient.User.Id; + APIClient.PostRequest("api/document/create", documentModel); + Response.Redirect("/Home/Documents"); + } + + public IActionResult Update(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Document = APIClient.GetRequest($"api/document/get?id={id}"); + return View(); + } + + [HttpPost] + public void Update([FromBody] DocumentBindingModel documentModel) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + documentModel.UserId = APIClient.User.Id; + APIClient.PostRequest("api/document/update", documentModel); + Response.Redirect("/Home/Documents"); + } + + public IActionResult AddDocument(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DocumentId = id; + return View(); + } + + [HttpPost] + public void AddDocument([FromBody] DocumentBindingModel documentModel) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + APIClient.PostRequest("api/document/update", documentModel); + } + + [HttpPost] + public void Delete(int id) + { + if (APIClient.User == null) + { + throw new Exception("403"); + } + APIClient.PostRequest($"api/document/delete", new DocumentBindingModel() { Id = id }); + Response.Redirect("/Home/Documents"); + } + + public List GetAllByUser() + { + if (APIClient.User == null) + { + return new(); + } + List? document = APIClient.GetRequest>($"api/document/getallbyuser?userId={APIClient.User.Id}"); + return document ?? new(); + } + + public DocumentViewModel? Get(int id) + { + if (APIClient.User == null) + { + return new(); + } + DocumentViewModel? document = APIClient.GetRequest($"api/document/get?id={id}"); + return document; + } + } +} diff --git a/UniversityProvider/Controllers/HomeController.cs b/UniversityProvider/Controllers/HomeController.cs index b0973b3..0b9a40c 100644 --- a/UniversityProvider/Controllers/HomeController.cs +++ b/UniversityProvider/Controllers/HomeController.cs @@ -98,6 +98,24 @@ namespace UniversityProvider.Controllers return View(); } + public IActionResult Documents(int page) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + if (page == 0) + { + page = 1; + } + ViewBag.Documents = APIClient.GetRequest> + ($"api/document/getmany?userId={APIClient.User.Id}&page={page}"); + ViewBag.Page = page; + ViewBag.NumberOfPages = APIClient.GetRequest + ($"api/document/getnumberofpages?userId={APIClient.User.Id}"); + return View(); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/UniversityProvider/Views/Document/Create.cshtml b/UniversityProvider/Views/Document/Create.cshtml new file mode 100644 index 0000000..2afd9f4 --- /dev/null +++ b/UniversityProvider/Views/Document/Create.cshtml @@ -0,0 +1,38 @@ +@{ + ViewData["Title"] = "Приказ"; +} + +

Создание приказа

+ +
+
+

+
+
+ +

Название:

+ + + + +
+
+ + + + + + + + + + + + +
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
+
+
+ + \ No newline at end of file diff --git a/UniversityProvider/Views/Document/Update.cshtml b/UniversityProvider/Views/Document/Update.cshtml new file mode 100644 index 0000000..e1dd794 --- /dev/null +++ b/UniversityProvider/Views/Document/Update.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} diff --git a/UniversityProvider/Views/Home/Documents.cshtml b/UniversityProvider/Views/Home/Documents.cshtml index e1dd794..10ad681 100644 --- a/UniversityProvider/Views/Home/Documents.cshtml +++ b/UniversityProvider/Views/Home/Documents.cshtml @@ -1,5 +1,71 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ +@using UniversityContracts.ViewModels + @{ + ViewData["Title"] = "Приказы"; } + +
+

Приказы

+
+ + +
+ @{ + if (ViewBag.Documents == null) + { +

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

+ return; + } + +
+
+ + / @ViewBag.NumberOfPages +
+ + Перейти + +
+ + + + + + + + + + + + @foreach (var item in ViewBag.Documents) + { + + + + + + + } + +
+ Название + + Дата + + + +
+ @item.Name + + @item.Date.ToString("yyyy-MM-dd") + + Изменить + + Удалить +
+ } +
+ + diff --git a/UniversityProvider/Views/Home/EducationStatuses.cshtml b/UniversityProvider/Views/Home/EducationStatuses.cshtml index 0ac08ea..f7de60c 100644 --- a/UniversityProvider/Views/Home/EducationStatuses.cshtml +++ b/UniversityProvider/Views/Home/EducationStatuses.cshtml @@ -17,7 +17,7 @@ return; }
diff --git a/UniversityProvider/wwwroot/css/site.css b/UniversityProvider/wwwroot/css/site.css index f27e5ad..f137c90 100644 --- a/UniversityProvider/wwwroot/css/site.css +++ b/UniversityProvider/wwwroot/css/site.css @@ -15,4 +15,14 @@ html { body { margin-bottom: 60px; -} \ No newline at end of file +} + +.scrollable-table { + max-height: 400px; + overflow-y: auto; +} + +.scrollable-table tr{ + transition: background-color 0.3s ease; +} + diff --git a/UniversityProvider/wwwroot/js/document/document-create.js b/UniversityProvider/wwwroot/js/document/document-create.js new file mode 100644 index 0000000..374f818 --- /dev/null +++ b/UniversityProvider/wwwroot/js/document/document-create.js @@ -0,0 +1,68 @@ +const createBtn = document.getElementById("create-button") +const tbody = document.getElementById("scrollable-table__tbody") +const nameInput = document.getElementById("name-input") +var students = [] +var dataArray = []; + +window.addEventListener('load', () => { + $.ajax({ + url: "/student/getallbyuser", + type: "GET", + contentType: "json" + }).done((result) => { + students = result; + students.forEach((student) => createRowForStudentsTable(student)); + }); +}) + +createBtn.addEventListener('click', () => { + var document = { + "Name": nameInput.value, + "Date": new Date(), + "DocumentStudents": dataArray, + } + $.ajax({ + url: "/document/create", + type: "POST", + contentType: "application/json", + data: JSON.stringify(document) + }).done(() => { + window.location.href = "/Home/Documents"; + }); +}) + +const createRowForStudentsTable = (student) => { + const { id, name, surname, dateOfBirth, studentCard, educationStatusName } = student; + const row = tbody.insertRow(); + row.setAttribute("data-id", id); + + const cells = [name, surname, formatDate(dateOfBirth), studentCard, educationStatusName]; + cells.forEach((value) => { + const cell = row.insertCell(); + cell.textContent = value; + }); + + row.addEventListener('click', () => addAndRemoveFromList(row)); +}; + +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; + +const addAndRemoveFromList = (row) => { + var id = parseInt(row.dataset.id); + console.log(students.find(x => x.id === id)) + var index = dataArray.indexOf(students.find(x => x.id === id)); + if (index === -1) { + dataArray.push(students.find(x => x.id === id)); + row.classList.add("bg-success"); + } else { + dataArray.splice(index, 1); + row.classList.remove("bg-success"); + } + console.log(dataArray); +} \ No newline at end of file diff --git a/UniversityProvider/wwwroot/js/document/document-update.js b/UniversityProvider/wwwroot/js/document/document-update.js new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/UniversityProvider/wwwroot/js/document/document-update.js @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/UniversityProvider/wwwroot/js/document/documents.js b/UniversityProvider/wwwroot/js/document/documents.js new file mode 100644 index 0000000..d4554b2 --- /dev/null +++ b/UniversityProvider/wwwroot/js/document/documents.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: "/document/delete", + type: "POST", + data: { Id: id } + }).done(() => { + window.location.reload(); + }); + } + }); +}); + +pageInput.addEventListener("input", () => { + const pageNumber = parseInt(pageInput.value); + goToPageBtn.href = `/Home/Documents?page=${pageNumber}`; +}); diff --git a/UniversityProvider/wwwroot/js/educationstatus/educationstatus-add-student.js b/UniversityProvider/wwwroot/js/educationstatus/educationstatus-add-student.js index c620601..3b84ce3 100644 --- a/UniversityProvider/wwwroot/js/educationstatus/educationstatus-add-student.js +++ b/UniversityProvider/wwwroot/js/educationstatus/educationstatus-add-student.js @@ -7,29 +7,32 @@ const updateBtn = document.getElementById("update-button"); var students = []; var educationStatus = null; -window.addEventListener("load", () => { - $.ajax({ - url: `/student/getallbyuserandeducationstatus?educationstatus=${educationStatusId}`, - type: "GET", - contentType: "json" - }).done((result) => { - students = result; +window.addEventListener("load", async () => { + try { + const studentsResponse = await $.ajax({ + url: `/student/getallbyuserandeducationstatus?educationstatus=${educationStatusId}`, + type: "GET", + contentType: "json" + }); + students = studentsResponse; + students.forEach((student) => { createStudentOption(student); }); - }); - $.ajax({ - url: `/educationstatus/get?id=${educationStatusId}`, - type: 'GET', - contentType: 'json' - }).done((result) => { - console.log(result); - educationStatus = result; + const educationStatusResponse = await $.ajax({ + url: `/educationstatus/get?id=${educationStatusId}`, + type: 'GET', + contentType: 'json' + }); + educationStatus = educationStatusResponse; fillEducationStatusInput(educationStatus); - }); + } catch (error) { + console.error(error); + } }); + updateBtn.addEventListener("click", () => { if (select.selectedIndex === -1) { return; @@ -62,54 +65,58 @@ const fillEducationStatusInput = (educationStatus) => { select.addEventListener("change", () => { studentTable.innerHTML = ""; - const trName = document.createElement('tr'); - const trSurname = document.createElement('tr'); - const trStudentCard = document.createElement('tr'); + + const createRow = (label, value) => { + const tr = document.createElement('tr'); + const tdLabel = document.createElement('td'); + tdLabel.innerHTML = label; + const tdValue = document.createElement('td'); + tdValue.innerHTML = value; + + tr.appendChild(tdLabel); + tr.appendChild(document.createElement('td')); + tr.appendChild(document.createElement('td')); + tr.appendChild(tdValue); + + return tr; + }; + + const student = students.find(x => x.id === parseInt(select.value)); + + const formattedDate = formatDate(student.dateOfBirth); + + const trName = createRow("Имя:", student.name); + const trSurname = createRow("Фамилия:", student.surname); + const trBirthdate = createRow("Дата рождения:", formattedDate); + const trStudentCard = createRow("Номер студ. билета:", student.studentCard); + const trEducationStatusName = document.createElement('tr'); - - var student = students.find(x => x.id === parseInt(select.value)); - - const tdNameField = document.createElement('td'); - tdNameField.innerHTML = "Имя:"; - const tdSurnameField = document.createElement('td'); - tdSurnameField.innerHTML = "Фамилия:"; - const tdStudentCardField = document.createElement('td'); - tdStudentCardField.innerHTML = "Номер студ. билета:"; const tdEducationStatusNameField = document.createElement('td'); tdEducationStatusNameField.innerHTML = "Статус обучения:"; - const tdNewEducationStatusName = document.createElement('td'); tdNewEducationStatusName.innerHTML = educationStatus.name; const tdArrowEducationStatusName = document.createElement('td'); - tdArrowEducationStatusName.innerHTML = "--->" - const tdName = document.createElement('td'); - tdName.innerHTML = student.name; - const tdSurname = document.createElement('td'); - tdSurname.innerHTML = student.surname; - const tdStudentCard = document.createElement('td'); - tdStudentCard.innerHTML = student.studentCard; - const tdEducationStatusName = document.createElement('td'); - tdEducationStatusName.innerHTML = student.educationStatusName; + tdArrowEducationStatusName.innerHTML = "-->"; + const tdEducationStatusName = createRow("", student.educationStatusName); - trName.appendChild(tdNameField); - trName.appendChild(document.createElement('td')); - trName.appendChild(document.createElement('td')); - trName.appendChild(tdName); - trSurname.appendChild(tdSurnameField); - trSurname.appendChild(document.createElement('td')); - trSurname.appendChild(document.createElement('td')); - trSurname.appendChild(tdSurname); - trStudentCard.appendChild(tdStudentCardField); - trStudentCard.appendChild(document.createElement('td')); - trStudentCard.appendChild(document.createElement('td')); - trStudentCard.appendChild(tdStudentCard); trEducationStatusName.appendChild(tdEducationStatusNameField); trEducationStatusName.appendChild(tdNewEducationStatusName); trEducationStatusName.appendChild(tdArrowEducationStatusName); trEducationStatusName.appendChild(tdEducationStatusName); - studentTable.appendChild(trName); - studentTable.appendChild(trSurname); - studentTable.appendChild(trStudentCard); - studentTable.appendChild(trEducationStatusName); -}) \ No newline at end of file + studentTable.append( + trName, + trSurname, + trBirthdate, + trStudentCard, + trEducationStatusName + ); +}); + +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; diff --git a/UniversityProvider/wwwroot/js/student/student-create.js b/UniversityProvider/wwwroot/js/student/student-create.js index 468d26b..bbcd99f 100644 --- a/UniversityProvider/wwwroot/js/student/student-create.js +++ b/UniversityProvider/wwwroot/js/student/student-create.js @@ -14,12 +14,12 @@ createBtn.addEventListener("click", () => { }); const correctData = function () { - + return true; }; const validate = function () { - + return true; }; diff --git a/UniversityRestAPI/Controllers/DocumentController.cs b/UniversityRestAPI/Controllers/DocumentController.cs index 5ae0e71..273712f 100644 --- a/UniversityRestAPI/Controllers/DocumentController.cs +++ b/UniversityRestAPI/Controllers/DocumentController.cs @@ -1,12 +1,111 @@ using Microsoft.AspNetCore.Mvc; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityRestAPI.Controllers { - public class DocumentController : Controller - { - public IActionResult Index() - { - return View(); - } - } + [Route("api/[controller]/[action]")] + [ApiController] + public class DocumentController : Controller + { + private readonly IDocumentLogic _documentLogic; + + public DocumentController(IDocumentLogic documentLogic) + { + _documentLogic = documentLogic; + } + + [HttpGet] + public DocumentViewModel? Get(int id) + { + try + { + return _documentLogic.ReadElement(new DocumentSearchModel { Id = id }); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUser(int userId) + { + try + { + return _documentLogic.ReadList(new DocumentSearchModel { UserId = userId }); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List? GetMany(int userId, int page) + { + try + { + return _documentLogic.ReadList(new DocumentSearchModel { UserId = userId, PageNumber = page, PageSize = 10 }); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public int GetNumberOfPages(int userId) + { + try + { + return _documentLogic.GetNumberOfPages(userId); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Create(DocumentBindingModel model) + { + try + { + _documentLogic.Create(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Update(DocumentBindingModel model) + { + try + { + _documentLogic.Update(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void Delete(DocumentBindingModel model) + { + try + { + _documentLogic.Delete(new() { Id = model.Id }); + } + catch (Exception ex) + { + throw; + } + } + } } diff --git a/UniversityRestAPI/Controllers/EducationStatusController.cs b/UniversityRestAPI/Controllers/EducationStatusController.cs index 18714a7..cfca77f 100644 --- a/UniversityRestAPI/Controllers/EducationStatusController.cs +++ b/UniversityRestAPI/Controllers/EducationStatusController.cs @@ -35,7 +35,7 @@ namespace UniversityRestAPI.Controllers { try { - return _educationStatusLogic.ReadList(null); + return _educationStatusLogic.ReadList(new EducationStatusSearchModel { UserId = userId }); } catch (Exception ex) {