Неработающая почта, но работающее представление

This commit is contained in:
DyCTaTOR 2024-05-29 19:26:11 +04:00
parent c04d59cbda
commit 62ab8d442b
10 changed files with 160 additions and 26 deletions

View File

@ -47,7 +47,7 @@ public class ReportLogic : IReportLogic
_saveToExcelWorker = saveToExcelWorker;
_saveToWordWorker = saveToWordWorker;
// _saveToPdfWorker = saveToPdfWorker;
_saveToPdfWorker = saveToPdfWorker;
_saveToWordStorekeeper = saveToWordStorekeeper;
_saveToExcelStorekeeper = saveToExcelStorekeeper;
@ -180,7 +180,7 @@ public class ReportLogic : IReportLogic
return reportPlanOfStudyViewModels;
}
public List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model)
public List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents()
{
var planOfStudies = _planOfStudyStorage.GetFullList();
var reportPlanOfStudyAndStudentViewModels = new List<ReportPlanOfStudyAndStudentViewModel>();
@ -190,24 +190,26 @@ public class ReportLogic : IReportLogic
// Получаем список студентов для текущего плана обучения
var students = _studentStorage.GetFilteredList(new StudentSearchModel { Id = planOfStudy.Id });
var studentsAndDisciplines = new List<(string Student, string Discipline)>();
// Создаем списки имен студентов и дисциплин
var studentNames = students.Select(student => student.Name).ToList();
var disciplineNames = new List<string>();
foreach (var student in students)
{
// Получаем список дисциплин для текущего студента
var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel { Id = student.Id });
foreach (var discipline in disciplines)
{
studentsAndDisciplines.Add((student.Name, discipline.Name));
}
// Добавляем имена дисциплин в общий список
disciplineNames.AddRange(disciplines.Select(discipline => discipline.Name));
}
// Создаем ReportPlanOfStudyAndStudentViewModel и добавляем его в список
reportPlanOfStudyAndStudentViewModels.Add(new ReportPlanOfStudyAndStudentViewModel
{
Id = planOfStudy.Id, // Добавляем идентификатор плана обучения
PlanOfStudyName = planOfStudy.Profile,
StudentsAndDisciplines = studentsAndDisciplines
StudentName = studentNames,
DisciplineName = disciplineNames
});
}
@ -258,11 +260,13 @@ public class ReportLogic : IReportLogic
throw new NotImplementedException();
}
public void SendPlanOfStudyToEmail(ReportDateRangeBindingModel option, string email)
public void SendPlanOfStudyToEmail(ReportBindingModel option)
{
/*_saveToPdfWorker.CreateDoc(new PdfInfoWorker
_saveToPdfWorker.CreateDoc(new PdfInfoWorker
{
});*/
FileName = option.FileName,
Title = "Отчёт по заказам за период",
PlanOfStudyAndStudent = GetPlanOfStudyAndStudents()
});
}
}

View File

@ -9,25 +9,30 @@ namespace UniversityBusinessLogic.OfficePackage
{
CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "4 cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "План обучения", "Студент - дисциплина" },
Texts = new List<string> { "Номер", "План обучения", "Студент", исциплина" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var item in info.PlanOfStudyAndStudent)
{
CreateRow(new PdfRowParameters
foreach (var studentName in item.StudentName)
{
Texts = new List<string> { item.Id.ToString(), item.PlanOfStudyName, string.Join(", ", item.StudentsAndDisciplines.Select(sd => $"{sd.Student} - {sd.Discipline}")) },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach (var disciplineName in item.DisciplineName)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { item.Id.ToString(), item.PlanOfStudyName, studentName, disciplineName },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
}
SavePdf(info);
}

View File

@ -6,10 +6,7 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public DateOnly DateFrom { get; set; }
public DateOnly DateTo { get; set; }
public List<object> ReportObjects { get; set; } = new();
public List<ReportPlanOfStudyAndStudentViewModel> PlanOfStudyAndStudent { get; set; } = new();
}

View File

@ -6,6 +6,7 @@ using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Enums;
using UniversityDataModels.Models;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace UniversityClientAppWorker.Controllers
{
@ -279,5 +280,38 @@ namespace UniversityClientAppWorker.Controllers
return;
}
}
[HttpGet]
public IActionResult ReportPlanOfStudyAndStudents()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View("ReportPlanOfStudyAndStudents", APIClient.GetRequest<List<ReportPlanOfStudyAndStudentViewModel>>($"api/planofstudys/getplanofstudyandstudents"));
}
[HttpPost]
public void ReportPlanOfStudyAndStudents(string type)
{
if (APIClient.User == null)
{
Redirect("~/Home/Enter");
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì");
}
if (type == "pdf")
{
APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel
{
FileName = "C:\\Users\\{Environment.UserName}\\Desktop\\Ñâåäåíèÿ ïî ïëàíàì îáó÷åíèÿ.pdf"
});
APIClient.PostRequest("api/order/sendpdftomail", new MailSendInfoBindingModel
{
MailAddress = APIClient.User.Email,
Subject = "Îò÷åò",
Text = "Îò÷åò ïî çàêàçàì"
});
}
Response.Redirect("Index");
return;
}
}
}

View File

@ -0,0 +1,62 @@
@using UniversityContracts.ViewModels
@model List<ReportPlanOfStudyAndStudentViewModel>
@{
ViewData["Title"] = "Сведения по планам обучения";
}
<div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2>
</div>
<form method="post">
<div class="row">
<div class="col-8"></div>
<div class="col-4 mt-2">
<form method="post">
<input type="hidden" name="type" value="pdf" />
<input type="submit" value="Отправить в формате Pdf на почту" class="btn btn-primary" />
</form>
</div>
<div class="col-4 mt-2">
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>План обучения</th>
<th>Студенты</th>
<th>Дисциплины</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.PlanOfStudyName)
</td>
<td>
@foreach (var student in item.StudentName)
{
<div>
@Html.DisplayFor(modelItem => student)
</div>
}
</td>
<td>
@foreach (var discipline in item.DisciplineName)
{
<div>
@Html.DisplayFor(modelItem => discipline)
</div>
}
</td>
</tr>
}
</tbody>
</table>
</form>

View File

@ -41,6 +41,10 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Home"
asp-action="ReportPlanOfStudys">Отчёт по планам обучения</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home"
asp-action="ReportPlanOfStudyAndStudents">Сведения по планам обучения</a>
</li>
</ul>
</div>
</div>

View File

@ -19,14 +19,13 @@ namespace UniversityContracts.BusinessLogicContracts
List<ReportTeacherViewModel> GetTeachers(int userId);
List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model);
List<ReportPlanOfStudyViewModel> GetPlanOfStudyAndDisciplines(int userId);
List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model);
List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents();
void SaveTeachersToWord(ReportBindingModel option);
void SavePlanOfStudyToWord(ReportBindingModel option);
void SaveTeachersToExcel(ReportBindingModel option);
void SavePlanOfStudyToExcel(ReportBindingModel option);
void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email);
public void SendPlanOfStudyToEmail(ReportDateRangeBindingModel option, string email);
public void SendPlanOfStudyToEmail(ReportBindingModel option);
}
}

View File

@ -10,6 +10,7 @@ namespace UniversityContracts.ViewModels
{
public int Id { get; set; }
public string PlanOfStudyName { get; set; } = string.Empty;
public List<(string Student, string Discipline)> StudentsAndDisciplines { get; set; } = new();
public List<string> StudentName { get; set; } = new();
public List<string> DisciplineName { get; set; } = new();
}
}

View File

@ -63,6 +63,20 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpGet]
public List<ReportPlanOfStudyAndStudentViewModel>? GetPlanOfStudyAndStudents()
{
try
{
var report = _reportLogic.GetPlanOfStudyAndStudents();
return report;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка планов обучения");
throw;
}
}
[HttpPost]
public void LoadReportToWord(ReportBindingModel model)
{
@ -90,6 +104,19 @@ namespace UniversityRestApi.Controllers
}
}
[HttpPost]
public void CreateReportToPDFFile(ReportBindingModel model)
{
try
{
_reportLogic.SendPlanOfStudyToEmail(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void SendPDFToMail(MailSendInfoBindingModel model)
{
try

View File

@ -39,6 +39,7 @@ builder.Services.AddTransient<IPlanOfStudyLogic, PlanOfStudyLogic>();
builder.Services.AddTransient<IAttestationLogic, AttestationLogic>();
builder.Services.AddTransient<IStatementLogic, StatementLogic>();
builder.Services.AddTransient<IStudentLogic, StudentLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();