From 7927b8e1ba5a773c4013cdf900f86af5596b4ad3 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 29 May 2024 20:33:49 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D1=82=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=B8=20=D0=BF=D0=B4=D1=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/AbstractSaveToPdfWorker.cs | 11 +++++++- .../HelperModels/PdfInfoWorker.cs | 2 -- .../Implements/SaveToPdfWorker.cs | 16 +++++++++--- .../Controllers/HomeController.cs | 26 ++++++++++++++----- .../UniversityClientAppWorker/Program.cs | 6 +++++ .../UniversityClientAppWorker.csproj | 1 + .../UniversityDatabase.cs | 2 +- .../Controllers/PlanOfStudysController.cs | 1 + 8 files changed, 51 insertions(+), 14 deletions(-) diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs index 7e49826..9ebc146 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -19,7 +19,7 @@ namespace UniversityBusinessLogic.OfficePackage ParagraphAlignment = PdfParagraphAlignmentType.Center }); - foreach (var item in info.PlanOfStudyAndStudent) + /*foreach (var item in info.PlanOfStudyAndStudent) { foreach (var studentName in item.StudentName) { @@ -33,6 +33,15 @@ namespace UniversityBusinessLogic.OfficePackage }); } } + }*/ + foreach(var item in info.PlanOfStudyAndStudent) + { + CreateRow(new PdfRowParameters + { + Texts = new List { item.Id.ToString(), item.PlanOfStudyName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); } SavePdf(info); } diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs index 99cd615..2e43205 100644 --- a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs @@ -5,9 +5,7 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels public class PdfInfoWorker { public string? FileName { get; set; } - public Stream? Stream { get; set; } public string Title { get; set; } = string.Empty; - public List ReportObjects { get; set; } = new(); public List PlanOfStudyAndStudent { get; set; } = new(); } } diff --git a/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs index 94bf731..01a3d74 100644 --- a/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs @@ -103,13 +103,23 @@ namespace UniversityBusinessLogic.OfficePackage.Implements protected override void SavePdf(PdfInfoWorker info) { + if (_document == null) + { + throw new InvalidOperationException("Document is not initialized."); + } var renderer = new PdfDocumentRenderer(true) { Document = _document }; - System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); - renderer.RenderDocument(); - renderer.PdfDocument.Save(info.FileName); + try + { + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + catch (NullReferenceException ex) + { + throw new Exception(ex.Message); + } } } } \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 05e3ff0..552d1b3 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -238,6 +238,19 @@ namespace UniversityClientAppWorker.Controllers return; } [HttpGet] + public IActionResult GetWordFile() + { + return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\ .docx", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + " .docx"); + } + public IActionResult GetExcelFile() + { + return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\ .xlsx", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + " .xlsx"); + } + [HttpGet] public IActionResult ReportPlanOfStudys() { if (APIClient.User == null) @@ -247,7 +260,7 @@ namespace UniversityClientAppWorker.Controllers return View("ReportPlanOfStudys", APIClient.GetRequest>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}")); } [HttpPost] - public void ReportPlanOfStudys(string type) + public IActionResult ReportPlanOfStudys(string type) { if (APIClient.User == null) { @@ -264,21 +277,20 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\ .docx" + FileName = $"C:\\Users\\{Environment.UserName}\\Downloads\\ .docx" }); - Response.Redirect("Index"); - return; + return GetWordFile(); } if (type == "xlsx") { APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\ .xlsx" + FileName = $"C:\\Users\\{Environment.UserName}\\Downloads\\ .xlsx" }); - Response.Redirect("Index"); - return; + return GetExcelFile(); } + return Redirect("Index"); } [HttpGet] public IActionResult ReportPlanOfStudyAndStudents() diff --git a/University/UniversityClientAppWorker/Program.cs b/University/UniversityClientAppWorker/Program.cs index ae82eb7..a9df2eb 100644 --- a/University/UniversityClientAppWorker/Program.cs +++ b/University/UniversityClientAppWorker/Program.cs @@ -1,10 +1,16 @@ using PlumbingRepairClientApp; +using UniversityBusinessLogic.OfficePackage; +using UniversityBusinessLogic.OfficePackage.Implements; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + var app = builder.Build(); APIClient.Connect(builder.Configuration); diff --git a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj index 469fd09..50cbca7 100644 --- a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj +++ b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj @@ -15,6 +15,7 @@ + diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..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=DESKTOP-N8BRIPR\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/PlanOfStudysController.cs b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs index d420613..70bd663 100644 --- a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs +++ b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs @@ -108,6 +108,7 @@ namespace UniversityRestApi.Controllers { try { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); _reportLogic.SendPlanOfStudyToEmail(model); } catch (Exception ex) From 478fbf8b8a153704671f9a33539ad1420861df92 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 29 May 2024 21:06:39 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=B4=D1=84=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MailWorker/MailKitWorker.cs | 2 +- .../OfficePackage/AbstractSaveToPdfWorker.cs | 56 +++++++++++-------- .../Controllers/HomeController.cs | 10 ++-- .../UniversityDatabase.cs | 2 +- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/University/UniversityBusinessLogic/MailWorker/MailKitWorker.cs b/University/UniversityBusinessLogic/MailWorker/MailKitWorker.cs index ac46a95..3bb5c2f 100644 --- a/University/UniversityBusinessLogic/MailWorker/MailKitWorker.cs +++ b/University/UniversityBusinessLogic/MailWorker/MailKitWorker.cs @@ -32,7 +32,7 @@ namespace UniversityBusinessLogic.MailWorker objMailMessage.Body = info.Text; objMailMessage.SubjectEncoding = Encoding.UTF8; objMailMessage.BodyEncoding = Encoding.UTF8; - Attachment attachment = new Attachment($"C:\\Users\\{Environment.UserName}\\Desktop\\Сведения по планам обучения.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + Attachment attachment = new Attachment("C:\\ВременныеОтчёты\\Сведения по планам обучения.pdf", new ContentType(MediaTypeNames.Application.Pdf)); objMailMessage.Attachments.Add(attachment); objSmtpClient.UseDefaultCredentials = false; diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs index 9ebc146..e16ad15 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -19,30 +19,38 @@ namespace UniversityBusinessLogic.OfficePackage ParagraphAlignment = PdfParagraphAlignmentType.Center }); - /*foreach (var item in info.PlanOfStudyAndStudent) - { - foreach (var studentName in item.StudentName) - { - foreach (var disciplineName in item.DisciplineName) - { - CreateRow(new PdfRowParameters - { - Texts = new List { item.Id.ToString(), item.PlanOfStudyName, studentName, disciplineName }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } - } - }*/ - foreach(var item in info.PlanOfStudyAndStudent) - { - CreateRow(new PdfRowParameters - { - Texts = new List { item.Id.ToString(), item.PlanOfStudyName }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } + foreach (var item in info.PlanOfStudyAndStudent) + { + foreach (var studentName in item.StudentName) + { + var rowTexts = new List { item.Id.ToString(), item.PlanOfStudyName, studentName }; + if (item.DisciplineName.Any()) + { + foreach (var disciplineName in item.DisciplineName) + { + rowTexts.Add(disciplineName); + CreateRow(new PdfRowParameters + { + Texts = rowTexts, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + rowTexts.RemoveAt(rowTexts.Count - 1); + } + } + else + { + // Если нет дисциплин, добавляем пустую строку + rowTexts.Add(""); + CreateRow(new PdfRowParameters + { + Texts = rowTexts, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + } SavePdf(info); } diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 552d1b3..7962177 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -277,7 +277,7 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Downloads\\ .docx" + FileName = "C:\\\\ .docx" }); return GetWordFile(); } @@ -286,7 +286,7 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Downloads\\ .xlsx" + FileName = "C:\\\\ .xlsx" }); return GetExcelFile(); } @@ -313,13 +313,13 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel { - FileName = "C:\\Users\\{Environment.UserName}\\Desktop\\ .pdf" + FileName = "C:\\\\ .pdf" }); - APIClient.PostRequest("api/order/sendpdftomail", new MailSendInfoBindingModel + APIClient.PostRequest("api/planofstudys/sendpdftomail", new MailSendInfoBindingModel { MailAddress = APIClient.User.Email, Subject = "", - Text = " " + Text = " " }); } Response.Redirect("Index"); diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 2b73bad..3eebb86 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=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } From 85159ea8afc3f3a5aa3d0b7bfb6f38ff35f92cce Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 29 May 2024 21:59:17 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 20 ++++++++++ .../Views/Home/Attestations.cshtml | 2 +- .../Views/Home/InfoAttestation.cshtml | 38 +++++++++++++++++++ .../IAttestationLogic.cs | 1 + .../Models/IAttestationModel.cs | 1 - .../UniversityDatabase.cs | 2 +- .../Controllers/AttestationController.cs | 17 ++++++++- .../Controllers/StudentController.cs | 13 +++++++ 8 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 7962177..5809915 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -1,3 +1,4 @@ +using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Mvc; using PlumbingRepairClientApp; using System.Diagnostics; @@ -149,15 +150,34 @@ namespace UniversityClientAppWorker.Controllers { throw new Exception(" "); } + var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); + + if(Student == null) + { + throw new Exception(" "); + } APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel { UserId = APIClient.User.Id, FormOfEvaluation = formOfEvaluation, StudentId = student, + StudentName = Student.Name, Score = score }); Response.Redirect("Attestations"); } + [HttpGet] + public async Task InfoAttestation(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); + ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); + var obj = await APIClient.GetRequestAsync($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}"); + return View(obj); + } [HttpGet] public async Task Students() { diff --git a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml index fb2d3c5..3320ecf 100644 --- a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml @@ -67,7 +67,7 @@
- Изменить + Изменить
diff --git a/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml new file mode 100644 index 0000000..a1c5ae0 --- /dev/null +++ b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml @@ -0,0 +1,38 @@ +@using UniversityContracts.ViewModels +@model AttestationViewModel +@{ + ViewData["Title"] = "Аттестация"; +} +
+

Аттестация

+
+ +
+
Форма оценивания:
+
+ +
+
+
+
Студент:
+
+ +
+
+
+
Оценка:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs index 7df94d5..d990a57 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs @@ -12,6 +12,7 @@ namespace UniversityContracts.BusinessLogicsContracts public interface IAttestationLogic { List? ReadList(AttestationSearchModel? model); + AttestationViewModel? ReadElement(AttestationSearchModel model); bool CreateAttestation(AttestationBindingModel model); bool DeleteAttestation(AttestationBindingModel model); bool UpdateAttestation(AttestationBindingModel model); diff --git a/University/UniversityDataModels/Models/IAttestationModel.cs b/University/UniversityDataModels/Models/IAttestationModel.cs index 084cdfb..9c2ea2e 100644 --- a/University/UniversityDataModels/Models/IAttestationModel.cs +++ b/University/UniversityDataModels/Models/IAttestationModel.cs @@ -5,7 +5,6 @@ namespace UniversityDataModels.Models public interface IAttestationModel : IId { int UserId { get; } - string StudentName { get; } string FormOfEvaluation { get; } AttestationScore Score { get; } int StudentId { get; } diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 3eebb86..85c48bf 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/AttestationController.cs b/University/UniversityRestApi/Controllers/AttestationController.cs index a7cae0d..5f8f581 100644 --- a/University/UniversityRestApi/Controllers/AttestationController.cs +++ b/University/UniversityRestApi/Controllers/AttestationController.cs @@ -32,6 +32,19 @@ namespace UniversityRestApi.Controllers throw; } } + [HttpGet] + public AttestationViewModel? GetAttestation(int userId, int id) + { + try + { + return _logic.ReadElement(new AttestationSearchModel { UserId = userId, Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId); + throw; + } + } [HttpPost] public void CreateAttestation(AttestationBindingModel model) { @@ -44,7 +57,7 @@ namespace UniversityRestApi.Controllers throw; } } - [HttpPut] + [HttpPost] public void UpdateAttestation(AttestationBindingModel model) { try @@ -57,7 +70,7 @@ namespace UniversityRestApi.Controllers throw; } } - [HttpDelete] + [HttpPost] public void DeleteAttestation(AttestationBindingModel model) { try diff --git a/University/UniversityRestApi/Controllers/StudentController.cs b/University/UniversityRestApi/Controllers/StudentController.cs index 06734a7..24c3e49 100644 --- a/University/UniversityRestApi/Controllers/StudentController.cs +++ b/University/UniversityRestApi/Controllers/StudentController.cs @@ -30,6 +30,19 @@ namespace UniversityRestApi.Controllers throw; } } + [HttpGet] + public StudentViewModel? GetStudent(int userId, int studentId) + { + try + { + return _logic.ReadElement(new StudentSearchModel { UserId = userId, Id = studentId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка студентов пользователя id={Id}", userId); + throw; + } + } [HttpPost] public void CreateStudent(StudentBindingModel model) { From d6e5e9dced9d7f73cc5802e53ea67b08b39f3fb1 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 29 May 2024 22:48:30 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=90=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 --- .../Controllers/HomeController.cs | 44 ++++++++++++++++++- .../Views/Home/InfoAttestation.cshtml | 7 +-- .../Views/Home/InfoPlanOfStudy.cshtml | 2 +- .../UniversityDatabase.cs | 2 +- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 5809915..f53d064 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -167,7 +167,7 @@ namespace UniversityClientAppWorker.Controllers Response.Redirect("Attestations"); } [HttpGet] - public async Task InfoAttestation(int id) + public IActionResult InfoAttestation(int id) { if (APIClient.User == null) { @@ -175,9 +175,49 @@ namespace UniversityClientAppWorker.Controllers } ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - var obj = await APIClient.GetRequestAsync($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}"); + var obj = APIClient.GetRequest($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}"); return View(obj); } + [HttpPost] + public void UpdateAttestation(int id, string formOfEvaluation, int student, AttestationScore score) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) + { + throw new Exception(" "); + } + var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); + + if (Student == null) + { + throw new Exception(" "); + } + APIClient.PostRequest("api/attestation/updateattestation", new AttestationBindingModel + { + Id = id, + FormOfEvaluation = formOfEvaluation, + StudentId = student, + StudentName = Student.Name, + Score = score + }); + Response.Redirect("Attestations"); + } + [HttpPost] + public void DeleteAttestation(int id) + { + if (id == 0) + { + throw new Exception("id 0"); + } + APIClient.PostRequest("api/attestation/deleteattestation", new PlanOfStudyBindingModel + { + Id = id + }); + Response.Redirect("Attestations"); + } [HttpGet] public async Task Students() { diff --git a/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml index a1c5ae0..43ada8d 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"]

@@ -26,12 +26,13 @@
Оценка:
- +
+
diff --git a/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml b/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml index 68c4eda..8eadf37 100644 --- a/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/InfoPlanOfStudy.cshtml @@ -4,7 +4,7 @@ ViewData["Title"] = "План обучения"; }
-

План обучения

+

@ViewData["Title"]

diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 85c48bf..3eebb86 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=DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); }