diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs index 60c7ed3..bd2c6a0 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs @@ -92,6 +92,8 @@ namespace HotelBusinessLogic.BusinessLogics OrganiserId = model.OrganiserId, }); + double sum = 0; + foreach (var mealPlan in listMealPlans) { foreach (var mp in mealPlan.MealPlanMembers.Values) @@ -130,6 +132,15 @@ namespace HotelBusinessLogic.BusinessLogics public void SaveMembersToPdfFile(ReportBindingModel model) { + if (model.DateFrom == null) + { + throw new ArgumentException("Дата начала не задана"); + } + + if (model.DateTo == null) + { + throw new ArgumentException("Дата окончания не задана"); + } _saveToPdf.CreateDoc(new PdfInfoOrganiser { FileName = model.FileName, diff --git a/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs b/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs index 137c8aa..78385c6 100644 --- a/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs +++ b/Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs @@ -9,6 +9,7 @@ using System.Security.Authentication; using System.Text; using System.Threading.Tasks; using HotelContracts.BusinessLogicsContracts; +using System.Net.Mime; namespace HotelBusinessLogic.MailWorker { @@ -29,6 +30,9 @@ 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)); + objMailMessage.Attachments.Add(attachment); + objSmtpClient.UseDefaultCredentials = false; objSmtpClient.EnableSsl = true; objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; diff --git a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoOrganiser.cs b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoOrganiser.cs index c9f9ac1..b69a142 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoOrganiser.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoOrganiser.cs @@ -4,7 +4,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels { public class PdfInfoOrganiser { - public string FileName { get; set; } = string.Empty; + public string FileName { get; set; } = "F:\\ReportsCourseWork\\pdffile.pdf"; public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } diff --git a/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfOrganiser.cs b/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfOrganiser.cs index 61e94d4..996c2c4 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfOrganiser.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfOrganiser.cs @@ -91,6 +91,7 @@ namespace HotelBusinessLogic.OfficePackage.Implements { Document = _document }; + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); renderer.RenderDocument(); renderer.PdfDocument.Save(info.FileName); } diff --git a/Hotel/HotelOrganiserApp/Controllers/HomeController.cs b/Hotel/HotelOrganiserApp/Controllers/HomeController.cs index c9d1dd2..f6a2a79 100644 --- a/Hotel/HotelOrganiserApp/Controllers/HomeController.cs +++ b/Hotel/HotelOrganiserApp/Controllers/HomeController.cs @@ -5,50 +5,26 @@ using HotelOrganiserApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using System.Text; +using System.Web.Helpers; +using System.Reflection; +using HotelBusinessLogic.BusinessLogics; +using HotelContracts.BusinessLogicsContracts; namespace HotelOrganiserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportOrganiserLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportOrganiserLogic report) { _logger = logger; + _report = report; } /*--------------------Reports------------------------*/ - [HttpGet] - public IActionResult ListMembersToPdfFile() - { - if (APIClient.Organiser == null) - { - return Redirect("~/Home/Enter"); - } - - return View(); - } - - [HttpPost] - public void ListMembersToPdfFile(DateTime dateFrom, DateTime dateTo) - { - if (APIClient.Organiser == null) - { - throw new Exception("Не авторизованы"); - } - - APIClient.PostRequest("api/Report/CreateReportToPdfFile", new ReportBindingModel() - { - DateFrom = dateFrom, - DateTo = dateTo, - OrganiserId=APIClient.Organiser.Id - }); - - Response.Redirect("ListMembersToPdfFile"); - } - - [HttpGet] public IActionResult ListMemberConferenceToFile() { @@ -109,12 +85,100 @@ namespace HotelOrganiserApp.Controllers { return new PhysicalFileResult("F:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); } - + public IActionResult GetPdfFile() + { + return new PhysicalFileResult("F:\\ReportsCourseWork\\pdffile.pdf", "application/pdf"); + } public IActionResult GetExcelFile() { return new PhysicalFileResult("F:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } + [HttpGet] + public IActionResult ListMembersToPdfFile() + { + if (APIClient.Organiser == null) + { + return Redirect("~/Home/Enter"); + } + return View("ListMembersToPdfFile"); + } + + [HttpPost] + public void ListMembersToPdfFile(DateTime dateFrom, DateTime dateTo, string organiserEmail) + { + if (APIClient.Organiser == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(organiserEmail)) + { + throw new Exception("Email пуст"); + } + APIClient.PostRequest("api/report/CreateReportToPdfFile", new ReportBindingModel + { + DateFrom = dateFrom, + DateTo = dateTo, + OrganiserId = APIClient.Organiser.Id + }); + APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel + { + MailAddress = organiserEmail, + Subject = "Отчет по участникам (pdf)", + Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString() + }); + Response.Redirect("ListMembersToPdfFile"); + } + + [HttpGet] + public string GetMembersReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Organiser == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + result = _report.GetMembers(new ReportBindingModel + { + OrganiserId = APIClient.Organiser.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + foreach (var report in result) + { + table += $"

{report.MemberFIO}

"; + table += $""; + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + table += "
КонференцияДата начала конференцииПлан питанияСтоимость плана питания
{report.ConferenceName}{report.StartDate}{report.MealPlanName}{report.MealPlanPrice}
"; + } + //table += $"

Итого: {result.Item2}

"; + return table; + } + /*--------------------MealPlans------------------------*/ [HttpGet] diff --git a/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj b/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj index 4781cac..2b54395 100644 --- a/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj +++ b/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -19,12 +19,15 @@ + + + diff --git a/Hotel/HotelOrganiserApp/Models/ErrorViewModel.cs b/Hotel/HotelOrganiserApp/Models/ErrorViewModel.cs index fd49647..4c98915 100644 --- a/Hotel/HotelOrganiserApp/Models/ErrorViewModel.cs +++ b/Hotel/HotelOrganiserApp/Models/ErrorViewModel.cs @@ -3,7 +3,6 @@ namespace HotelOrganiserApp.Models public class ErrorViewModel { public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } } \ No newline at end of file diff --git a/Hotel/HotelOrganiserApp/Program.cs b/Hotel/HotelOrganiserApp/Program.cs index d0ac9bb..8e45332 100644 --- a/Hotel/HotelOrganiserApp/Program.cs +++ b/Hotel/HotelOrganiserApp/Program.cs @@ -1,6 +1,20 @@ +using DocumentFormat.OpenXml.VariantTypes; +using HotelBusinessLogic.BusinessLogics; +using HotelBusinessLogic.OfficePackage; +using HotelBusinessLogic.OfficePackage.Implements; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.StoragesContracts; +using HotelDataBaseImplement.Implemets; using HotelOrganiserApp; 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 +23,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/HotelOrganiserApp/Views/Home/ListMembersToPdfFile.cshtml b/Hotel/HotelOrganiserApp/Views/Home/ListMembersToPdfFile.cshtml index 875e97c..6be9f34 100644 --- a/Hotel/HotelOrganiserApp/Views/Home/ListMembersToPdfFile.cshtml +++ b/Hotel/HotelOrganiserApp/Views/Home/ListMembersToPdfFile.cshtml @@ -1,38 +1,60 @@ -@{ - ViewData["Title"] = "ListMembersToPdf"; +@using HotelContracts.ViewModels + +@{ + ViewData["Title"] = "ListMembersToPdfFile"; } - - - - -
-

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

+

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

-
-
- - -
- -
-
-
-
-
\ No newline at end of file +
+ @{ +
+
+
+ + +
+
+ + +
+
+
+ Ваш email + + +
+
+
+
+ + } +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/Hotel/HotelRestApi/Controllers/ReportController.cs b/Hotel/HotelRestApi/Controllers/ReportController.cs index e25ef12..619f2ea 100644 --- a/Hotel/HotelRestApi/Controllers/ReportController.cs +++ b/Hotel/HotelRestApi/Controllers/ReportController.cs @@ -2,6 +2,9 @@ using HotelContracts.BusinessLogicsContracts; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using DocumentFormat.OpenXml.Presentation; +using DocumentFormat.OpenXml.Spreadsheet; +using HotelBusinessLogic.MailWorker; namespace HotelRestApi.Controllers { @@ -12,11 +15,13 @@ namespace HotelRestApi.Controllers private readonly ILogger _logger; private readonly IReportOrganiserLogic _reportOrganiserLogic; private readonly IReportHeadwaiterLogic _reportHeadwaiterLogic; - public ReportController(ILogger logger, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic) + private readonly AbstractMailWorker _mailWorker; + public ReportController(ILogger logger, AbstractMailWorker mailWorker, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic) { _logger = logger; _reportOrganiserLogic = reportOrganiserLogic; _reportHeadwaiterLogic = reportHeadwaiterLogic; + _mailWorker = mailWorker; } [HttpPost] @@ -26,10 +31,10 @@ namespace HotelRestApi.Controllers { _reportOrganiserLogic.SaveMembersToPdfFile(new ReportBindingModel { - FileName="Отчет PDF.pdf", DateFrom = model.DateFrom, DateTo = model.DateTo, - OrganiserId=model.OrganiserId, + OrganiserId = model.OrganiserId, + FileName = "F:\\ReportsCourseWork\\pdffile.pdf", }); } catch (Exception ex) @@ -39,6 +44,20 @@ namespace HotelRestApi.Controllers } } + [HttpPost] + public void SendPdfToMail(MailSendInfoBindingModel model) + { + try + { + _mailWorker.MailSendAsync(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отправки письма"); + throw; + } + } + [HttpPost] public void CreateReportToWordFile(ReportBindingModel model) {