From d7753b4c27b0140785fade133479f82f1cd94f67 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Sun, 26 May 2024 23:51:13 +0400 Subject: [PATCH] =?UTF-8?q?C=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=83=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 37 ++++++++++++++++--- .../Views/Home/Teachers.cshtml | 37 ++++++++++--------- .../BindingModels/TeacherBindingModel.cs | 1 - .../Implements/TeacherStorage.cs | 15 +++++--- .../Controllers/StatementController.cs | 6 +++ 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/University/UniversityClientApp/Controllers/HomeController.cs b/University/UniversityClientApp/Controllers/HomeController.cs index 6343ef8..e547801 100644 --- a/University/UniversityClientApp/Controllers/HomeController.cs +++ b/University/UniversityClientApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Reflection.Metadata; using UniversityClientApp.Models; using UniversityClientAppStorekeeper; using UniversityContracts.BindingModels; @@ -81,15 +82,41 @@ namespace UniversityClientApp.Controllers public IActionResult Statements() { - return View(); + if (APIStorekeeper.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIStorekeeper.GetRequest>($"api/statement/getstatements?teacherId={0}")); } - public IActionResult Teachers() + [HttpGet] + public IActionResult Teachers() { - return View(); - } + if (APIStorekeeper.Client == null) + { + return Redirect("~/Home/Enter"); + } + //ViewBag.Documents = APIStorekeeper.GetRequest>("api/main/getdiscipline"); + return View(APIStorekeeper.GetRequest>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}")); + } + [HttpPost] + public void Teachers(string name, string position, string academicDegree) + { + if (APIStorekeeper.Client == null) + { + Redirect("~/Home/Enter"); + } + APIStorekeeper.PostRequest("api/teacher/createteacher", new TeacherBindingModel + { + UserId = APIStorekeeper.Client.Id, + Name = name, + Position = position, + AcademicDegree = academicDegree + }); + Response.Redirect("Index"); + } - public IActionResult Report() { + public IActionResult Report() { return View(); } diff --git a/University/UniversityClientApp/Views/Home/Teachers.cshtml b/University/UniversityClientApp/Views/Home/Teachers.cshtml index 3668609..3550d46 100644 --- a/University/UniversityClientApp/Views/Home/Teachers.cshtml +++ b/University/UniversityClientApp/Views/Home/Teachers.cshtml @@ -1,4 +1,6 @@ -@{ +@using UniversityContracts.ViewModels +@model List +@{ ViewData["Title"] = "Manage Teachers"; } @@ -43,35 +45,36 @@ + - - - - @* @foreach (var teacher in Model) + + @foreach (var item in Model) { - - - - + + + - } *@ + }
Id Name Academic Degree Position DisciplinesActions
@teacher.Name@teacher.AcademicDegree@teacher.Position - @foreach (var discipline in teacher.Disciplines) - { - @discipline.Name - } + @Html.DisplayFor(modelItem => item.Id) - Edit - Details - Delete + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.AcademicDegree) + + @Html.DisplayFor(modelItem => item.Position) + + + +
diff --git a/University/UniversityContracts/BindingModels/TeacherBindingModel.cs b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs index 75d6955..cad5bc4 100644 --- a/University/UniversityContracts/BindingModels/TeacherBindingModel.cs +++ b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs @@ -12,7 +12,6 @@ namespace UniversityContracts.BindingModels { public int Id { get; set; } public int UserId { get; set; } - public int StorekeeperId { get; set; } public string Name { get; set; } = string.Empty; public string AcademicDegree { get; set; } = string.Empty; public string Position { get; set; } = string.Empty; diff --git a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs index 94da27a..e5b4d81 100644 --- a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs @@ -23,18 +23,23 @@ namespace UniversityDatabaseImplement.Implements } public List GetFilteredList(TeacherSearchModel model) { - if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.AcademicDegree) || string.IsNullOrEmpty(model.Position)) - { - return new(); - } using var context = new UniversityDatabase(); - return context.Teachers + if (!string.IsNullOrEmpty(model.Name) || !string.IsNullOrEmpty(model.AcademicDegree) || !string.IsNullOrEmpty(model.Position)) + { + return context.Teachers .Where(x => x.Name.Contains(model.Name)) .Where(x => x.Position.Contains(model.Position)) .Where(x => x.AcademicDegree.Contains(model.AcademicDegree)) .Include(x => x.User) .Select(x => x.GetViewModel) .ToList(); + } + else { return context.Teachers.Include(x => x.User).Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } public TeacherViewModel? GetElement(TeacherSearchModel model) { diff --git a/University/UniversityRestApi/Controllers/StatementController.cs b/University/UniversityRestApi/Controllers/StatementController.cs index 28f0cd7..1f85990 100644 --- a/University/UniversityRestApi/Controllers/StatementController.cs +++ b/University/UniversityRestApi/Controllers/StatementController.cs @@ -25,6 +25,10 @@ namespace UniversityRestApi.Controllers { try { + if (teacherId == 0) + { + return _logic.ReadList(null); + } return _logic.ReadList(new StatementSearchModel { TeacherId = teacherId }); } catch (Exception ex) @@ -33,6 +37,8 @@ namespace UniversityRestApi.Controllers throw; } } + + [HttpPost] public void CreateStatement(StatementBindingModel model) {