report is completed
This commit is contained in:
parent
8708d8b6d0
commit
555afefd32
@ -1,4 +1,5 @@
|
|||||||
using CanteenContracts.BindingModels;
|
using CanteenBusinessLogic.MailWorker;
|
||||||
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.BusinessLogicsContracts;
|
using CanteenContracts.BusinessLogicsContracts;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.StoragesContracts;
|
using CanteenContracts.StoragesContracts;
|
||||||
@ -16,11 +17,13 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IManagerStorage _managerStorage;
|
private readonly IManagerStorage _managerStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
|
||||||
public ManagerLogic(ILogger<ManagerLogic> logger, IManagerStorage managerStorage)
|
public ManagerLogic(ILogger<ManagerLogic> logger, IManagerStorage managerStorage, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_managerStorage = managerStorage;
|
_managerStorage = managerStorage;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(ManagerBindingModel model)
|
public bool Create(ManagerBindingModel model)
|
||||||
@ -85,6 +88,18 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
return list;
|
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)
|
public bool Update(ManagerBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -137,5 +152,6 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Такой менеджер уже есть");
|
throw new InvalidOperationException("Такой менеджер уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ using CanteenContracts.StoragesContracts;
|
|||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
using CanteenContracts.ViewModels;
|
using CanteenContracts.ViewModels;
|
||||||
using DocumentFormat.OpenXml.Bibliography;
|
using DocumentFormat.OpenXml.Bibliography;
|
||||||
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||||
|
using DocumentFormat.OpenXml.Presentation;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace CanteenBusinessLogic.BusinessLogics
|
namespace CanteenBusinessLogic.BusinessLogics
|
||||||
@ -79,29 +82,57 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
public List<ReportCooksPCView> GetCooksPCView(ReportBindingModel model)
|
||||||
|
|
||||||
public void saveLunchesToPdfFile(ReportBindingModel model)
|
|
||||||
{
|
{
|
||||||
saveToPdf.CreateDoc(new PdfInfo
|
var list = new List<ReportCooksPCView>();
|
||||||
|
|
||||||
|
var cooks = cookStorage.GetFilteredList(new CookSearchModel
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
ManagerId = model.UserId
|
||||||
Title = "Список заказов",
|
|
||||||
DateAfter = model.DateAfter.Value,
|
|
||||||
DateBefore = model.DateBefore.Value,
|
|
||||||
Lunches = GetLunchesPCView(model)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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<LunchViewModel>()
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
public List<ReportCookView> GetCooksByLanches(ReportBindingModel model)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list.Add(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public List<ReportCookView> GetCooksByLunches(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
var list = new List<ReportCookView>();
|
var list = new List<ReportCookView>();
|
||||||
|
|
||||||
var lunches = lunchStorage.GetFilteredList(new LunchSearchModel
|
var lunches = lunchStorage.GetFilteredList(new LunchSearchModel
|
||||||
{
|
{
|
||||||
DateFrom = (DateTime)model.DateAfter,
|
|
||||||
DateTo = model.DateBefore,
|
|
||||||
VisitorId = model.UserId
|
VisitorId = model.UserId
|
||||||
});
|
}).Where(x => model.LunchId.Contains(x.Id)).ToList();
|
||||||
|
|
||||||
|
|
||||||
foreach (var lunch in lunches)
|
foreach (var lunch in lunches)
|
||||||
{
|
{
|
||||||
@ -130,7 +161,6 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ReportOrderView> GetOrdersByProducts(ReportBindingModel model)
|
private List<ReportOrderView> GetOrdersByProducts(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
var list = new List<ReportOrderView>();
|
var list = new List<ReportOrderView>();
|
||||||
@ -138,7 +168,7 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
var products = productStorage.GetFilteredList(new ProductSearchModel
|
var products = productStorage.GetFilteredList(new ProductSearchModel
|
||||||
{
|
{
|
||||||
ManagerId = model.UserId
|
ManagerId = model.UserId
|
||||||
});
|
}).Where(x => model.ProductId.Contains(x.Id));
|
||||||
|
|
||||||
foreach (var product in products)
|
foreach (var product in products)
|
||||||
{
|
{
|
||||||
@ -160,38 +190,55 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
return list;
|
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)
|
public void saveCooksToExcel(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
saveToExcel.CreateCooksReport(new ExcelInfo()
|
saveToExcel.CreateCooksReport(new ExcelInfo()
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
|
||||||
Title = "Список поваров:",
|
Title = "Список поваров:",
|
||||||
Cooks = GetCooksByLanches(model)
|
Cooks = GetCooksByLunches(model)
|
||||||
});
|
|
||||||
}
|
|
||||||
public void saveCooksToWord(ReportBindingModel model)
|
|
||||||
{
|
|
||||||
saveToWord.CreateCooksDoc(new WordInfo()
|
|
||||||
{
|
|
||||||
FileName = model.FileName,
|
|
||||||
Title = "Список поваров",
|
|
||||||
Cooks = GetCooksByLanches(model)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void saveOrdersToExcel(ReportBindingModel model)
|
public void saveOrdersToExcel(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
saveToExcel.CreateOrdersReport(new ExcelInfo()
|
saveToExcel.CreateOrdersReport(new ExcelInfo()
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
|
||||||
Title = "Список заказов:",
|
Title = "Список заказов:",
|
||||||
Orders = GetOrdersByProducts(model)
|
Orders = GetOrdersByProducts(model)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public void saveCooksToWord(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
saveToWord.CreateCooksDoc(new WordInfo()
|
||||||
|
{
|
||||||
|
Title = "Список поваров",
|
||||||
|
Cooks = GetCooksByLunches(model)
|
||||||
|
});
|
||||||
|
}
|
||||||
public void saveOrdersToWord(ReportBindingModel model)
|
public void saveOrdersToWord(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
saveToWord.CreateOrdersDoc(new WordInfo()
|
saveToWord.CreateOrdersDoc(new WordInfo()
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
|
||||||
Title = "Список заказов",
|
Title = "Список заказов",
|
||||||
Orders = GetOrdersByProducts(model)
|
Orders = GetOrdersByProducts(model)
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
@ -9,6 +9,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.1.2" />
|
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.1.2" />
|
||||||
|
<PackageReference Include="MailKit" Version="4.1.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="1.50.5147" />
|
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="1.50.5147" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -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<AbstractMailWorker> 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);
|
||||||
|
}
|
||||||
|
}
|
42
Canteen/CanteenBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
42
Canteen/CanteenBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -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<MailKitWorker> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -100,7 +100,7 @@ namespace CanteenBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
ColumnName = "A",
|
ColumnName = "A",
|
||||||
RowIndex = rowIndex,
|
RowIndex = rowIndex,
|
||||||
Text = $"Продукт: {orderView.Product.ProductName}, {orderView.Product.Price}",
|
Text = $"Продукт: Id: {orderView.Product.Id}. {orderView.Product.ProductName}, {orderView.Product.Price}",
|
||||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
});
|
});
|
||||||
MergeCells(new ExcelMergeParameters
|
MergeCells(new ExcelMergeParameters
|
||||||
|
@ -5,12 +5,13 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CanteenBusinessLogic.OfficePackage.HelperEnums;
|
using CanteenBusinessLogic.OfficePackage.HelperEnums;
|
||||||
using CanteenBusinessLogic.OfficePackage.HelperModels;
|
using CanteenBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using CanteenContracts.ViewModels;
|
||||||
|
|
||||||
namespace CanteenBusinessLogic.OfficePackage
|
namespace CanteenBusinessLogic.OfficePackage
|
||||||
{
|
{
|
||||||
public abstract class AbstractSaveToPdf
|
public abstract class AbstractSaveToPdf
|
||||||
{
|
{
|
||||||
public void CreateDoc(PdfInfo info)
|
public void CreateLunchDoc(PdfInfo info)
|
||||||
{
|
{
|
||||||
CreatePdf(info);
|
CreatePdf(info);
|
||||||
CreateParagraph(new PdfParagraph
|
CreateParagraph(new PdfParagraph
|
||||||
@ -62,6 +63,47 @@ namespace CanteenBusinessLogic.OfficePackage
|
|||||||
}
|
}
|
||||||
SavePdf(info);
|
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<string> { "2cm", "3cm", "2cm", "2cm", "2cm" });
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "Id повара", "ФИО повара", "Id обеда", "Дата начала обеда", "Дата окончания обеда" },
|
||||||
|
Style = "NormalTitle",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||||
|
});
|
||||||
|
foreach (var cook in info.Cooks)
|
||||||
|
{
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { cook.CookId.ToString(), cook.FIO.ToString(), "", "", "" },
|
||||||
|
Style = "Normal",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var lunch in cook.Lunches)
|
||||||
|
{
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "", "", 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 CreatePdf(PdfInfo info);
|
||||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||||
protected abstract void CreateTable(List<string> columns);
|
protected abstract void CreateTable(List<string> columns);
|
||||||
|
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CanteenBusinessLogic.OfficePackage.HelperEnums;
|
using CanteenBusinessLogic.OfficePackage.HelperEnums;
|
||||||
using CanteenBusinessLogic.OfficePackage.HelperModels;
|
using CanteenBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using DocumentFormat.OpenXml.EMMA;
|
||||||
|
|
||||||
namespace CanteenBusinessLogic.OfficePackage
|
namespace CanteenBusinessLogic.OfficePackage
|
||||||
{
|
{
|
||||||
@ -73,14 +74,72 @@ namespace CanteenBusinessLogic.OfficePackage
|
|||||||
|
|
||||||
SaveWord(info);
|
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 CreateWord(WordInfo info);
|
||||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||||
protected abstract void SaveWord(WordInfo info);
|
protected abstract void SaveWord(WordInfo info);
|
||||||
|
|
||||||
internal void CreateOrdersDoc(WordInfo wordInfo)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class ExcelInfo
|
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 string Title { get; set; }
|
||||||
public List<ReportCookView> Cooks { get; set; }
|
public List<ReportCookView> Cooks { get; set; }
|
||||||
public List<ReportOrderView> Orders { get; set; }
|
public List<ReportOrderView> Orders { get; set; }
|
||||||
|
@ -9,11 +9,11 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class PdfInfo
|
public class PdfInfo
|
||||||
{
|
{
|
||||||
public string FileName { get; set; }
|
public string FileName = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.pdf";
|
||||||
public string FilePath = "C:\\Reports";
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public DateTime DateAfter { get; set; }
|
public DateTime DateAfter { get; set; }
|
||||||
public DateTime DateBefore { get; set; }
|
public DateTime DateBefore { get; set; }
|
||||||
public List<ReportLunchesPCView> Lunches { get; set; }
|
public List<ReportLunchesPCView> Lunches { get; set; }
|
||||||
|
public List<ReportCooksPCView> Cooks { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class WordInfo
|
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 string Title { get; set; }
|
||||||
public List<ReportCookView> Cooks { get; set; }
|
public List<ReportCookView> Cooks { get; set; }
|
||||||
public List<ReportOrderView> Orders { get; set; }
|
public List<ReportOrderView> Orders { get; set; }
|
||||||
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,11 @@ namespace CanteenContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public class ReportBindingModel
|
public class ReportBindingModel
|
||||||
{
|
{
|
||||||
public string FileName { get; set; }
|
public string? FileName { get; set; }
|
||||||
public DateTime? DateAfter { get; set; }
|
public DateTime? DateAfter { get; set; }
|
||||||
public DateTime? DateBefore { get; set; }
|
public DateTime? DateBefore { get; set; }
|
||||||
public List<LunchViewModel>? lunches { get; set; }
|
|
||||||
public List<OrderViewModel>? orders { get; set; }
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
public List<int>? LunchId { get; set; }
|
||||||
|
public List<int>? ProductId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,6 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
bool Finish(LunchBindingModel model);
|
bool Finish(LunchBindingModel model);
|
||||||
bool UpdateOrders(LunchBindingModel lunch, OrderBindingModel order);
|
bool UpdateOrders(LunchBindingModel lunch, OrderBindingModel order);
|
||||||
bool UpdateProducts(LunchBindingModel lunch, ProductBindingModel product, int count);
|
bool UpdateProducts(LunchBindingModel lunch, ProductBindingModel product, int count);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,6 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
ManagerViewModel? ReadElement(ManagerSearchModel model);
|
ManagerViewModel? ReadElement(ManagerSearchModel model);
|
||||||
bool Create(ManagerBindingModel model);
|
bool Create(ManagerBindingModel model);
|
||||||
bool Update(ManagerBindingModel model);
|
bool Update(ManagerBindingModel model);
|
||||||
|
bool SendMail(MailSendInfoBindingModel emailInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,10 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
{
|
{
|
||||||
public interface IReportLogic
|
public interface IReportLogic
|
||||||
{
|
{
|
||||||
public List<ReportCookView> GetCooksByLanches(ReportBindingModel model);
|
public List<ReportCookView> GetCooksByLunches(ReportBindingModel model);
|
||||||
List<ReportLunchesPCView> GetLunchesPCView(ReportBindingModel model);
|
List<ReportLunchesPCView> GetLunchesPCView(ReportBindingModel model);
|
||||||
void saveLunchesToPdfFile(ReportBindingModel model);
|
void saveLunchesToPdfFile(ReportBindingModel model);
|
||||||
|
void saveCooksToPdfFile(ReportBindingModel model);
|
||||||
void saveCooksToWord(ReportBindingModel model);
|
void saveCooksToWord(ReportBindingModel model);
|
||||||
void saveCooksToExcel(ReportBindingModel model);
|
void saveCooksToExcel(ReportBindingModel model);
|
||||||
public void saveOrdersToExcel(ReportBindingModel model);
|
public void saveOrdersToExcel(ReportBindingModel model);
|
||||||
|
16
Canteen/CanteenContracts/ViewModels/ReportCooksPCView.cs
Normal file
16
Canteen/CanteenContracts/ViewModels/ReportCooksPCView.cs
Normal file
@ -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<LunchViewModel> Lunches { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace CanteenDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
|
|
||||||
public List<CookViewModel> GetFilteredList(CookSearchModel model)
|
public List<CookViewModel> GetFilteredList(CookSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue && !model.OrderId.HasValue)
|
if (!model.Id.HasValue && !model.OrderId.HasValue && !model.ManagerId.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
public List<LunchViewModel> GetFilteredList(LunchSearchModel model)
|
public List<LunchViewModel> GetFilteredList(LunchSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.VisitorId.HasValue)
|
if (!model.VisitorId.HasValue & !model.DateFrom.HasValue & !model.DateTo.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
@ -477,13 +477,14 @@ namespace CanteenManagerApp.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Report()
|
public IActionResult Report()
|
||||||
{
|
{
|
||||||
|
ViewBag.ProductList = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
|
||||||
return View(new ReportBindingModel());
|
return View(new ReportBindingModel());
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ReportPdf(ReportBindingModel model)
|
public void ReportPdf(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
model.UserId = APIClient.Manager.Id;
|
model.UserId = APIClient.Manager.Id;
|
||||||
APIClient.PostRequest("api/main/SaveLunchesToPDF", model);
|
APIClient.PostRequest("api/main/SaveOrdersToPDF", model);
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,7 +492,7 @@ namespace CanteenManagerApp.Controllers
|
|||||||
public void ReportXsl(ReportBindingModel model)
|
public void ReportXsl(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
model.UserId = APIClient.Manager.Id;
|
model.UserId = APIClient.Manager.Id;
|
||||||
APIClient.PostRequest("api/main/SaveOrdersToXSL", model);
|
APIClient.PostRequest("api/main/SavevToXSL", model);
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,8 +507,19 @@ namespace CanteenManagerApp.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ReportEmail(ReportBindingModel model)
|
public void ReportEmail(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
APIClient.PostRequest("api/main/SaveEMAIL", model);
|
if (APIClient.Manager == null)
|
||||||
Response.Redirect("Index");
|
{
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,27 +5,38 @@
|
|||||||
ViewBag.Title = "Report";
|
ViewBag.Title = "Report";
|
||||||
}
|
}
|
||||||
|
|
||||||
<h2>Generate Report</h2>
|
<h2>Отчеты</h2>
|
||||||
|
|
||||||
@using (Html.BeginForm("Report", "Home", FormMethod.Post))
|
@using (Html.BeginForm("Report", "Home", FormMethod.Post))
|
||||||
{
|
{
|
||||||
<div>
|
<div class="row">
|
||||||
@Html.LabelFor(m => m.FileName)
|
<h4>Pdf</h4>
|
||||||
@Html.TextBoxFor(m => m.FileName)
|
<div class="col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
@Html.LabelFor(m => m.DateBefore, "От")
|
||||||
|
@Html.TextBoxFor(m => m.DateBefore, new { type = "date", @class = "form-control" })
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="col-md-6">
|
||||||
@Html.LabelFor(m => m.DateAfter)
|
<div class="form-group">
|
||||||
@Html.TextBoxFor(m => m.DateAfter, new { type = "date" })
|
@Html.LabelFor(m => m.DateAfter, "До")
|
||||||
|
@Html.TextBoxFor(m => m.DateAfter, new { type = "date", @class = "form-control" })
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mt-2">
|
||||||
|
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportPdf", "Home")">Сохранить в pdf</button>
|
||||||
|
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportEmail", "Home")">Отправить pdf по почте</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="mt-3">
|
||||||
@Html.LabelFor(m => m.DateBefore)
|
<h4>Word, Excel</h4>
|
||||||
@Html.TextBoxFor(m => m.DateBefore, new { type = "date" })
|
<div class="form-group mb-2">
|
||||||
|
@Html.LabelFor(m => m.ProductId, "Выбранные продукты")
|
||||||
|
@Html.DropDownListFor(m => m.ProductId, new SelectList(ViewBag.ProductList, "Id", "ProductName"), new { @class = "form-control", multiple = "multiple" })
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportXsl", "Home")">Сохранить в excel</button>
|
||||||
|
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportWord", "Home")">Сохранить в word</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" formaction="@Url.Action("ReportPdf", "Home")">Сохранить в pfd</button>
|
|
||||||
<button type="submit" formaction="@Url.Action("ReportEmail", "Home")">Отправить по почте</button>
|
|
||||||
<button type="submit" formaction="@Url.Action("ReportXsl", "Home")">Сохранить в excel</button>
|
|
||||||
<button type="submit" formaction="@Url.Action("ReportWord", "Home")">Сохранить в word</button>
|
|
||||||
}
|
}
|
@ -45,9 +45,25 @@ namespace CanteenRestApi.Controllers
|
|||||||
{
|
{
|
||||||
DateAfter = model.DateAfter,
|
DateAfter = model.DateAfter,
|
||||||
DateBefore = model.DateBefore,
|
DateBefore = model.DateBefore,
|
||||||
FileName = model.FileName,
|
UserId = model.UserId
|
||||||
UserId = model.UserId,
|
});
|
||||||
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = 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)
|
catch (Exception ex)
|
||||||
@ -62,16 +78,12 @@ namespace CanteenRestApi.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var excelFileName = $"{model.FileName}.xlsx";
|
|
||||||
var excelFilePath = excelFileName;
|
|
||||||
|
|
||||||
_reportLogic.saveCooksToExcel(new ReportBindingModel()
|
_reportLogic.saveCooksToExcel(new ReportBindingModel()
|
||||||
{
|
{
|
||||||
DateAfter = model.DateAfter,
|
DateAfter = model.DateAfter,
|
||||||
DateBefore = model.DateBefore,
|
DateBefore = model.DateBefore,
|
||||||
FileName = excelFilePath,
|
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
|
LunchId = model.LunchId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -90,9 +102,8 @@ namespace CanteenRestApi.Controllers
|
|||||||
{
|
{
|
||||||
DateAfter = model.DateAfter,
|
DateAfter = model.DateAfter,
|
||||||
DateBefore = model.DateBefore,
|
DateBefore = model.DateBefore,
|
||||||
FileName = model.FileName,
|
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
|
LunchId = model.LunchId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -109,9 +120,8 @@ namespace CanteenRestApi.Controllers
|
|||||||
{
|
{
|
||||||
_reportLogic.saveOrdersToExcel(new ReportBindingModel()
|
_reportLogic.saveOrdersToExcel(new ReportBindingModel()
|
||||||
{
|
{
|
||||||
FileName = $"{model.FileName}.xlsx",
|
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
orders = _order.ReadList(new OrderSearchModel { VisitorId = model.UserId }),
|
ProductId = model.ProductId
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -123,15 +133,14 @@ namespace CanteenRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void SaveOrderToWORD(ReportBindingModel model)
|
public void SaveOrdersToWORD(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_reportLogic.saveOrdersToWord(new ReportBindingModel()
|
_reportLogic.saveOrdersToWord(new ReportBindingModel()
|
||||||
{
|
{
|
||||||
FileName = $"{model.FileName}.docx",
|
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
|
ProductId = model.ProductId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -583,6 +592,19 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
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]
|
[HttpGet]
|
||||||
public List<LunchViewModel>? GetLunchList(int visitorId)
|
public List<LunchViewModel>? GetLunchList(int visitorId)
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts;
|
|||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
namespace CanteenRestApi.Controllers
|
namespace CanteenRestApi.Controllers
|
||||||
{
|
{
|
||||||
@ -12,11 +13,13 @@ namespace CanteenRestApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IManagerLogic _logic;
|
private readonly IManagerLogic _logic;
|
||||||
|
private readonly IReportLogic _report;
|
||||||
|
|
||||||
public ManagerController(IManagerLogic logic, ILogger<ManagerController> logger)
|
public ManagerController(IManagerLogic logic, IReportLogic report, ILogger<ManagerController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
|
_report = report;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -64,5 +67,27 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
using CanteenBusinessLogic.BusinessLogics;
|
using CanteenBusinessLogic.BusinessLogics;
|
||||||
|
using CanteenBusinessLogic.MailWorker;
|
||||||
using CanteenBusinessLogic.OfficePackage;
|
using CanteenBusinessLogic.OfficePackage;
|
||||||
using CanteenBusinessLogic.OfficePackage.Implements;
|
using CanteenBusinessLogic.OfficePackage.Implements;
|
||||||
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.BusinessLogicsContracts;
|
using CanteenContracts.BusinessLogicsContracts;
|
||||||
using CanteenContracts.StoragesContracts;
|
using CanteenContracts.StoragesContracts;
|
||||||
using CanteenDatabaseImplement.Implements;
|
using CanteenDatabaseImplement.Implements;
|
||||||
@ -34,6 +36,7 @@ builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
|||||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// 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 app = builder.Build();
|
||||||
|
|
||||||
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||||
|
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.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -5,5 +5,11 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"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"
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -227,6 +227,34 @@ namespace CanteenVisitorApp.Controllers
|
|||||||
Response.Redirect("Orders");
|
Response.Redirect("Orders");
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
public IActionResult LunchComplete()
|
||||||
|
{
|
||||||
|
if (APIClient.Visitor == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"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()
|
public IActionResult UpdateOrder()
|
||||||
{
|
{
|
||||||
if (APIClient.Visitor == null)
|
if (APIClient.Visitor == null)
|
||||||
@ -372,7 +400,7 @@ namespace CanteenVisitorApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
ViewBag.Lunches = APIClient.GetRequest<List<OrderViewModel>>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}");
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@ -400,7 +428,7 @@ namespace CanteenVisitorApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
ViewBag.Lunches = APIClient.GetRequest<List<OrderViewModel>>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}");
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
25
Canteen/CanteenVisitorApp/Views/Home/LunchComplete.cshtml
Normal file
25
Canteen/CanteenVisitorApp/Views/Home/LunchComplete.cshtml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "LunchComplete";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Завершение обеда</h2>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.row {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Выберите обед</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="id" name="id" class="form-control" asp-items="@(new SelectList(@ViewBag.Lunches, "Id", "Id"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Завершить" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -9,6 +9,7 @@
|
|||||||
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("UpdateLunch", "Home")'">Обновить обед</button>
|
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("UpdateLunch", "Home")'">Обновить обед</button>
|
||||||
<button type="button" class="btn btn-success" onclick="location.href='@Url.Action("LunchAddOrders", "Home")'">Привязать заказ</button>
|
<button type="button" class="btn btn-success" onclick="location.href='@Url.Action("LunchAddOrders", "Home")'">Привязать заказ</button>
|
||||||
<button type="button" class="btn btn-success" onclick="location.href='@Url.Action("LunchAddProducts", "Home")'">Привязать продукт</button>
|
<button type="button" class="btn btn-success" onclick="location.href='@Url.Action("LunchAddProducts", "Home")'">Привязать продукт</button>
|
||||||
|
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("LunchComplete", "Home")'">Завершить обед</button>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Заказ:</div>
|
<div class="col-4">Заказ:</div>
|
||||||
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Lunches, "Id", "Id"))"></select></div>
|
<div class="col-8"><select id="Id" name="Id" class="form-control" asp-items="@(new SelectList(@ViewBag.Lunches, "Id", "Id"))"></select></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Название обеда:</div>
|
<div class="col-4">Название обеда:</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user