From 96a5f2c7085f3e67660b50d2aa749ec7e04e85aa Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Tue, 28 May 2024 00:44:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B0=D1=82=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/AttestationLogic.cs | 47 ------------ .../Controllers/HomeController.cs | 27 ++++++- .../Views/Home/Attestations.cshtml | 75 +++++++++++-------- .../BindingModels/AttestationBindingModel.cs | 1 + .../IAttestationLogic.cs | 6 -- .../ViewModels/AttestationViewModel.cs | 2 + .../Implements/AttestationStorage.cs | 25 +++---- .../Models/Attestation.cs | 4 + .../Controllers/AttestationController.cs | 6 +- 9 files changed, 88 insertions(+), 105 deletions(-) diff --git a/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs index 6e4559f..12339c0 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs @@ -58,8 +58,6 @@ namespace UniversityBusinessLogic.BusinessLogics { CheckModel(model); - model.Score = AttestationScore.Неявка; - if (_attestationStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -89,51 +87,6 @@ namespace UniversityBusinessLogic.BusinessLogics } return true; } - public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore) - { - CheckModel(model); - - if (!Enum.IsDefined(typeof(AttestationScore), newScore)) - { - _logger.LogWarning("Score update to " + newScore.ToString() + " operation failed. Attestation status incorrect."); - return false; - } - - if (_attestationStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - - model.Score = newScore; - return true; - } - public bool SetPass(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Зачёт); - } - - public bool SetNotPass(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Незачёт); - } - - public bool SetTwo(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Неудовлетворительно); - } - public bool SetThree(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Удовлетворительно); - } - public bool SetFour(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Хорошо); - } - public bool SetFive(AttestationBindingModel model) - { - return ScoreUpdate(model, AttestationScore.Отлично); - } private void CheckModel(AttestationBindingModel model, bool withParams = true) { diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index fbacfda..8ecab70 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -110,10 +110,31 @@ namespace UniversityClientAppWorker.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - return View(); + ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); + ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); + return View(APIClient.GetRequest>($"api/attestation/getattestations?userId={APIClient.User.Id}")); } - [HttpGet] + [HttpPost] + public void CreateAttestation(string formOfEvaluation, int student, AttestationScore score) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) + { + throw new Exception(" "); + } + APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel + { + UserId = APIClient.User.Id, + FormOfEvaluation = formOfEvaluation, + StudentId = student, + Score = score + }); + Response.Redirect("Attestations"); + } + [HttpGet] public IActionResult Students() { if (APIClient.User == null) diff --git a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml index 248d778..0795e61 100644 --- a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml @@ -1,34 +1,40 @@ -@{ - ViewData["Title"] = "Manage Attestations"; +@using UniversityContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Управление аттестациями"; }

@ViewData["Title"]

-
+
-
Form Of Evaluation:
+
Форма оценивания:
- +
-
Student:
+
Студент:
- +
-
Score:
+
Оценка:
-
- +
+
@@ -36,31 +42,40 @@ - - - - + + + + + - @* @foreach (var discipline in Model) + @foreach (var attestation in Model) { - - - - + + + + + + } - - - - } *@
Form Of EvaluationStudentScoreActionsIdФорма оцениванияСтудентОценкаДействия
@discipline.Name@discipline.Description - @foreach (var student in discipline.Students) - { - @student.Name +
+ @Html.DisplayFor(modelItem => attestation.Id) + + @Html.DisplayFor(modelItem => attestation.FormOfEvaluation) + + @Html.DisplayFor(modelItem => attestation.StudentName) + + @Html.DisplayFor(modelItem => attestation.Score) + +
+ Изменить +
+ + +
+
+
- Edit - Details - Delete -
diff --git a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs index 8a23be6..037024b 100644 --- a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs +++ b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs @@ -15,5 +15,6 @@ namespace UniversityContracts.BindingModels public string FormOfEvaluation { get; set; } = string.Empty; public AttestationScore Score { get; set; } = AttestationScore.Неявка; public int StudentId { get; set; } + public string StudentName { get; set; } = string.Empty; } } diff --git a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs index 92d2502..7df94d5 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs @@ -15,12 +15,6 @@ namespace UniversityContracts.BusinessLogicsContracts bool CreateAttestation(AttestationBindingModel model); bool DeleteAttestation(AttestationBindingModel model); bool UpdateAttestation(AttestationBindingModel model); - bool SetPass(AttestationBindingModel model); - bool SetNotPass(AttestationBindingModel model); - bool SetTwo(AttestationBindingModel model); - bool SetThree(AttestationBindingModel model); - bool SetFour(AttestationBindingModel model); - bool SetFive(AttestationBindingModel model); } } diff --git a/University/UniversityContracts/ViewModels/AttestationViewModel.cs b/University/UniversityContracts/ViewModels/AttestationViewModel.cs index 23073ac..470610c 100644 --- a/University/UniversityContracts/ViewModels/AttestationViewModel.cs +++ b/University/UniversityContracts/ViewModels/AttestationViewModel.cs @@ -14,6 +14,8 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public int UserId { get; set; } public int StudentId { get; set; } + [DisplayName("ФИО студента")] + public string StudentName { get; set; } = string.Empty; [DisplayName("Форма оценивания")] public string FormOfEvaluation { get; set; } = string.Empty; [DisplayName("Оценка")] diff --git a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs index ca70a69..d3efe1e 100644 --- a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs @@ -23,25 +23,18 @@ namespace UniversityDatabaseImplement.Implements public List GetFilteredList(AttestationSearchModel model) { - using var context = new UniversityDatabase(); - if (model.Id.HasValue) + if (model == null) { - return context.Attestations - .Include(x => x.Student) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.StudentId.HasValue) - { - return context.Attestations - .Include(x => x.Student) - .Where(x => x.StudentId == model.StudentId) - .Select(x => x.GetViewModel) - .ToList(); + return new(); } - return new(); + using var context = new UniversityDatabase(); + + return context.Attestations + .Include(x => x.Student) + .Include(x => x.User) + .Select(x => x.GetViewModel) + .ToList(); } public AttestationViewModel? GetElement(AttestationSearchModel model) diff --git a/University/UniversityDatabaseImplement/Models/Attestation.cs b/University/UniversityDatabaseImplement/Models/Attestation.cs index 36c3a46..bcd1710 100644 --- a/University/UniversityDatabaseImplement/Models/Attestation.cs +++ b/University/UniversityDatabaseImplement/Models/Attestation.cs @@ -18,6 +18,7 @@ namespace UniversityDatabaseImplement.Models public int UserId { get; private set; } [Required] public int StudentId { get; private set; } + public string StudentName { get; private set; } = string.Empty; [Required] public string FormOfEvaluation { get; private set; } = string.Empty; [Required] @@ -37,6 +38,7 @@ namespace UniversityDatabaseImplement.Models User = context.Users.First(x => x.Id == model.UserId), StudentId = model.StudentId, Student = context.Students.First(x => x.Id == model.StudentId), + StudentName = model.StudentName, FormOfEvaluation = model.FormOfEvaluation, Score = model.Score }; @@ -48,6 +50,7 @@ namespace UniversityDatabaseImplement.Models return; } StudentId = model.StudentId; + StudentName = model.StudentName; FormOfEvaluation = model.FormOfEvaluation; Score = model.Score; } @@ -55,6 +58,7 @@ namespace UniversityDatabaseImplement.Models { Id = Id, StudentId = StudentId, + StudentName = StudentName, FormOfEvaluation = FormOfEvaluation, Score = Score }; diff --git a/University/UniversityRestApi/Controllers/AttestationController.cs b/University/UniversityRestApi/Controllers/AttestationController.cs index d5e2555..a7cae0d 100644 --- a/University/UniversityRestApi/Controllers/AttestationController.cs +++ b/University/UniversityRestApi/Controllers/AttestationController.cs @@ -20,15 +20,15 @@ namespace UniversityRestApi.Controllers } [HttpGet] - public List? GetAttestations(int studentId) + public List? GetAttestations(int userId) { try { - return _logic.ReadList(new AttestationSearchModel { StudentId = studentId }); + return _logic.ReadList(new AttestationSearchModel { UserId = userId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения аттестаций студента id={Id}", studentId); + _logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId); throw; } }