From 42982bcdab79fbfb05f2f5ce14224820bc4395ab Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Thu, 30 May 2024 00:22:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BA=D1=83=D1=80=D1=81=D0=BE=D0=B2=D0=B0=D1=8F=20worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniversityClientAppWorker/APIClient.cs | 18 + .../Controllers/HomeController.cs | 76 ++- .../Views/Home/Enter.cshtml | 2 +- .../Views/Home/Index.cshtml | 17 +- .../Views/Home/InfoAttestation.cshtml | 9 +- .../Views/Home/InfoPlanOfStudy.cshtml | 5 +- .../Views/Home/InfoStudent.cshtml | 39 ++ .../Views/Home/Privacy.cshtml | 2 +- .../Home/ReportPlanOfStudyAndStudents.cshtml | 2 +- .../Views/Home/Students.cshtml | 8 +- .../Views/Shared/_Layout.cshtml | 8 - .../BindingModels/StudentBindingModel.cs | 1 + .../SearchModels/PlanOfStudySearchModel.cs | 2 - .../ViewModels/StudentViewModel.cs | 2 + .../Implements/AttestationStorage.cs | 2 +- .../Implements/PlanOfStudyStorage.cs | 4 - ...240529193238_newViewForStudent.Designer.cs | 475 ++++++++++++++++++ .../20240529193238_newViewForStudent.cs | 29 ++ .../UniversityDatabaseModelSnapshot.cs | 4 + .../Models/Student.cs | 4 + .../UniversityDatabase.cs | 2 +- .../Controllers/StudentController.cs | 4 +- 22 files changed, 679 insertions(+), 36 deletions(-) create mode 100644 University/UniversityClientAppWorker/Views/Home/InfoStudent.cshtml create mode 100644 University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.Designer.cs create mode 100644 University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.cs diff --git a/University/UniversityClientAppWorker/APIClient.cs b/University/UniversityClientAppWorker/APIClient.cs index 57f9a5f..a9c839e 100644 --- a/University/UniversityClientAppWorker/APIClient.cs +++ b/University/UniversityClientAppWorker/APIClient.cs @@ -49,6 +49,24 @@ namespace PlumbingRepairClientApp } } + public static async Task GetRequestStudentsAsync(string requestUrl) + { + var response = await _client.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) + { + var settings = new JsonSerializerSettings + { + Converters = new List { new TeacherConverter() } + }; + return JsonConvert.DeserializeObject(result, settings); + } + else + { + throw new Exception(result); + } + } + public static async Task GetRequestAsync(string requestUrl) { var response = await _client.GetAsync(requestUrl); diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index f53d064..dc93915 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -1,10 +1,12 @@ using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Mvc; using PlumbingRepairClientApp; using System.Diagnostics; using UniversityClientAppWorker.Models; using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; using UniversityDataModels.Enums; using UniversityDataModels.Models; using static System.Runtime.InteropServices.JavaScript.JSType; @@ -231,7 +233,7 @@ namespace UniversityClientAppWorker.Controllers return View(APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}")); } [HttpPost] - public void CreateStudent(string name, int planOfStudy, string phoneNumber) + public async Task CreateStudent(string name, int planOfStudy, string phoneNumber) { if (APIClient.User == null) { @@ -241,15 +243,85 @@ namespace UniversityClientAppWorker.Controllers { throw new Exception(" , "); } + var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); + if(PlanOfStudy == null) + { + throw new Exception(" "); + } APIClient.PostRequest("api/student/createstudent", new StudentBindingModel { UserId = APIClient.User.Id, Name = name, PlanOfStudyId = planOfStudy, + PlanOfStudyProfile = PlanOfStudy.Profile, PhoneNumber = phoneNumber, }); - Response.Redirect("Students"); + return Redirect("/Home/Students"); + } + [HttpGet] + public async Task InfoStudent(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + if(id == 0) + { + throw new Exception("id 0"); + } + var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> + ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); + ViewBag.PlanOfStudys = planOfStudys; + var obj = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={id}"); + return View(obj); + } + [HttpPost] + public async Task UpdateStudent(int id, string name, int planOfStudy, string phoneNumber) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if(id == 0) + { + throw new Exception("id 0"); + } + if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber)) + { + throw new Exception(" , "); + } + var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); + if (PlanOfStudy == null) + { + throw new Exception(" "); + } + APIClient.PostRequest("api/student/updatestudent", new StudentBindingModel + { + Id = id, + Name = name, + PlanOfStudyId = planOfStudy, + PlanOfStudyProfile = PlanOfStudy.Profile, + PhoneNumber = phoneNumber, + }); + return Redirect("/Home/Students"); + } + [HttpPost] + public void DeleteStudent(int id) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if (id == 0) + { + throw new Exception("id 0"); + } + APIClient.PostRequest("api/student/deletestudent", new StudentBindingModel + { + Id = id + }); + Response.Redirect("Students"); } [HttpGet] public IActionResult Enter() diff --git a/University/UniversityClientAppWorker/Views/Home/Enter.cshtml b/University/UniversityClientAppWorker/Views/Home/Enter.cshtml index e37d486..37b1aee 100644 --- a/University/UniversityClientAppWorker/Views/Home/Enter.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Enter.cshtml @@ -15,6 +15,6 @@
-
+
diff --git a/University/UniversityClientAppWorker/Views/Home/Index.cshtml b/University/UniversityClientAppWorker/Views/Home/Index.cshtml index efd37c1..be6c536 100644 --- a/University/UniversityClientAppWorker/Views/Home/Index.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Index.cshtml @@ -7,9 +7,16 @@

@ViewData["Title"]

- +
+
+ +
+
+ +
+
-
+
Профиль:
@@ -49,9 +56,9 @@ Id - Profile - FormOfStudy - Actions + Профиль + Форма обучения + Действия diff --git a/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml index 43ada8d..a0ab5af 100644 --- a/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml @@ -1,10 +1,10 @@ @using UniversityContracts.ViewModels @model AttestationViewModel @{ - ViewData["Title"] = "План обучения"; + ViewData["Title"] = "Аттестация"; }
-

@ViewData["Title"]

+

@ViewData["Title"] - @Model.Id

@@ -32,8 +32,11 @@
+ + + - +
\ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml index 8eadf37..c6579f1 100644 --- a/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml @@ -4,7 +4,7 @@ ViewData["Title"] = "План обучения"; }
-

@ViewData["Title"]

+

@ViewData["Title"] - @Model.Id

@@ -33,6 +33,9 @@
+ + +
diff --git a/University/UniversityClientAppWorker/Views/Home/InfoStudent.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoStudent.cshtml new file mode 100644 index 0000000..5f60e7d --- /dev/null +++ b/University/UniversityClientAppWorker/Views/Home/InfoStudent.cshtml @@ -0,0 +1,39 @@ +@using UniversityContracts.ViewModels +@model StudentViewModel +@{ + ViewData["Title"] = "Студент"; +} + +
+

@ViewData["Title"] - @Model.Id

+
+
+
+
ФИО:
+
+ +
+
+
+
План обучения:
+
+ +
+
+
+
Номер телефона:
+
+ +
+
+
+
+
+ + + + + +
+
+ \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml b/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml index a2fc040..4316d56 100644 --- a/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml @@ -21,6 +21,6 @@
-
+
\ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml index c9225ec..305f86d 100644 --- a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndStudents.cshtml @@ -14,7 +14,7 @@
- +
diff --git a/University/UniversityClientAppWorker/Views/Home/Students.cshtml b/University/UniversityClientAppWorker/Views/Home/Students.cshtml index ec45aac..55d2104 100644 --- a/University/UniversityClientAppWorker/Views/Home/Students.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Students.cshtml @@ -24,7 +24,7 @@
Номер телефона:
- +
@@ -56,15 +56,15 @@ @Html.DisplayFor(modelItem => student.Name) - @Html.DisplayFor(modelItem => student.PlanOfStudyId) + @Html.DisplayFor(modelItem => student.PlanOfStudyProfile) @Html.DisplayFor(modelItem => student.PhoneNumber)
- Изменить -
+ Изменить +
diff --git a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml index f728a2d..a3f5281 100644 --- a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml +++ b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml @@ -37,14 +37,6 @@ - -
diff --git a/University/UniversityContracts/BindingModels/StudentBindingModel.cs b/University/UniversityContracts/BindingModels/StudentBindingModel.cs index 748c58b..ad26dd2 100644 --- a/University/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -7,6 +7,7 @@ namespace UniversityContracts.BindingModels public int Id { get; set; } public int UserId { get; set; } public int PlanOfStudyId { get; set; } + public string PlanOfStudyProfile { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; public string PhoneNumber { get; set; } = string.Empty; } diff --git a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs index 9b48f00..e3466a2 100644 --- a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs +++ b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs @@ -11,7 +11,5 @@ namespace UniversityContracts.SearchModels public int? Id { get; set; } public int UserId { get; set; } public string? Profile { get; set; } - public DateOnly? DateFrom { get; set; } - public DateOnly? DateTo { get; set; } } } diff --git a/University/UniversityContracts/ViewModels/StudentViewModel.cs b/University/UniversityContracts/ViewModels/StudentViewModel.cs index 1da47ed..b566cf1 100644 --- a/University/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/University/UniversityContracts/ViewModels/StudentViewModel.cs @@ -8,6 +8,8 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public int UserId { get; set; } public int PlanOfStudyId { get; set; } + [DisplayName("Профиль")] + public string PlanOfStudyProfile { get; set; } = string.Empty; [DisplayName("ФИО")] public string Name { get; set; } = string.Empty; [DisplayName("Номер Телефона")] diff --git a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs index 32fd224..a67b2be 100644 --- a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs @@ -32,7 +32,7 @@ namespace UniversityDatabaseImplement.Implements var query = context.Attestations .Include(x => x.Student) - .ThenInclude(s => s.User) // Загружаем данные пользователя студента + .ThenInclude(s => s.User) .Include(x => x.User) .AsQueryable(); diff --git a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs index 3285805..3fbeed8 100644 --- a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs @@ -74,10 +74,6 @@ namespace UniversityDatabaseImplement.Implements { query = query.Where(x => x.Id == model.Id.Value); } - if (model.DateFrom.HasValue && model.DateTo.HasValue) - { - query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value); - }; return query.Select(x => x.GetViewModel).ToList(); } diff --git a/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.Designer.cs b/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.Designer.cs new file mode 100644 index 0000000..d5ea922 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.Designer.cs @@ -0,0 +1,475 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + [Migration("20240529193238_newViewForStudent")] + partial class newViewForStudent + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfEvaluation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.Property("StudentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.HasIndex("UserId"); + + b.ToTable("Attestations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.HasIndex("UserId"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("FormOfStudy") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Profile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("PlanOfStudys"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("TeacherId"); + + b.ToTable("PlanOfStudyTeachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.HasIndex("UserId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("PlanOfStudyProfile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AcademicDegree") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Role") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("Attestations") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Attestations") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Disciplines") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Disciplines") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("PlanOfStudys") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Teachers") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("PlanOfStudyTeachers") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Statements") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Statements") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Students") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Students") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("Students") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentDiscipline") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Teachers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("Attestations"); + + b.Navigation("StudentDiscipline"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudyTeachers"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Navigation("Attestations"); + + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudys"); + + b.Navigation("Statements"); + + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.cs b/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.cs new file mode 100644 index 0000000..7f425ef --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240529193238_newViewForStudent.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + /// + public partial class newViewForStudent : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PlanOfStudyProfile", + table: "Students", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PlanOfStudyProfile", + table: "Students"); + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs index 579bc8c..d284877 100644 --- a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs +++ b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs @@ -191,6 +191,10 @@ namespace UniversityDatabaseImplement.Migrations b.Property("PlanOfStudyId") .HasColumnType("int"); + b.Property("PlanOfStudyProfile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b.Property("UserId") .HasColumnType("int"); diff --git a/University/UniversityDatabaseImplement/Models/Student.cs b/University/UniversityDatabaseImplement/Models/Student.cs index e52e20c..94285d0 100644 --- a/University/UniversityDatabaseImplement/Models/Student.cs +++ b/University/UniversityDatabaseImplement/Models/Student.cs @@ -19,6 +19,7 @@ namespace UniversityDatabaseImplement.Models public int UserId { get; private set; } [Required] public int PlanOfStudyId { get; private set; } + public string PlanOfStudyProfile { get; private set; } = string.Empty; [Required] public string Name { get; set; } = string.Empty; [Required] @@ -38,6 +39,7 @@ namespace UniversityDatabaseImplement.Models User = context.Users.First(x => x.Id == model.UserId), PlanOfStudyId = model.PlanOfStudyId, PlanOfStudy = context.PlanOfStudys.First(x => x.Id == model.PlanOfStudyId), + PlanOfStudyProfile = model.PlanOfStudyProfile, Name = model.Name, PhoneNumber = model.PhoneNumber }; @@ -51,11 +53,13 @@ namespace UniversityDatabaseImplement.Models PhoneNumber = model.PhoneNumber; Name = model.Name; PlanOfStudyId = model.PlanOfStudyId; + PlanOfStudyProfile = model.PlanOfStudyProfile; } public StudentViewModel GetViewModel => new() { Id = Id, PlanOfStudyId = PlanOfStudyId, + PlanOfStudyProfile = PlanOfStudyProfile, UserId = UserId, Name = Name, PhoneNumber = PhoneNumber diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 3eebb86..2b73bad 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR - optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/StudentController.cs b/University/UniversityRestApi/Controllers/StudentController.cs index 24c3e49..1786a4e 100644 --- a/University/UniversityRestApi/Controllers/StudentController.cs +++ b/University/UniversityRestApi/Controllers/StudentController.cs @@ -56,7 +56,7 @@ namespace UniversityRestApi.Controllers throw; } } - [HttpPut] + [HttpPost] public void UpdateStudent(StudentBindingModel model) { try @@ -69,7 +69,7 @@ namespace UniversityRestApi.Controllers throw; } } - [HttpDelete] + [HttpPost] public void DeleteStudent(StudentBindingModel model) { try