From 74537d905a78403d942682125443b8c9642cea0a Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 28 May 2024 17:05:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BD=D0=BE=D0=B3=D0=B8=D0=B5-=D0=BA?= =?UTF-8?q?=D0=BE-=D0=BC=D0=BD=D0=BE=D0=B3=D0=B8=D0=BC=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 61 ++++++++++++++++++- .../Views/Home/Disciplines.cshtml | 20 ++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/University/UniversityClientApp/Controllers/HomeController.cs b/University/UniversityClientApp/Controllers/HomeController.cs index 175feaf..017c641 100644 --- a/University/UniversityClientApp/Controllers/HomeController.cs +++ b/University/UniversityClientApp/Controllers/HomeController.cs @@ -5,7 +5,10 @@ using UniversityClientApp.Models; using UniversityClientAppStorekeeper; using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; +using UniversityDatabaseImplement; using UniversityDataModels.Enums; +using UniversityDataModels.Models; namespace UniversityClientApp.Controllers { @@ -83,25 +86,77 @@ namespace UniversityClientApp.Controllers return Redirect("~/Home/Enter"); } ViewBag.Teachers = APIStorekeeper.GetRequest>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}"); + ViewBag.Students = APIStorekeeper.GetRequest>($"api/student/getstudents?userId={APIStorekeeper.Client.Id}"); return View(APIStorekeeper.GetRequest>($"api/discipline/getdisciplines?teacherId={0}")); } [HttpPost] - public void Disciplines(string name, string description, DateOnly date, int teacher) + public void Disciplines(string name, string description, DateOnly date, int teacher, List studentIds) { if (APIStorekeeper.Client == null) { Redirect("~/Home/Enter"); } - APIStorekeeper.PostRequest("api/discipline/creatediscipline", new DisciplineBindingModel + + var disciplineModel = new DisciplineBindingModel { UserId = APIStorekeeper.Client.Id, Name = name, Description = description, Date = date, TeacherId = teacher, - }); + StudentDisciplines = studentIds.ToDictionary(id => id, id => (IStudentModel)null) + // не правильно + }; + + APIStorekeeper.PostRequest("api/discipline/creatediscipline", disciplineModel); + Response.Redirect("Disciplines"); } + /*public IActionResult Disciplines(string name, string description, DateOnly date, int teacher, List studentIds) + { + if (APIStorekeeper.Client == null) + { + return RedirectToAction("Enter", "Home"); + } + + // Предполагаем, что у вас есть доступ к контексту базы данных UniversityDatabase + using (var context = new UniversityDatabase()) + { + // Создаем словарь для хранения студентов + var studentDisciplines = new Dictionary(); + + // Итерируем по списку идентификаторов студентов + foreach (var studentId in studentIds) + { + // Получаем студента из базы данных или создаем новый экземпляр Student + // Вам нужно будет заполнить необходимые свойства, такие как UserId, PlanOfStudyId, Name и PhoneNumber + var student = context.Students.Find(studentId); + + // Добавляем студента в словарь + studentDisciplines.Add(studentId, student); + } + + var disciplineModel = new DisciplineBindingModel + { + UserId = APIStorekeeper.Client.Id, + Name = name, + Description = description, + Date = date, + TeacherId = teacher, + StudentDisciplines = studentDisciplines + }; + + APIStorekeeper.PostRequest("api/discipline/creatediscipline", disciplineModel); + + return RedirectToAction("Disciplines"); + } + }*/ + + + + + + [HttpGet] public IActionResult Statements() diff --git a/University/UniversityClientApp/Views/Home/Disciplines.cshtml b/University/UniversityClientApp/Views/Home/Disciplines.cshtml index b0d549e..a5ab93b 100644 --- a/University/UniversityClientApp/Views/Home/Disciplines.cshtml +++ b/University/UniversityClientApp/Views/Home/Disciplines.cshtml @@ -1,5 +1,8 @@ п»ї@using UniversityContracts.ViewModels @model List +@{ + List students = ViewBag.Students; +} @{ ViewData["Title"] = "Manage Disciplines"; } @@ -36,6 +39,23 @@ + +
+
Students:
+
+ @foreach (var student in students) + { +
+ + +
+ } +
+
+ +