From 9581aaa847f2d8164bbf1430135bed01396d8fae Mon Sep 17 00:00:00 2001 From: bocchanskyy Date: Tue, 24 Dec 2024 17:10:55 +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 --- .../MailWorker/AbstractMailWorker.cs | 14 +++++---- .../MailWorker/MailKitWorker.cs | 15 ++++++---- .../OfficePackage/AbstractSaveToPdf.cs | 14 +++------ .../OfficePackage/Implements/SaveToPdf.cs | 1 + .../Implements/ServiceStorage.cs | 30 +++++++++++++++---- .../BeautyStudioRestAPI.csproj | 1 + BeautyStudio/BeautyStudioRestAPI/Program.cs | 10 +++++-- .../StoreKeeperWebApp/StoreKeeperData.cs | 4 +-- .../StoreKeeperWebApp/appsettings.json | 3 +- 9 files changed, 61 insertions(+), 31 deletions(-) diff --git a/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/AbstractMailWorker.cs b/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/AbstractMailWorker.cs index 97e4b8d..a8ba829 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -12,13 +12,11 @@ namespace BeautyStudioBusinessLogic.MailWorker protected int _smtpClientPort; protected string _popHost = string.Empty; protected int _popPort; - private readonly IStoreKeeperLogic _executorLogic; private readonly ILogger _logger; - public AbstractMailWorker(ILogger logger, IStoreKeeperLogic executorLogic) + public AbstractMailWorker(ILogger logger) { _logger = logger; - _executorLogic = executorLogic; } public void MailConfig(MailConfigBindingModel config) @@ -44,12 +42,18 @@ namespace BeautyStudioBusinessLogic.MailWorker return; } - if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + if (string.IsNullOrEmpty(info.MailAddress)) { return; } + if (string.IsNullOrEmpty(info.Subject)) { + return; - _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + } + //if (string.IsNullOrEmpty(info.Text)) { + // return; + //} + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); await SendMailAsync(info); } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/MailKitWorker.cs b/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/MailKitWorker.cs index e181061..fb3556c 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/MailKitWorker.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/MailWorker/MailKitWorker.cs @@ -11,7 +11,7 @@ namespace BeautyStudioBusinessLogic.MailWorker { public class MailKitWorker : AbstractMailWorker { - public MailKitWorker(ILogger logger, IStoreKeeperLogic _storekeeperLogic) : base(logger, _storekeeperLogic) { } + public MailKitWorker(ILogger logger) : base(logger) { } protected override async Task SendMailAsync(MailSendInfoBindingModel info) { @@ -23,12 +23,17 @@ namespace BeautyStudioBusinessLogic.MailWorker objMailMessage.From = new MailAddress(_mailLogin); objMailMessage.To.Add(new MailAddress(info.MailAddress)); objMailMessage.Subject = info.Subject; - objMailMessage.Body = info.Text; objMailMessage.SubjectEncoding = Encoding.UTF8; objMailMessage.BodyEncoding = Encoding.UTF8; - Attachment attachment = new Attachment("C:\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); - objMailMessage.Attachments.Add(attachment); - + if (info.Text != null) + { + objMailMessage.Body = info.Text; + } + if (info.Pdf != null) + { + var attachment = new Attachment(new MemoryStream(info.Pdf), info.FileName); + objMailMessage.Attachments.Add(attachment); + } objSmtpClient.UseDefaultCredentials = false; objSmtpClient.EnableSsl = true; objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index a8cecb3..a571e96 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -24,7 +24,8 @@ namespace BeautyStudioBusinessLogic.OfficePackage CreateParagraph(new PdfParagraph { Text = info.Title, - Style = "NormalTitle" + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center }); // Период выборки данных @@ -32,20 +33,13 @@ namespace BeautyStudioBusinessLogic.OfficePackage CreateParagraph(new PdfParagraph { Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", - Style = "Normal" + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center }); // Создаем таблицу с двумя колонками CreateTable(new List { "5cm", "10cm" }); - // Создаем заголовок таблицы - CreateRow(new PdfRowParameters - { - Texts = new List { "Услуга", "Процедуры", "Косметика" }, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - // Записываем основную информацию foreach (var report in info.Services) { diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 978c327..39beb4f 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BeautyStudioBusinessLogic.OfficePackage; +using System.Runtime.CompilerServices; namespace BeautyStudioBusinessLogic.OfficePackage.Implements { diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs index fa4e1e6..009e8a8 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs @@ -27,11 +27,31 @@ namespace BeautyStudioDatabaseImplement.Implements return new(); } using var context = new BeautyStudioDatabase(); - if (model.DateCreate.HasValue) - return context.Services.Where(x => x.StoreKeeperId == model.StoreKeeperId).Where(x => x.DateCreate <= model.DateComplete && x.DateCreate >= model.DateCreate).Select(x => x.GetViewModel).ToList(); - else - return context.Services.Where(x => x.StoreKeeperId == model.StoreKeeperId).Select(x => x.GetViewModel).ToList(); - } + + DateTime? dateCreateUtc = model.DateCreate.HasValue + ? DateTime.SpecifyKind(model.DateCreate.Value, DateTimeKind.Utc) + : null; + + DateTime? dateCompleteUtc = model.DateComplete.HasValue + ? DateTime.SpecifyKind(model.DateComplete.Value, DateTimeKind.Utc) + : null; + + if (model.DateCreate.HasValue) + { + return context.Services + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Where(x => x.DateCreate <= dateCompleteUtc && x.DateCreate >= dateCreateUtc) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return context.Services + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Select(x => x.GetViewModel) + .ToList(); + } + } public ServiceViewModel? GetElement(ServiceSearchModel model) { using var context = new BeautyStudioDatabase(); diff --git a/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj b/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj index 1097767..8369ce9 100644 --- a/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj +++ b/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj @@ -18,6 +18,7 @@ + diff --git a/BeautyStudio/BeautyStudioRestAPI/Program.cs b/BeautyStudio/BeautyStudioRestAPI/Program.cs index 4995f69..3d90ed9 100644 --- a/BeautyStudio/BeautyStudioRestAPI/Program.cs +++ b/BeautyStudio/BeautyStudioRestAPI/Program.cs @@ -7,6 +7,7 @@ using BeautyStudioBusinessLogic.OfficePackage; using BeautyStudioBusinessLogic.OfficePackage.Implements; using System.Reflection.PortableExecutable; using BeautyStudioBusinessLogic.MailWorker; +using StoreKeeperWebApp; var builder = WebApplication.CreateBuilder(args); @@ -32,8 +33,6 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); - builder.Services.AddControllers(); @@ -49,7 +48,12 @@ mailSender?.MailConfig(new MailConfigBindingModel PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) }); // Configure the HTTP request pipeline. - +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.UseAuthorization(); app.MapControllers(); diff --git a/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs b/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs index 4d9b101..2a62578 100644 --- a/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs +++ b/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs @@ -286,8 +286,8 @@ namespace StoreKeeperWebApp DateTo = endDate!.Value, FileName = stream, Services = reports, - Title = "Отчет" - }); + Title = "Отчет", + }); ; byte[] report = stream.GetBuffer(); _mail.MailSendAsync(new() { MailAddress = UserStoreKeeper.user!.StoreKeeperEmail, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report }); } diff --git a/BeautyStudio/StoreKeeperWebApp/appsettings.json b/BeautyStudio/StoreKeeperWebApp/appsettings.json index 7666d6d..e075eb2 100644 --- a/BeautyStudio/StoreKeeperWebApp/appsettings.json +++ b/BeautyStudio/StoreKeeperWebApp/appsettings.json @@ -11,5 +11,6 @@ "PopHost": "pop.gmail.com", "PopPort": "995", "MailLogin": "rpplabs724@gmail.com", - "MailPassword": "tlta buqp gljg jiso" + "MailPassword": "idsj gftu cgnr fflz", + "EnableSSl": "true" }