diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/ManagerLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/ManagerLogic.cs index 7d484ee..79b601a 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/ManagerLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/ManagerLogic.cs @@ -1,4 +1,5 @@ -using CanteenContracts.BindingModels; +using CanteenBusinessLogic.MailWorker; +using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.StoragesContracts; @@ -16,11 +17,13 @@ namespace CanteenBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IManagerStorage _managerStorage; + private readonly AbstractMailWorker _mailWorker; - public ManagerLogic(ILogger logger, IManagerStorage managerStorage) + public ManagerLogic(ILogger logger, IManagerStorage managerStorage, AbstractMailWorker mailWorker) { _logger = logger; _managerStorage = managerStorage; + _mailWorker = mailWorker; } public bool Create(ManagerBindingModel model) @@ -85,6 +88,18 @@ namespace CanteenBusinessLogic.BusinessLogics return list; } + public bool SendMail(MailSendInfoBindingModel emailInfo) + { + _mailWorker.MailSendAsync(new() + { + MailAddress = emailInfo.MailAddress, + Subject = emailInfo.Subject, + Path = emailInfo.Path, + }); + + return true; + } + public bool Update(ManagerBindingModel model) { CheckModel(model); @@ -137,5 +152,6 @@ namespace CanteenBusinessLogic.BusinessLogics throw new InvalidOperationException("Такой менеджер уже есть"); } } + } } diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs index 9120ded..0cf8bfe 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs @@ -7,6 +7,9 @@ using CanteenContracts.StoragesContracts; using CanteenContracts.View; using CanteenContracts.ViewModels; using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing.Charts; +using DocumentFormat.OpenXml.Presentation; +using DocumentFormat.OpenXml.Wordprocessing; using System.Linq; namespace CanteenBusinessLogic.BusinessLogics @@ -79,29 +82,57 @@ namespace CanteenBusinessLogic.BusinessLogics return list; } - - - public void saveLunchesToPdfFile(ReportBindingModel model) + public List GetCooksPCView(ReportBindingModel model) { - saveToPdf.CreateDoc(new PdfInfo + var list = new List(); + + var cooks = cookStorage.GetFilteredList(new CookSearchModel { - FileName = model.FileName, - Title = "Список заказов", - DateAfter = model.DateAfter.Value, - DateBefore = model.DateBefore.Value, - Lunches = GetLunchesPCView(model) + ManagerId = model.UserId }); + + var lunches = lunchStorage.GetFilteredList(new LunchSearchModel + { + DateFrom = model.DateBefore, + DateTo = model.DateAfter, + }); + + foreach (var cook in cooks) + { + var record = new ReportCooksPCView + { + CookId = cook.Id, + FIO = cook.FIO, + Lunches = new List() + }; + + foreach (var lunch in lunches) + { + foreach(var order in lunch.LunchOrders) + { + var findOrder = orderStorage.GetElement(new OrderSearchModel { Id = order.Key }); + if (findOrder.OrderCooks.ContainsKey(cook.Id)) + { + record.Lunches.Add(lunch); + break; + } + } + } + + list.Add(record); + } + + return list; } - public List GetCooksByLanches(ReportBindingModel model) + public List GetCooksByLunches(ReportBindingModel model) { var list = new List(); var lunches = lunchStorage.GetFilteredList(new LunchSearchModel { - DateFrom = (DateTime)model.DateAfter, - DateTo = model.DateBefore, VisitorId = model.UserId - }); + }).Where(x => model.LunchId.Contains(x.Id)).ToList(); + foreach (var lunch in lunches) { @@ -130,7 +161,6 @@ namespace CanteenBusinessLogic.BusinessLogics } return list; } - private List GetOrdersByProducts(ReportBindingModel model) { var list = new List(); @@ -138,7 +168,7 @@ namespace CanteenBusinessLogic.BusinessLogics var products = productStorage.GetFilteredList(new ProductSearchModel { ManagerId = model.UserId - }); + }).Where(x => model.ProductId.Contains(x.Id)); foreach (var product in products) { @@ -160,38 +190,55 @@ namespace CanteenBusinessLogic.BusinessLogics } return list; } + public void saveLunchesToPdfFile(ReportBindingModel model) + { + saveToPdf.CreateLunchDoc(new PdfInfo + { + Title = "Список обедов", + DateAfter = model.DateAfter.Value, + DateBefore = model.DateBefore.Value, + Lunches = GetLunchesPCView(model) + }); + } + public void saveCooksToPdfFile(ReportBindingModel model) + { + saveToPdf.CreateCookDoc(new PdfInfo + { + Title = "Список поваров", + DateAfter = model.DateAfter.Value, + DateBefore = model.DateBefore.Value, + FileName = (model.FileName != null) ? model.FileName : $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.pdf", + Cooks = GetCooksPCView(model) + }); + } public void saveCooksToExcel(ReportBindingModel model) { saveToExcel.CreateCooksReport(new ExcelInfo() { - FileName = model.FileName, Title = "Список поваров:", - Cooks = GetCooksByLanches(model) - }); - } - public void saveCooksToWord(ReportBindingModel model) - { - saveToWord.CreateCooksDoc(new WordInfo() - { - FileName = model.FileName, - Title = "Список поваров", - Cooks = GetCooksByLanches(model) + Cooks = GetCooksByLunches(model) }); } public void saveOrdersToExcel(ReportBindingModel model) { saveToExcel.CreateOrdersReport(new ExcelInfo() { - FileName = model.FileName, Title = "Список заказов:", Orders = GetOrdersByProducts(model) }); } + public void saveCooksToWord(ReportBindingModel model) + { + saveToWord.CreateCooksDoc(new WordInfo() + { + Title = "Список поваров", + Cooks = GetCooksByLunches(model) + }); + } public void saveOrdersToWord(ReportBindingModel model) { saveToWord.CreateOrdersDoc(new WordInfo() { - FileName = model.FileName, Title = "Список заказов", Orders = GetOrdersByProducts(model) }); diff --git a/Canteen/CanteenBusinessLogic/CanteenBusinessLogic.csproj b/Canteen/CanteenBusinessLogic/CanteenBusinessLogic.csproj index c48e2ea..a7884b7 100644 --- a/Canteen/CanteenBusinessLogic/CanteenBusinessLogic.csproj +++ b/Canteen/CanteenBusinessLogic/CanteenBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -9,6 +9,7 @@ + diff --git a/Canteen/CanteenBusinessLogic/MailWorker/AbstractMailWorker.cs b/Canteen/CanteenBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..4eeb391 --- /dev/null +++ b/Canteen/CanteenBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,58 @@ +using CanteenContracts.BindingModels; +using CanteenContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CanteenBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + protected string _mailPassword = string.Empty; + protected string _smtpClientHost = string.Empty; + protected int _smtpClientPort; + protected string _popHost = string.Empty; + protected int _popPort; + + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger) + { + _logger = logger; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + + _logger.LogDebug("Config: {login}, {password}, {clientHost},{ clientPOrt}, { popHost}, { popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Path)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + + await SendMailAsync(info); + } + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + } +} diff --git a/Canteen/CanteenBusinessLogic/MailWorker/MailKitWorker.cs b/Canteen/CanteenBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..7ce7d52 --- /dev/null +++ b/Canteen/CanteenBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,42 @@ +using CanteenContracts.BindingModels; +using CanteenContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System.Net.Mail; +using System.Net; +using System.Text; + +namespace CanteenBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger) : base(logger) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Attachments.Add(new Attachment(info.Path)); + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index d6d6ad4..de7adda 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -100,7 +100,7 @@ namespace CanteenBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = rowIndex, - Text = $"Продукт: {orderView.Product.ProductName}, {orderView.Product.Price}", + Text = $"Продукт: Id: {orderView.Product.Id}. {orderView.Product.ProductName}, {orderView.Product.Price}", StyleInfo = ExcelStyleInfoType.TextWithBroder }); MergeCells(new ExcelMergeParameters diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 8b74997..40dff6c 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -5,12 +5,13 @@ using System.Text; using System.Threading.Tasks; using CanteenBusinessLogic.OfficePackage.HelperEnums; using CanteenBusinessLogic.OfficePackage.HelperModels; +using CanteenContracts.ViewModels; namespace CanteenBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { - public void CreateDoc(PdfInfo info) + public void CreateLunchDoc(PdfInfo info) { CreatePdf(info); CreateParagraph(new PdfParagraph @@ -62,6 +63,47 @@ namespace CanteenBusinessLogic.OfficePackage } SavePdf(info); } + public void CreateCookDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle" + }); + CreateParagraph(new PdfParagraph + { + Text = $"с {info.DateAfter.ToShortDateString()} по {info.DateBefore.ToShortDateString()}", + Style = "Normal" + }); + CreateTable(new List { "2cm", "3cm", "2cm", "2cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Id повара", "ФИО повара", "Id обеда", "Дата начала обеда", "Дата окончания обеда" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var cook in info.Cooks) + { + CreateRow(new PdfRowParameters + { + Texts = new List { cook.CookId.ToString(), cook.FIO.ToString(), "", "", "" }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + + foreach (var lunch in cook.Lunches) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", lunch.Id.ToString(), lunch.DateCreate.ToShortDateString(), lunch.DateImplement?.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + SavePdf(info); + } protected abstract void CreatePdf(PdfInfo info); protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateTable(List columns); diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs index dcdd8fc..9089ee6 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using CanteenBusinessLogic.OfficePackage.HelperEnums; using CanteenBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.EMMA; namespace CanteenBusinessLogic.OfficePackage { @@ -73,14 +74,72 @@ namespace CanteenBusinessLogic.OfficePackage SaveWord(info); } + public void CreateOrdersDoc(WordInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var reportOrderView in info.Orders) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Продукт: ", new WordTextProperties { Bold = true, Size = "24" }), + (reportOrderView.Product.Id.ToString(), new WordTextProperties { Bold = false, Size = "24" }), + ("Название: ", new WordTextProperties { Bold = true, Size = "24" }), + (reportOrderView.Product.ProductName.ToString(), new WordTextProperties { Bold = false, Size = "24" }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Заказы: ", new WordTextProperties { Bold = true, Size = "24" }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + foreach (var order in reportOrderView.Orders) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Заказ: ", new WordTextProperties { Bold = false, Size = "24" }), + (order.Id.ToString(), new WordTextProperties { Bold = false, Size = "24" }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + } + + SaveWord(info); + } protected abstract void CreateWord(WordInfo info); protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void SaveWord(WordInfo info); - - internal void CreateOrdersDoc(WordInfo wordInfo) - { - throw new NotImplementedException(); - } } } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 0d43e45..e8985bf 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -10,7 +10,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels { public class ExcelInfo { - public string FileName { get; set; } + public string FileName = $"C:\\XlsxReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.xlsx"; public string Title { get; set; } public List Cooks { get; set; } public List Orders { get; set; } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index c224714..08c84ad 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -9,11 +9,11 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels { public class PdfInfo { - public string FileName { get; set; } - public string FilePath = "C:\\Reports"; + public string FileName = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.pdf"; public string Title { get; set; } public DateTime DateAfter { get; set; } public DateTime DateBefore { get; set; } public List Lunches { get; set; } + public List Cooks { get; set; } } } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 67a6189..2d8e8d7 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -10,7 +10,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels { public class WordInfo { - public string FileName { get; set; } + public string FileName = $"C:\\WordReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.docx"; public string Title { get; set; } public List Cooks { get; set; } public List Orders { get; set; } diff --git a/Canteen/CanteenContracts/BindingModels/MailConfigBindingModel.cs b/Canteen/CanteenContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..9344b97 --- /dev/null +++ b/Canteen/CanteenContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,12 @@ +namespace CanteenContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + public string PopHost { get; set; } = string.Empty; + public int PopPort { get; set; } + } +} diff --git a/Canteen/CanteenContracts/BindingModels/MailSendInfoBindingModel.cs b/Canteen/CanteenContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..f635711 --- /dev/null +++ b/Canteen/CanteenContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,11 @@ +namespace CanteenContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + public string Path { get; set; } = string.Empty; + public ReportBindingModel report { get; set; } + } +} diff --git a/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs b/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs index 6470568..68b6f5d 100644 --- a/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs @@ -9,11 +9,11 @@ namespace CanteenContracts.BindingModels { public class ReportBindingModel { - public string FileName { get; set; } + public string? FileName { get; set; } public DateTime? DateAfter { get; set; } public DateTime? DateBefore { get; set; } - public List? lunches { get; set; } - public List? orders { get; set; } public int UserId { get; set; } + public List? LunchId { get; set; } + public List? ProductId { get; set; } } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs index a02f158..bb88487 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs @@ -20,5 +20,6 @@ namespace CanteenContracts.BusinessLogicsContracts bool Finish(LunchBindingModel model); bool UpdateOrders(LunchBindingModel lunch, OrderBindingModel order); bool UpdateProducts(LunchBindingModel lunch, ProductBindingModel product, int count); + } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IManagerLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IManagerLogic.cs index fa64bcc..8d00adf 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IManagerLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IManagerLogic.cs @@ -15,5 +15,6 @@ namespace CanteenContracts.BusinessLogicsContracts ManagerViewModel? ReadElement(ManagerSearchModel model); bool Create(ManagerBindingModel model); bool Update(ManagerBindingModel model); + bool SendMail(MailSendInfoBindingModel emailInfo); } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs index a596289..e1cbac4 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs @@ -11,9 +11,10 @@ namespace CanteenContracts.BusinessLogicsContracts { public interface IReportLogic { - public List GetCooksByLanches(ReportBindingModel model); + public List GetCooksByLunches(ReportBindingModel model); List GetLunchesPCView(ReportBindingModel model); void saveLunchesToPdfFile(ReportBindingModel model); + void saveCooksToPdfFile(ReportBindingModel model); void saveCooksToWord(ReportBindingModel model); void saveCooksToExcel(ReportBindingModel model); public void saveOrdersToExcel(ReportBindingModel model); diff --git a/Canteen/CanteenContracts/ViewModels/ReportCooksPCView.cs b/Canteen/CanteenContracts/ViewModels/ReportCooksPCView.cs new file mode 100644 index 0000000..02b284f --- /dev/null +++ b/Canteen/CanteenContracts/ViewModels/ReportCooksPCView.cs @@ -0,0 +1,16 @@ +using CanteenContracts.View; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.ViewModels +{ + public class ReportCooksPCView + { + public int CookId{ get; set; } + public string FIO { get; set; } + public List Lunches { get; set; } + } +} diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index fc050a6..7ef45cc 100644 --- a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs +++ b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs @@ -11,7 +11,7 @@ namespace CanteenDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-23CS6SP\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=MOVAVI-DESKTOP\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs index 089c094..dadd23d 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs @@ -34,7 +34,7 @@ namespace CanteenDatabaseImplement.Implements public List GetFilteredList(CookSearchModel model) { - if (!model.Id.HasValue && !model.OrderId.HasValue) + if (!model.Id.HasValue && !model.OrderId.HasValue && !model.ManagerId.HasValue) { return new(); } diff --git a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs index a244d82..0957548 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs @@ -46,7 +46,7 @@ namespace CanteenDatabaseImplement.Implements } public List GetFilteredList(LunchSearchModel model) { - if (!model.VisitorId.HasValue) + if (!model.VisitorId.HasValue & !model.DateFrom.HasValue & !model.DateTo.HasValue) { return new(); } diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index b8826fe..4dead79 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -477,13 +477,14 @@ namespace CanteenManagerApp.Controllers [HttpGet] public IActionResult Report() { + ViewBag.ProductList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); return View(new ReportBindingModel()); } [HttpPost] public void ReportPdf(ReportBindingModel model) { model.UserId = APIClient.Manager.Id; - APIClient.PostRequest("api/main/SaveLunchesToPDF", model); + APIClient.PostRequest("api/main/SaveOrdersToPDF", model); Response.Redirect("Index"); } @@ -491,7 +492,7 @@ namespace CanteenManagerApp.Controllers public void ReportXsl(ReportBindingModel model) { model.UserId = APIClient.Manager.Id; - APIClient.PostRequest("api/main/SaveOrdersToXSL", model); + APIClient.PostRequest("api/main/SavevToXSL", model); Response.Redirect("Index"); } @@ -506,8 +507,19 @@ namespace CanteenManagerApp.Controllers [HttpPost] public void ReportEmail(ReportBindingModel model) { - APIClient.PostRequest("api/main/SaveEMAIL", model); - Response.Redirect("Index"); + if (APIClient.Manager == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + model.UserId = APIClient.Manager.Id; + APIClient.PostRequest($"api/manager/SendEmail", new MailSendInfoBindingModel + { + MailAddress = APIClient.Manager.Login, + Subject = "Отчет", + report = model + }); + + Response.Redirect("Report"); } } } \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Report.cshtml b/Canteen/CanteenManagerApp/Views/Home/Report.cshtml index f34fc8b..0cc91a2 100644 --- a/Canteen/CanteenManagerApp/Views/Home/Report.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/Report.cshtml @@ -5,27 +5,38 @@ ViewBag.Title = "Report"; } -

Generate Report

+

Отчеты

@using (Html.BeginForm("Report", "Home", FormMethod.Post)) { -
- @Html.LabelFor(m => m.FileName) - @Html.TextBoxFor(m => m.FileName) +
+

Pdf

+
+
+ @Html.LabelFor(m => m.DateBefore, "От") + @Html.TextBoxFor(m => m.DateBefore, new { type = "date", @class = "form-control" }) +
+
+ +
+
+ @Html.LabelFor(m => m.DateAfter, "До") + @Html.TextBoxFor(m => m.DateAfter, new { type = "date", @class = "form-control" }) +
+
+
+
+ +
-
- @Html.LabelFor(m => m.DateAfter) - @Html.TextBoxFor(m => m.DateAfter, new { type = "date" }) +
+

Word, Excel

+
+ @Html.LabelFor(m => m.ProductId, "Выбранные продукты") + @Html.DropDownListFor(m => m.ProductId, new SelectList(ViewBag.ProductList, "Id", "ProductName"), new { @class = "form-control", multiple = "multiple" }) +
+ +
- -
- @Html.LabelFor(m => m.DateBefore) - @Html.TextBoxFor(m => m.DateBefore, new { type = "date" }) -
- - - - - } \ No newline at end of file diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index 0b520ba..4b6ee1a 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -45,9 +45,25 @@ namespace CanteenRestApi.Controllers { DateAfter = model.DateAfter, DateBefore = model.DateBefore, - FileName = model.FileName, - UserId = model.UserId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId}), + UserId = model.UserId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } + [HttpPost] + public void SaveOrdersToPDF(ReportBindingModel model) + { + try + { + _reportLogic.saveCooksToPdfFile(new ReportBindingModel() + { + DateAfter = model.DateAfter, + DateBefore = model.DateBefore, + UserId = model.UserId }); } catch (Exception ex) @@ -62,16 +78,12 @@ namespace CanteenRestApi.Controllers { try { - var excelFileName = $"{model.FileName}.xlsx"; - var excelFilePath = excelFileName; - _reportLogic.saveCooksToExcel(new ReportBindingModel() { DateAfter = model.DateAfter, DateBefore = model.DateBefore, - FileName = excelFilePath, UserId = model.UserId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }), + LunchId = model.LunchId }); } catch (Exception ex) @@ -90,9 +102,8 @@ namespace CanteenRestApi.Controllers { DateAfter = model.DateAfter, DateBefore = model.DateBefore, - FileName = model.FileName, UserId = model.UserId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }), + LunchId = model.LunchId }); } catch (Exception ex) @@ -109,9 +120,8 @@ namespace CanteenRestApi.Controllers { _reportLogic.saveOrdersToExcel(new ReportBindingModel() { - FileName = $"{model.FileName}.xlsx", UserId = model.UserId, - orders = _order.ReadList(new OrderSearchModel { VisitorId = model.UserId }), + ProductId = model.ProductId }); } @@ -123,15 +133,14 @@ namespace CanteenRestApi.Controllers } [HttpPost] - public void SaveOrderToWORD(ReportBindingModel model) + public void SaveOrdersToWORD(ReportBindingModel model) { try { _reportLogic.saveOrdersToWord(new ReportBindingModel() { - FileName = $"{model.FileName}.docx", UserId = model.UserId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }), + ProductId = model.ProductId }); } catch (Exception ex) @@ -583,6 +592,19 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpPost] + public void LunchComplete(LunchBindingModel model) + { + try + { + _lunch.Finish(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } [HttpGet] public List? GetLunchList(int visitorId) { diff --git a/Canteen/CanteenRestApi/Controllers/ManagerController.cs b/Canteen/CanteenRestApi/Controllers/ManagerController.cs index fb8e238..e38866d 100644 --- a/Canteen/CanteenRestApi/Controllers/ManagerController.cs +++ b/Canteen/CanteenRestApi/Controllers/ManagerController.cs @@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.View; using Microsoft.AspNetCore.Mvc; +using System.IO.Pipes; namespace CanteenRestApi.Controllers { @@ -12,11 +13,13 @@ namespace CanteenRestApi.Controllers { private readonly ILogger _logger; private readonly IManagerLogic _logic; + private readonly IReportLogic _report; - public ManagerController(IManagerLogic logic, ILogger logger) + public ManagerController(IManagerLogic logic, IReportLogic report, ILogger logger) { _logger = logger; _logic = logic; + _report = report; } [HttpGet] @@ -64,5 +67,27 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpPost] + public void SendEmail(MailSendInfoBindingModel emailInfo) + { + try + { + string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}111111.pdf"; + _report.saveCooksToPdfFile(new ReportBindingModel + { + FileName = path, + UserId = emailInfo.report.UserId, + DateBefore = emailInfo.report.DateBefore, + DateAfter = emailInfo.report.DateAfter + }); + emailInfo.Path = path; + _logic.SendMail(emailInfo); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during updating"); + throw; + } + } } } diff --git a/Canteen/CanteenRestApi/Cook.docx b/Canteen/CanteenRestApi/Cook.docx deleted file mode 100644 index 09b976c..0000000 Binary files a/Canteen/CanteenRestApi/Cook.docx and /dev/null differ diff --git a/Canteen/CanteenRestApi/Cook.docx.xlsx.xls b/Canteen/CanteenRestApi/Cook.docx.xlsx.xls deleted file mode 100644 index dd56d27..0000000 Binary files a/Canteen/CanteenRestApi/Cook.docx.xlsx.xls and /dev/null differ diff --git a/Canteen/CanteenRestApi/Cook.xlsx b/Canteen/CanteenRestApi/Cook.xlsx deleted file mode 100644 index 1f8d8d7..0000000 Binary files a/Canteen/CanteenRestApi/Cook.xlsx and /dev/null differ diff --git a/Canteen/CanteenRestApi/Order.xlsx b/Canteen/CanteenRestApi/Order.xlsx deleted file mode 100644 index c0267c0..0000000 Binary files a/Canteen/CanteenRestApi/Order.xlsx and /dev/null differ diff --git a/Canteen/CanteenRestApi/Program.cs b/Canteen/CanteenRestApi/Program.cs index bd24e7d..12b4364 100644 --- a/Canteen/CanteenRestApi/Program.cs +++ b/Canteen/CanteenRestApi/Program.cs @@ -1,7 +1,9 @@ using CanteenBusinessLogic.BusinessLogics; +using CanteenBusinessLogic.MailWorker; using CanteenBusinessLogic.OfficePackage; using CanteenBusinessLogic.OfficePackage.Implements; +using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.StoragesContracts; using CanteenDatabaseImplement.Implements; @@ -34,6 +36,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -49,6 +52,17 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/Canteen/CanteenRestApi/Report.docx b/Canteen/CanteenRestApi/Report.docx deleted file mode 100644 index 080143c..0000000 Binary files a/Canteen/CanteenRestApi/Report.docx and /dev/null differ diff --git a/Canteen/CanteenRestApi/Report.xlsx b/Canteen/CanteenRestApi/Report.xlsx index 8c0fa1a..4b0b0c0 100644 Binary files a/Canteen/CanteenRestApi/Report.xlsx and b/Canteen/CanteenRestApi/Report.xlsx differ diff --git a/Canteen/CanteenRestApi/appsettings.json b/Canteen/CanteenRestApi/appsettings.json index 10f68b8..d4cf540 100644 --- a/Canteen/CanteenRestApi/appsettings.json +++ b/Canteen/CanteenRestApi/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "test.email.movavi@gmail.com", + "MailPassword": "rmss tjbo ykkz swac" } diff --git a/Canteen/CanteenRestApi/eport b/Canteen/CanteenRestApi/eport deleted file mode 100644 index 478bc42..0000000 Binary files a/Canteen/CanteenRestApi/eport and /dev/null differ diff --git a/Canteen/CanteenRestApi/pdfReport.pdf b/Canteen/CanteenRestApi/pdfReport.pdf deleted file mode 100644 index 01aa0b7..0000000 Binary files a/Canteen/CanteenRestApi/pdfReport.pdf and /dev/null differ diff --git a/Canteen/CanteenRestApi/report b/Canteen/CanteenRestApi/report deleted file mode 100644 index eea019a..0000000 Binary files a/Canteen/CanteenRestApi/report and /dev/null differ diff --git a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs index 0ec1cf3..97c6905 100644 --- a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs +++ b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs @@ -227,6 +227,34 @@ namespace CanteenVisitorApp.Controllers Response.Redirect("Orders"); } [HttpGet] + public IActionResult LunchComplete() + { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Lunches = APIClient.GetRequest>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}"); + return View(); + } + [HttpPost] + public void LunchComplete(int id) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + if (id <= 0) + { + throw new Exception("Выберите обед"); + } + APIClient.PostRequest("api/main/LunchComplete", new LunchBindingModel + { + Id = id + }); + + Response.Redirect("Lunches"); + } + [HttpGet] public IActionResult UpdateOrder() { if (APIClient.Visitor == null) @@ -372,7 +400,7 @@ namespace CanteenVisitorApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Lunches = APIClient.GetRequest>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}"); + ViewBag.Lunches = APIClient.GetRequest>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}"); return View(); } [HttpPost] @@ -400,7 +428,7 @@ namespace CanteenVisitorApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Lunches = APIClient.GetRequest>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}"); + ViewBag.Lunches = APIClient.GetRequest>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}"); return View(); } [HttpPost] diff --git a/Canteen/CanteenVisitorApp/Views/Home/LunchComplete.cshtml b/Canteen/CanteenVisitorApp/Views/Home/LunchComplete.cshtml new file mode 100644 index 0000000..58df41e --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/LunchComplete.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "LunchComplete"; +} +
+

Завершение обеда

+
+ +
+
+
Выберите обед
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/Lunches.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Lunches.cshtml index 1720636..ec0419f 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/Lunches.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/Lunches.cshtml @@ -9,6 +9,7 @@ + diff --git a/Canteen/CanteenVisitorApp/Views/Home/UpdateLunch.cshtml b/Canteen/CanteenVisitorApp/Views/Home/UpdateLunch.cshtml index 0865272..31f6f98 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/UpdateLunch.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/UpdateLunch.cshtml @@ -8,7 +8,7 @@
Заказ:
-
+
Название обеда: