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 7e49826..e16ad15 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -19,21 +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) + { + 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/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..f53d064 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,74 @@ 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 IActionResult 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 = 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() { @@ -238,6 +298,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 +320,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 +337,20 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\ .docx" + FileName = "C:\\\\ .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:\\\\ .xlsx" }); - Response.Redirect("Index"); - return; + return GetExcelFile(); } + return Redirect("Index"); } [HttpGet] public IActionResult ReportPlanOfStudyAndStudents() @@ -301,13 +373,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/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/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..43ada8d --- /dev/null +++ b/University/UniversityClientAppWorker/Views/Home/InfoAttestation.cshtml @@ -0,0 +1,39 @@ +@using UniversityContracts.ViewModels +@model AttestationViewModel +@{ + ViewData["Title"] = "План обучения"; +} +
+

@ViewData["Title"]

+
+ +
+
Форма оценивания:
+
+ +
+
+
+
Студент:
+
+ +
+
+
+
Оценка:
+
+ +
+
+
+
+
+ + +
+
+
\ No newline at end of file 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/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 07213d0..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=DESKTOP-N8BRIPR\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); } 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/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) 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) {