From 616ab0c5c483017cdf6caf572cdd8099450cb2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Fri, 19 May 2023 19:25:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 80 +++++++++++++-- .../HotelHeadwaiterApp.csproj | 7 +- Hotel/HostrelHeadwaiterApp/Program.cs | 19 +++- .../Views/Home/ListDinnersToPdfFile.cshtml | 98 +++++++++++++------ .../BusinessLogics/ConferenceBookingLogic.cs | 40 +++++++- .../BusinessLogics/DinnerLogic.cs | 38 ++++++- .../BusinessLogics/ReportLogicHeadwaiter.cs | 10 ++ .../BusinessLogics/RoomLogic.cs | 41 +++++++- .../MailWorker/MailKitWorker.cs | 2 +- .../HelperModels/PdfInfoHeadwaiter.cs | 2 +- .../Controllers/ReportController.cs | 4 +- 11 files changed, 283 insertions(+), 58 deletions(-) diff --git a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs index 1c99444..0683845 100644 --- a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs +++ b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using HostrelHeadwaiterApp.Models; using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using Microsoft.AspNetCore.Mvc; @@ -10,10 +11,12 @@ namespace HostrelHeadwaiterApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportHeadwaiterLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportHeadwaiterLogic report) { _logger = logger; + _report = report; } public IActionResult CreateDinner() @@ -627,6 +630,11 @@ namespace HostrelHeadwaiterApp.Controllers return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } + public IActionResult GetPdfFile() + { + return new PhysicalFileResult("E:\\ReportsCourseWork\\pdffile.pdf", "application/pdf"); + } + [HttpGet] public IActionResult ListDinnersToPdfFile() { @@ -634,26 +642,82 @@ namespace HostrelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - - return View(); + return View("ListDinnersToPdfFile"); } [HttpPost] - public void ListDinnersToPdfFile(DateTime dateFrom, DateTime dateTo) + public void ListDinnersToPdfFile(DateTime dateFrom, DateTime dateTo, string headwaiterEmail) { if (APIClient.Headwaiter == null) { - throw new Exception("Не авторизованы"); + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - - APIClient.PostRequest("api/Report/CreateHeadwaiterReportToPdfFile", new ReportHeadwaiterBindingModel() + if (string.IsNullOrEmpty(headwaiterEmail)) + { + throw new Exception("Email пуст"); + } + APIClient.PostRequest("api/report/CreateHeadwaiterReportToPdfFile", new ReportHeadwaiterBindingModel { DateFrom = dateFrom, DateTo = dateTo, HeadwaiterId = APIClient.Headwaiter.Id }); - + APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel + { + MailAddress = headwaiterEmail, + Subject = "Отчет по участникам (pdf)", + Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString() + }); Response.Redirect("ListDinnersToPdfFile"); } + + [HttpGet] + public string GetDinnersReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + result = _report.GetDinners(new ReportHeadwaiterBindingModel + { + HeadwaiterId = APIClient.Headwaiter.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + foreach (var report in result) + { + table += $"

{report.DinnerName}

"; + table += $""; + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + table += "
Имя комнатыЦена комнатыНазвание залаДата броинирования
{report.RoomName}{report.RoomPrice}{report.NameHall}{report.BookingDate}
"; + } + //table += $"

Итого: {result.Item2}

"; + return table; + } } } \ No newline at end of file diff --git a/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj b/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj index 6dc593f..e0b37f3 100644 --- a/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj +++ b/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj @@ -7,13 +7,16 @@ + - - + + + + diff --git a/Hotel/HostrelHeadwaiterApp/Program.cs b/Hotel/HostrelHeadwaiterApp/Program.cs index 1400edb..810fd26 100644 --- a/Hotel/HostrelHeadwaiterApp/Program.cs +++ b/Hotel/HostrelHeadwaiterApp/Program.cs @@ -1,6 +1,19 @@ using HostrelHeadwaiterApp; +using HotelBusinessLogic.BusinessLogics; +using HotelBusinessLogic.OfficePackage; +using HotelBusinessLogic.OfficePackage.Implements; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.StoragesContracts; +using HotelDataBaseImplement.Implemets; var builder = WebApplication.CreateBuilder(args); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // Add services to the container. builder.Services.AddControllersWithViews(); @@ -9,12 +22,12 @@ var app = builder.Build(); APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) -{ +//if (!app.Environment.IsDevelopment()) +//{ app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); -} +//} app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnersToPdfFile.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnersToPdfFile.cshtml index a1862a6..e542b5b 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnersToPdfFile.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnersToPdfFile.cshtml @@ -1,35 +1,73 @@ -@{ - ViewData["Title"] = "ListDinnersToPdf"; +@using HotelContracts.ViewModels + +@{ + ViewData["Title"] = "ListDinnersToPdfFile"; } -
-

- Создание отчета по участникам за период -

+

Отчет по участникам за период

-
-
- - -
- -
-
-
-
-
\ No newline at end of file +
+ @{ +
+ + +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+ } +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs index 886bfe3..06cedde 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs @@ -1,4 +1,5 @@ -using HotelContracts.BindingModels; +using HotelBusinessLogic.MailWorker; +using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.StoragesContracts; @@ -17,11 +18,15 @@ namespace HotelBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IConferenceBookingStorage _conferenceBookingStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IHeadwaiterLogic _headwaiterLogic; - public ConferenceBookingLogic(ILogger logger, IConferenceBookingStorage conferenceBookingStorage) + public ConferenceBookingLogic(ILogger logger, IConferenceBookingStorage conferenceBookingStorage, IHeadwaiterLogic headwaiterLogic, AbstractMailWorker mailWorker) { _logger = logger; _conferenceBookingStorage = conferenceBookingStorage; + _mailWorker = mailWorker; + _headwaiterLogic = headwaiterLogic; } public bool AddDinnerToConferenceBooking(ConferenceBookingSearchModel model, IDinnerModel dinner) @@ -62,12 +67,16 @@ namespace HotelBusinessLogic.BusinessLogics CheckModel(model); model.ConferenceBookingDinners = new(); - if (_conferenceBookingStorage.Insert(model) == null) + var result = _conferenceBookingStorage.Insert(model); + + if (result == null) { _logger.LogWarning("Insert operation failed"); return false; } + SendConferenceBookingMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", План питания №{result.Id}", $"План питания №{result.Id} под названием {result.NameHall} и стоимостью {result.BookingDate} добавлен"); + return true; } @@ -77,12 +86,16 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_conferenceBookingStorage.Delete(model) == null) + var result = _conferenceBookingStorage.Delete(model); + + if (result == null) { _logger.LogWarning("Delete operation failed"); return false; } + SendConferenceBookingMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", План питания №{result.Id}", $"План питания №{result.Id} под названием {result.NameHall} и стоимостью {result.BookingDate} удален"); + return true; } @@ -158,5 +171,24 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("ConferenceBooking. Id: { Id}", model.Id); } + + private bool SendConferenceBookingMessage(int headwaiterId, string subject, string text) + { + var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId }); + + if (headwaiter == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = headwaiter.HeadwaiterEmail, + Subject = subject, + Text = text + }); + + return true; + } } } diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs index b97212d..7842eab 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs @@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.StoragesContracts; using HotelContracts.ViewModels; +using HotelBusinessLogic.MailWorker; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -16,23 +17,31 @@ namespace HotelBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IDinnerStorage _dinnerStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IHeadwaiterLogic _headwaiterLogic; - public DinnerLogic(ILogger logger, IDinnerStorage dinnerStorage) + public DinnerLogic(ILogger logger, IDinnerStorage dinnerStorage, AbstractMailWorker mailWorker, IHeadwaiterLogic headwaiterLogic) { _logger = logger; _dinnerStorage = dinnerStorage; + _mailWorker = mailWorker; + _headwaiterLogic = headwaiterLogic; } public bool Create(DinnerBindingModel model) { CheckModel(model); - if (_dinnerStorage.Insert(model) == null) + var result = _dinnerStorage.Insert(model); + + if (result == null) { _logger.LogWarning("Insert operation failed"); return false; } + SendDinnerMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Участник №{result.Id}", $"Участник №{result.Id} по имени {result.DinnerName} и с гражданством {result.DinnerPrice} добавлен"); + return true; } @@ -42,12 +51,16 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_dinnerStorage.Delete(model) == null) + var result = _dinnerStorage.Delete(model); + + if (result == null) { _logger.LogWarning("Delete operation failed"); return false; } + SendDinnerMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Участник №{result.Id}", $"Участник №{result.Id} по имени {result.DinnerName} и с гражданством {result.DinnerPrice} удален"); + return true; } @@ -126,5 +139,24 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("Dinner. DinnerName:{DinnerName}.DinnerPrice:{ DinnerPrice}. Id: { Id}", model.DinnerName, model.DinnerPrice, model.Id); } + + private bool SendDinnerMessage(int headwaiterId, string subject, string text) + { + var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId }); + + if (headwaiter == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = headwaiter.HeadwaiterEmail, + Subject = subject, + Text = text + }); + + return true; + } } } diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs index 0339189..789d84c 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs @@ -138,6 +138,16 @@ namespace HotelBusinessLogic.BusinessLogics public void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model) { + if (model.DateFrom == null) + { + throw new ArgumentException("Дата начала не задана"); + } + + if (model.DateTo == null) + { + throw new ArgumentException("Дата окончания не задана"); + } + _saveToPdf.CreateDoc(new PdfInfoHeadwaiter { FileName = model.FileName, diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs index 22d1efd..560cf27 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs @@ -1,4 +1,5 @@ -using HotelContracts.BindingModels; +using HotelBusinessLogic.MailWorker; +using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.StoragesContracts; @@ -17,23 +18,31 @@ namespace HotelBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IRoomStorage _roomStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IHeadwaiterLogic _headwaiterLogic; - public RoomLogic(ILogger logger, IRoomStorage roomStorage) + public RoomLogic(ILogger logger, IRoomStorage roomStorage, IHeadwaiterLogic headwaiterLogic, AbstractMailWorker mailWorker) { _logger = logger; _roomStorage = roomStorage; + _mailWorker = mailWorker; + _headwaiterLogic = headwaiterLogic; } public bool Create(RoomBindingModel model) { CheckModel(model); model.RoomDinners = new(); - if (_roomStorage.Insert(model) == null) + var result = _roomStorage.Insert(model); + + if (result == null) { _logger.LogWarning("Insert operation failed"); return false; } + SendRoomMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Конференция №{result.Id}", $"Конференция №{result.Id} под названием {result.RoomName} и датой начала {result.RoomPrice} добавлена {result.RoomFrame}"); + return true; } @@ -43,12 +52,17 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_roomStorage.Delete(model) == null) + var result = _roomStorage.Delete(model); + + if (result == null) { _logger.LogWarning("Delete operation failed"); return false; } + SendRoomMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Конференция №{result.Id}", $"Конференция №{result.Id} под названием {result.RoomName} и датой начала {result.RoomPrice} удалена {result.RoomFrame}"); + + return true; } @@ -168,5 +182,24 @@ namespace HotelBusinessLogic.BusinessLogics _logger.LogInformation("Room. RoomName:{RoomName}.RoomFrame:{ RoomFrame}.RoomPrice:{ RoomPrice}. Id: { Id}", model.RoomName, model.RoomFrame, model.RoomPrice, model.Id); } + + private bool SendRoomMessage(int headwaiterId, string subject, string text) + { + var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId }); + + if (headwaiter == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = headwaiter.HeadwaiterEmail, + Subject = subject, + Text = text + }); + + return true; + } } } diff --git a/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs b/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs index 78385c6..5ed2669 100644 --- a/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs +++ b/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs @@ -30,7 +30,7 @@ namespace HotelBusinessLogic.MailWorker objMailMessage.Body = info.Text; objMailMessage.SubjectEncoding = Encoding.UTF8; objMailMessage.BodyEncoding = Encoding.UTF8; - Attachment attachment = new Attachment("F:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + Attachment attachment = new Attachment("E:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); objMailMessage.Attachments.Add(attachment); objSmtpClient.UseDefaultCredentials = false; diff --git a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs index 12262da..99e65e2 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs @@ -9,7 +9,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels { public class PdfInfoHeadwaiter { - public string FileName { get; set; } = string.Empty; + public string FileName { get; set; } = "E:\\ReportsCourseWork\\pdffile.pdf"; public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } diff --git a/Hotel/HotelRestApi/Controllers/ReportController.cs b/Hotel/HotelRestApi/Controllers/ReportController.cs index 9bcffd2..3699fc9 100644 --- a/Hotel/HotelRestApi/Controllers/ReportController.cs +++ b/Hotel/HotelRestApi/Controllers/ReportController.cs @@ -34,7 +34,7 @@ namespace HotelRestApi.Controllers DateFrom = model.DateFrom, DateTo = model.DateTo, OrganiserId = model.OrganiserId, - FileName = "F:\\ReportsCourseWork\\pdffile.pdf", + FileName = "E:\\ReportsCourseWork\\pdffile.pdf", }); } catch (Exception ex) @@ -121,7 +121,7 @@ namespace HotelRestApi.Controllers { _reportHeadwaiterLogic.SaveDinnersToPdfFile(new ReportHeadwaiterBindingModel { - FileName = "Отчет PDF.pdf", + FileName = "E:\\ReportsCourseWork\\pdffile.pdf", DateFrom = model.DateFrom, DateTo = model.DateTo, HeadwaiterId = model.HeadwaiterId,