diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs index 2927eb3..3c3399d 100644 --- a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs @@ -172,8 +172,8 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic public List GetLessonTask(ReportBindingModel model) { - - var tasks = _taskStorage.GetFilteredList(new TaskSearchModel + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + var tasks = _taskStorage.GetFilteredList(new TaskSearchModel { TeacherId = model.TeacherId, DateFrom = model.DateFrom, @@ -272,7 +272,7 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic _saveToPdfTeacher.CreateDoc(new PdfInfoTeacher { FileName = model.FileName, - Title = "Список заданий и занятий со сохожими материалами", + Title = "Список заданий и занятий с общими материалами", DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), LessonTasks = GetLessonTask(model) diff --git a/SchoolAgainStudy/TeacherWebClient/App.config b/SchoolAgainStudy/TeacherWebClient/App.config new file mode 100644 index 0000000..6c999e7 --- /dev/null +++ b/SchoolAgainStudy/TeacherWebClient/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs index 904ebfb..ca0d494 100644 --- a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using SchoolAgainStudyBusinessLogic.MailWorker; using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.SearchModel; @@ -19,7 +20,8 @@ namespace TeacherWebClient.Controllers private readonly IMaterialLogic _material; private readonly ITeacherLogic _teacher; private readonly IReportLogic _report; - public HomeController(ILogger logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report) + private readonly AbstractMailWorker mailSender; + public HomeController(ILogger logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report, AbstractMailWorker abstractMailWorker) { _logger = logger; _product = product; @@ -28,6 +30,25 @@ namespace TeacherWebClient.Controllers _material = material; _teacher = teacher; _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] @@ -224,7 +245,7 @@ namespace TeacherWebClient.Controllers { 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("Введите название и дату"); } @@ -273,10 +294,6 @@ namespace TeacherWebClient.Controllers { throw new Exception("Нет изделия"); } - if (materials.Length == 0) - { - throw new Exception("Нет материалов"); - } Dictionary lessonMaterials = new Dictionary(); foreach (int id in materials) @@ -331,7 +348,7 @@ namespace TeacherWebClient.Controllers { 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("Введите название и даты"); } @@ -382,10 +399,6 @@ namespace TeacherWebClient.Controllers { 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)) { throw new Exception("Дата выдачи должна быть раньше срока сдачи"); @@ -445,5 +458,39 @@ namespace TeacherWebClient.Controllers var items = _report.GetDiyMaterial(new ReportBindingModel { Materials = list, TeacherId = APIClient.Teacher.Id }); 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); + } } } \ No newline at end of file diff --git a/SchoolAgainStudy/TeacherWebClient/Program.cs b/SchoolAgainStudy/TeacherWebClient/Program.cs index dae0433..b2ecccf 100644 --- a/SchoolAgainStudy/TeacherWebClient/Program.cs +++ b/SchoolAgainStudy/TeacherWebClient/Program.cs @@ -6,6 +6,7 @@ using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.StorageContracts; using SchoolAgainStudyDataBaseImplements.Implements; using TeacherWebClient; +using SchoolAgainStudyBusinessLogic.MailWorker;; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); @@ -29,6 +30,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/SchoolAgainStudy/TeacherWebClient/TeacherWebClient.csproj b/SchoolAgainStudy/TeacherWebClient/TeacherWebClient.csproj index 34b0ea8..4f6ab1c 100644 --- a/SchoolAgainStudy/TeacherWebClient/TeacherWebClient.csproj +++ b/SchoolAgainStudy/TeacherWebClient/TeacherWebClient.csproj @@ -6,6 +6,16 @@ enable + + + + + + + Always + + + all diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Home/SendingEmail.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Home/SendingEmail.cshtml new file mode 100644 index 0000000..d5bb029 --- /dev/null +++ b/SchoolAgainStudy/TeacherWebClient/Views/Home/SendingEmail.cshtml @@ -0,0 +1,21 @@ +@{ + ViewData["Title"] = "Report"; +} +
+
+
От:
+
@Html.TextBox("dateFrom" ,"" ,new {type="Date"})
+
+
+
До:
+
@Html.TextBox("dateTo" ,"" ,new {type="Date"})
+
+
+
+
+
+
+
+ @section scripts{ + +} diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Home/Tasks.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Home/Tasks.cshtml index 3adbf2d..6a36882 100644 --- a/SchoolAgainStudy/TeacherWebClient/Views/Home/Tasks.cshtml +++ b/SchoolAgainStudy/TeacherWebClient/Views/Home/Tasks.cshtml @@ -35,7 +35,7 @@ Срок сдачи - Интересы + Материалы diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Home/_LessonTaskListPartial.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Home/_LessonTaskListPartial.cshtml new file mode 100644 index 0000000..829cccb --- /dev/null +++ b/SchoolAgainStudy/TeacherWebClient/Views/Home/_LessonTaskListPartial.cshtml @@ -0,0 +1,46 @@ +@using SchoolAgainStudyContracts.ViewModel; +@model List + + +
+ @{ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Занятия + + Дата проведения + + Задания + + Дата выдачи +
+ @Html.DisplayFor(modelItem => item.TitleLesson) + + @Html.DisplayFor(modelItem => item.DateEventLesson) + + @Html.DisplayFor(modelItem => item.TitleTask) + + @Html.DisplayFor(modelItem => item.DateIssueTask) +
+ } +
diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml index ea4fdc7..3b424d4 100644 --- a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml @@ -40,6 +40,9 @@ +