Формируется ПДФ, идет отправка на почту
This commit is contained in:
parent
0d12590f78
commit
f1dbc908c7
@ -172,8 +172,8 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
public List<ReportLessonTaskViewModel> GetLessonTask(ReportBindingModel model)
|
public List<ReportLessonTaskViewModel> GetLessonTask(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||||
var tasks = _taskStorage.GetFilteredList(new TaskSearchModel
|
var tasks = _taskStorage.GetFilteredList(new TaskSearchModel
|
||||||
{
|
{
|
||||||
TeacherId = model.TeacherId,
|
TeacherId = model.TeacherId,
|
||||||
DateFrom = model.DateFrom,
|
DateFrom = model.DateFrom,
|
||||||
@ -272,7 +272,7 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
|
|||||||
_saveToPdfTeacher.CreateDoc(new PdfInfoTeacher
|
_saveToPdfTeacher.CreateDoc(new PdfInfoTeacher
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
Title = "Список заданий и занятий со сохожими материалами",
|
Title = "Список заданий и занятий с общими материалами",
|
||||||
DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
|
DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
|
||||||
DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
|
DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
|
||||||
LessonTasks = GetLessonTask(model)
|
LessonTasks = GetLessonTask(model)
|
||||||
|
11
SchoolAgainStudy/TeacherWebClient/App.config
Normal file
11
SchoolAgainStudy/TeacherWebClient/App.config
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<appSettings>
|
||||||
|
<add key="SmtpClientHost" value="smtp.gmail.com" />
|
||||||
|
<add key="SmtpClientPort" value="587" />
|
||||||
|
<add key="PopHost" value="pop.gmail.com" />
|
||||||
|
<add key="PopPort" value="995" />
|
||||||
|
<add key="MailLogin" value="labrpp89@gmail.com" />
|
||||||
|
<add key="MailPassword" value="ajtl tzre ozva bbtz" />
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using SchoolAgainStudyBusinessLogic.MailWorker;
|
||||||
using SchoolAgainStudyContracts.BindingModel;
|
using SchoolAgainStudyContracts.BindingModel;
|
||||||
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
||||||
using SchoolAgainStudyContracts.SearchModel;
|
using SchoolAgainStudyContracts.SearchModel;
|
||||||
@ -19,7 +20,8 @@ namespace TeacherWebClient.Controllers
|
|||||||
private readonly IMaterialLogic _material;
|
private readonly IMaterialLogic _material;
|
||||||
private readonly ITeacherLogic _teacher;
|
private readonly ITeacherLogic _teacher;
|
||||||
private readonly IReportLogic _report;
|
private readonly IReportLogic _report;
|
||||||
public HomeController(ILogger<HomeController> logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report)
|
private readonly AbstractMailWorker mailSender;
|
||||||
|
public HomeController(ILogger<HomeController> logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report, AbstractMailWorker abstractMailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_product = product;
|
_product = product;
|
||||||
@ -28,6 +30,25 @@ namespace TeacherWebClient.Controllers
|
|||||||
_material = material;
|
_material = material;
|
||||||
_teacher = teacher;
|
_teacher = teacher;
|
||||||
_report = report;
|
_report = report;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mailSender = abstractMailWorker;
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
||||||
|
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
||||||
|
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
|
||||||
|
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
|
||||||
|
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
|
||||||
|
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError(ex, "Ошибка работы с почтой");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -224,7 +245,7 @@ namespace TeacherWebClient.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(dateEvent) && product <= 0 || materials.Length == 0)
|
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(dateEvent) || product <= 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Введите название и дату");
|
throw new Exception("Введите название и дату");
|
||||||
}
|
}
|
||||||
@ -273,10 +294,6 @@ namespace TeacherWebClient.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Нет изделия");
|
throw new Exception("Нет изделия");
|
||||||
}
|
}
|
||||||
if (materials.Length == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Нет материалов");
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary<int, IMaterial> lessonMaterials = new Dictionary<int, IMaterial>();
|
Dictionary<int, IMaterial> lessonMaterials = new Dictionary<int, IMaterial>();
|
||||||
foreach (int id in materials)
|
foreach (int id in materials)
|
||||||
@ -331,7 +348,7 @@ namespace TeacherWebClient.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(dateIssue) || string.IsNullOrEmpty(dateDelivery) || materials.Length == 0)
|
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(dateIssue) || string.IsNullOrEmpty(dateDelivery))
|
||||||
{
|
{
|
||||||
throw new Exception("Введите название и даты");
|
throw new Exception("Введите название и даты");
|
||||||
}
|
}
|
||||||
@ -382,10 +399,6 @@ namespace TeacherWebClient.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Нет срока сдачи");
|
throw new Exception("Нет срока сдачи");
|
||||||
}
|
}
|
||||||
if (materials.Length == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Нет материалов");
|
|
||||||
}
|
|
||||||
if (DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc) >= DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc))
|
if (DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc) >= DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc))
|
||||||
{
|
{
|
||||||
throw new Exception("Дата выдачи должна быть раньше срока сдачи");
|
throw new Exception("Дата выдачи должна быть раньше срока сдачи");
|
||||||
@ -445,5 +458,39 @@ namespace TeacherWebClient.Controllers
|
|||||||
var items = _report.GetDiyMaterial(new ReportBindingModel { Materials = list, TeacherId = APIClient.Teacher.Id });
|
var items = _report.GetDiyMaterial(new ReportBindingModel { Materials = list, TeacherId = APIClient.Teacher.Id });
|
||||||
return PartialView("_DiyListPartial", items);
|
return PartialView("_DiyListPartial", items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult SendingEmail()
|
||||||
|
{
|
||||||
|
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult GetPartialForPDF(string dateFrom, string dateTo)
|
||||||
|
{
|
||||||
|
var _dateFrom = DateTime.SpecifyKind(DateTime.Parse(dateFrom), DateTimeKind.Utc);
|
||||||
|
var _dateTo = DateTime.SpecifyKind(DateTime.Parse(dateTo), DateTimeKind.Utc);
|
||||||
|
if (_dateFrom > _dateTo)
|
||||||
|
{
|
||||||
|
throw new Exception("Неверные даты");
|
||||||
|
}
|
||||||
|
string path = $"C:\\Университет\\2 курс\\4 семестр\\РПП\\Курсач РПП\\Reports\\{APIClient.Teacher.Name} от {_dateFrom.ToString("dd/MM/yyyy")}.pdf";
|
||||||
|
_report.SaveLessonTaskToPdfFile
|
||||||
|
(new ReportBindingModel
|
||||||
|
{
|
||||||
|
FileName = path,
|
||||||
|
DateFrom = _dateFrom,
|
||||||
|
DateTo = _dateTo,
|
||||||
|
TeacherId = APIClient.Teacher.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = _report.GetLessonTask(new ReportBindingModel { DateFrom = _dateFrom, DateTo = _dateTo, TeacherId = APIClient.Teacher.Id });
|
||||||
|
mailSender.MailSendAsync(new MailSendInfoBindingModel
|
||||||
|
{
|
||||||
|
MailAddress = APIClient.Teacher.Email,
|
||||||
|
Subject = "Отчет",
|
||||||
|
Path = path
|
||||||
|
});
|
||||||
|
return PartialView("_LessonTaskListPartial", items);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ using SchoolAgainStudyContracts.BusinessLogicContracts;
|
|||||||
using SchoolAgainStudyContracts.StorageContracts;
|
using SchoolAgainStudyContracts.StorageContracts;
|
||||||
using SchoolAgainStudyDataBaseImplements.Implements;
|
using SchoolAgainStudyDataBaseImplements.Implements;
|
||||||
using TeacherWebClient;
|
using TeacherWebClient;
|
||||||
|
using SchoolAgainStudyBusinessLogic.MailWorker;;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
@ -29,6 +30,8 @@ builder.Services.AddTransient<ITeacherLogic, TeacherLogic>();
|
|||||||
builder.Services.AddTransient<IMaterialLogic, MaterialLogic>();
|
builder.Services.AddTransient<IMaterialLogic, MaterialLogic>();
|
||||||
builder.Services.AddTransient<ILessonLogic, LessonLogic>();
|
builder.Services.AddTransient<ILessonLogic, LessonLogic>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
builder.Services.AddTransient<AbstractSaveToExcelStudent, SaveToExcelStudent>();
|
builder.Services.AddTransient<AbstractSaveToExcelStudent, SaveToExcelStudent>();
|
||||||
builder.Services.AddTransient<AbstractSaveToWordStudent, SaveToWordStudent>();
|
builder.Services.AddTransient<AbstractSaveToWordStudent, SaveToWordStudent>();
|
||||||
builder.Services.AddTransient<AbstractSaveToPdfStudent, SaveToPdfStudent>();
|
builder.Services.AddTransient<AbstractSaveToPdfStudent, SaveToPdfStudent>();
|
||||||
|
@ -6,6 +6,16 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Remove="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Report";
|
||||||
|
}
|
||||||
|
<form id="my_form" asp-action="SendingEmail" method="get" data-ajax="true" data-ajax-method="get" data-ajax-update="#panel" data-ajax-mode='replace' data-ajax-url="@Url.Action("GetPartialForPDF","Home")">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">От:</div>
|
||||||
|
<div class="col-8">@Html.TextBox("dateFrom" ,"" ,new {type="Date"})</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">До:</div>
|
||||||
|
<div class="col-8">@Html.TextBox("dateTo" ,"" ,new {type="Date"})</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="row pr-3 pl-3" id="panel">
|
||||||
|
@section scripts{
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ajax-unobtrusive/3.2.6/jquery.unobtrusive-ajax.min.js"></script>
|
||||||
|
}
|
@ -35,7 +35,7 @@
|
|||||||
Срок сдачи
|
Срок сдачи
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Интересы
|
Материалы
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
@using SchoolAgainStudyContracts.ViewModel;
|
||||||
|
@model List<ReportLessonTaskViewModel>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Занятия
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Дата проведения
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Задания
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Дата выдачи
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.TitleLesson)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateEventLesson)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.TitleTask)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateIssueTask)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</div>
|
@ -40,6 +40,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Reports">Отчеты</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Reports">Отчеты</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="SendingEmail">НаПочту</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user