diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs index 8883a04..9120ded 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs @@ -6,6 +6,8 @@ using CanteenContracts.SearchModel; using CanteenContracts.StoragesContracts; using CanteenContracts.View; using CanteenContracts.ViewModels; +using DocumentFormat.OpenXml.Bibliography; +using System.Linq; namespace CanteenBusinessLogic.BusinessLogics { @@ -35,12 +37,11 @@ namespace CanteenBusinessLogic.BusinessLogics { var list = new List(); - // Получаем список обедов (сущность 1) за указанный период и для указанного посетителя var lunches = lunchStorage.GetFilteredList(new LunchSearchModel { DateFrom = (DateTime)model.DateAfter, DateTo = model.DateBefore, - VisitorId = model.VisitorId + VisitorId = model.UserId }); foreach (var lunch in lunches) @@ -53,16 +54,13 @@ namespace CanteenBusinessLogic.BusinessLogics Cooks = new List() }; - // Получаем связанные заказы (сущность 2) для текущего обеда var orders = lunch.LunchOrders.Keys.ToList(); foreach (var orderId in orders) { - // Получаем заказы (сущность 2) и добавляем их в список Orders var order = orderStorage.GetElement(new OrderSearchModel { Id = orderId }); record.Orders.Add(order); } - // Получаем связанных поваров (сущность 4) для текущих продуктов обеда var lunchProducts = lunch.LunchProducts.Keys.ToList(); foreach (var productId in lunchProducts) { @@ -71,7 +69,6 @@ namespace CanteenBusinessLogic.BusinessLogics foreach (var cookId in productCooks) { - // Получаем поваров (сущность 4) и добавляем их в список Cooks var cook = cookStorage.GetElement(new CookSearchModel { Id = cookId }); record.Cooks.Add(cook); } @@ -95,24 +92,77 @@ namespace CanteenBusinessLogic.BusinessLogics Lunches = GetLunchesPCView(model) }); } - public List GetCooksByLanches(ReportBindingModel model) + public List GetCooksByLanches(ReportBindingModel model) { - var list = new List(); - var listCookIds = new List(); - foreach (var lunch in model.lunches) + var list = new List(); + + var lunches = lunchStorage.GetFilteredList(new LunchSearchModel { - var lunchProducts = lunch.LunchProducts.Keys.ToList().Select(rec => productStorage.GetElement(new ProductSearchModel { Id = rec })); - foreach (var elem in lunchProducts) + DateFrom = (DateTime)model.DateAfter, + DateTo = model.DateBefore, + VisitorId = model.UserId + }); + + foreach (var lunch in lunches) + { + var record = new ReportCookView { - listCookIds.AddRange(elem.ProductCooks.Keys.ToList()); + Lunch = lunch, + Cooks = new List() + }; + var lunchProducts = lunch.LunchProducts.Keys.ToList(); + foreach (var productId in lunchProducts) + { + var product = productStorage.GetElement(new ProductSearchModel { Id = productId }); + var productCooks = product.ProductCooks.Keys.ToList(); + + foreach (var cookId in productCooks) + { + if (record.Cooks.Where(cook => cook.Id == cookId).ToList().Count == 0) + { + var cook = cookStorage.GetElement(new CookSearchModel { Id = cookId }); + record.Cooks.Add(cook); + } + } } + + list.Add(record); + } + return list; + } + + private List GetOrdersByProducts(ReportBindingModel model) + { + var list = new List(); + + var products = productStorage.GetFilteredList(new ProductSearchModel + { + ManagerId = model.UserId + }); + + foreach (var product in products) + { + var record = new ReportOrderView + { + Product = product, + Orders = new List() + }; + var productCook = product.ProductCooks.Keys.ToList(); + foreach (var cookId in productCook) + { + var orders = orderStorage.GetOrderCooksList(new OrderSearchModel { CookId = cookId }); + orders.ForEach(x => + { + if (record.Orders.Find(y => y.Id == x.Id) == null) record.Orders.Add(x); + }); + } + list.Add(record); } - list = listCookIds.Distinct().ToList().Select(rec => cookStorage.GetElement(new CookSearchModel { Id = rec })).ToList(); return list; } public void saveCooksToExcel(ReportBindingModel model) { - saveToExcel.CreateReport(new ExcelInfo() + saveToExcel.CreateCooksReport(new ExcelInfo() { FileName = model.FileName, Title = "Список поваров:", @@ -121,12 +171,30 @@ namespace CanteenBusinessLogic.BusinessLogics } public void saveCooksToWord(ReportBindingModel model) { - saveToWord.CreateDoc(new WordInfo() + saveToWord.CreateCooksDoc(new WordInfo() { FileName = model.FileName, Title = "Список поваров", Cooks = GetCooksByLanches(model) }); } + public void saveOrdersToExcel(ReportBindingModel model) + { + saveToExcel.CreateOrdersReport(new ExcelInfo() + { + FileName = model.FileName, + Title = "Список заказов:", + Orders = GetOrdersByProducts(model) + }); + } + public void saveOrdersToWord(ReportBindingModel model) + { + saveToWord.CreateOrdersDoc(new WordInfo() + { + FileName = model.FileName, + Title = "Список заказов", + Orders = GetOrdersByProducts(model) + }); + } } } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 4812d0c..d6d6ad4 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -5,12 +5,13 @@ using System.Text; using System.Threading.Tasks; using CanteenBusinessLogic.OfficePackage.HelperEnums; using CanteenBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.EMMA; namespace CanteenBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { - public void CreateReport(ExcelInfo info) + public void CreateCooksReport(ExcelInfo info) { CreateExcel(info); InsertCellInWorksheet(new ExcelCellParameters @@ -26,35 +27,119 @@ namespace CanteenBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; - foreach (var pc in info.Cooks) + + foreach (var reportCookView in info.Cooks) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = pc.FIO, - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "B", - RowIndex = rowIndex, - Text = "", - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = "", + Text = $"Обед: {reportCookView.Lunch.LunchName}, {reportCookView.Lunch.DateCreate}", StyleInfo = ExcelStyleInfoType.TextWithBroder }); MergeCells(new ExcelMergeParameters { CellFromName = "A" + rowIndex, - CellToName = "C" + rowIndex + CellToName = "E" + rowIndex }); rowIndex++; + + foreach (var cook in reportCookView.Cooks) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = cook.FIO, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = "", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = "", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A" + rowIndex, + CellToName = "C" + rowIndex + }); + rowIndex++; + } + } + SaveExcel(info); + } + + public void CreateOrdersReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var orderView in info.Orders) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = $"Продукт: {orderView.Product.ProductName}, {orderView.Product.Price}", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A" + rowIndex, + CellToName = "E" + rowIndex + }); + rowIndex++; + + foreach (var order in orderView.Orders) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = $"Id: {order.Id}", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = "", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = "", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A" + rowIndex, + CellToName = "C" + rowIndex + }); + rowIndex++; + } } SaveExcel(info); } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 00381c8..dcdd8fc 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -10,36 +10,77 @@ namespace CanteenBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { - public void CreateDoc(WordInfo info) + public void CreateCooksDoc(WordInfo info) { CreateWord(info); CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24"}) }, + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) }, TextProperties = new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Center } }); - foreach (var component in info.Cooks) + + foreach (var reportCookView in info.Cooks) { CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> {("Повар: ", new WordTextProperties {Bold = true, Size = "24"}), - (component.FIO, new WordTextProperties {Bold = false, Size = "24"})}, + Texts = new List<(string, WordTextProperties)> + { + ("Обед: ", new WordTextProperties { Bold = true, Size = "24" }), + (reportCookView.Lunch.LunchName, new WordTextProperties { Bold = false, Size = "24" }), + (" Дата создания: ", new WordTextProperties { Bold = true, Size = "24" }), + (reportCookView.Lunch.DateCreate.ToString(), new WordTextProperties { Bold = false, Size = "24" }) + }, TextProperties = new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Both } }); - } - SaveWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Повара: ", new WordTextProperties { Bold = true, Size = "24" }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + foreach (var cook in reportCookView.Cooks) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (cook.FIO, 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 48e5832..0d43e45 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } public string Title { get; set; } - public List Cooks { get; set; } + public List Cooks { get; set; } + public List Orders { get; set; } } } diff --git a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index e664e37..67a6189 100644 --- a/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/Canteen/CanteenBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } public string Title { get; set; } - public List Cooks { get; set; } + public List Cooks { get; set; } + public List Orders { get; set; } } } diff --git a/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs b/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs index 658c0c6..6470568 100644 --- a/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/ReportBindingModel.cs @@ -13,6 +13,7 @@ namespace CanteenContracts.BindingModels public DateTime? DateAfter { get; set; } public DateTime? DateBefore { get; set; } public List? lunches { get; set; } - public int VisitorId { get; set; } + public List? orders { get; set; } + public int UserId { get; set; } } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs index 08d3663..a596289 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IReportLogic.cs @@ -11,10 +11,12 @@ namespace CanteenContracts.BusinessLogicsContracts { public interface IReportLogic { - List GetCooksByLanches(ReportBindingModel model); + public List GetCooksByLanches(ReportBindingModel model); List GetLunchesPCView(ReportBindingModel model); void saveLunchesToPdfFile(ReportBindingModel model); void saveCooksToWord(ReportBindingModel model); void saveCooksToExcel(ReportBindingModel model); + public void saveOrdersToExcel(ReportBindingModel model); + public void saveOrdersToWord(ReportBindingModel model); } } diff --git a/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs b/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs index 0503b4d..8c00c4f 100644 --- a/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs @@ -11,5 +11,6 @@ namespace CanteenContracts.SearchModel public int? Id { get; set; } public string? FIO { get; set; } public int? ManagerId { get; set; } + public int? OrderId { get; set; } } } diff --git a/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs b/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs index b747160..434d762 100644 --- a/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs @@ -10,6 +10,7 @@ namespace CanteenContracts.SearchModel { public int? Id { get; set; } public int? VisitorId { get; set; } + public int? CookId { get; set; } } } diff --git a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs index 7bf4105..84519f6 100644 --- a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs +++ b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs @@ -16,7 +16,7 @@ namespace CanteenContracts.StoragesContracts List GetFullList(); List GetFilteredList(OrderSearchModel model); OrderViewModel? GetElement(OrderSearchModel model); - OrderCookViewModel? GetOrderCookElement(OrderCookSearchModel model); + List? GetOrderCooksList(OrderSearchModel model); OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); diff --git a/Canteen/CanteenContracts/ViewModels/ReportCookView.cs b/Canteen/CanteenContracts/ViewModels/ReportCookView.cs new file mode 100644 index 0000000..ff8e262 --- /dev/null +++ b/Canteen/CanteenContracts/ViewModels/ReportCookView.cs @@ -0,0 +1,15 @@ +using CanteenContracts.View; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.ViewModels +{ + public class ReportCookView + { + public LunchViewModel Lunch { get; set; } + public List Cooks { get; set; } + } +} diff --git a/Canteen/CanteenContracts/ViewModels/ReportOrderView.cs b/Canteen/CanteenContracts/ViewModels/ReportOrderView.cs new file mode 100644 index 0000000..26e1630 --- /dev/null +++ b/Canteen/CanteenContracts/ViewModels/ReportOrderView.cs @@ -0,0 +1,15 @@ +using CanteenContracts.View; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.ViewModels +{ + public class ReportOrderView + { + public List Orders { get; set; } + public ProductViewModel Product { get; set; } + } +} diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index a924378..fc050a6 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-A68O3K0;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-23CS6SP\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 8dca61d..089c094 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/CookStorage.cs @@ -4,6 +4,7 @@ using CanteenContracts.StoragesContracts; using CanteenContracts.View; using CanteenDatabaseImplement.Models; using CanteenDataModels.Models; +using FluentNHibernate.Conventions; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -25,16 +26,30 @@ namespace CanteenDatabaseImplement.Implements using var context = new CanteenDatabase(); - return context.Cooks.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + return context.Cooks + .Include(x => x.Products) + .ThenInclude(x => x.Product) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } public List GetFilteredList(CookSearchModel model) { + if (!model.Id.HasValue && !model.OrderId.HasValue) + { + return new(); + } using var context = new CanteenDatabase(); return context.Cooks .Include(x => x.Manager) - .Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)) + .Include(x => x.Products) + .ThenInclude(x => x.Product) + .Include(x => x.Orders) + .ThenInclude(x => x.Order) + .Where(x => + (model.Id.HasValue && x.Id == model.Id) || + (model.ManagerId.HasValue && model.ManagerId == x.ManagerId) || + (model.OrderId.HasValue && x.Orders.Find(x => x.CookId == model.OrderId) != null)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs index 4afa0e3..a244d82 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs @@ -55,11 +55,11 @@ namespace CanteenDatabaseImplement.Implements return context.Lunches .Include(x => x.Orders) - .ThenInclude(x => x.Order) + .ThenInclude(x => x.Order) .Include(x => x.Products) - .ThenInclude(x => x.Product) - .ThenInclude(x => x.Cooks) - .ThenInclude(x => x.Cook) + .ThenInclude(x => x.Product) + .ThenInclude(x => x.Cooks) + .ThenInclude(x => x.Cook) .Where(x => (x.DateCreate >= model.DateFrom && x.DateImplement <= model.DateTo) || (model.Id.HasValue && x.Id == model.Id) || diff --git a/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs index 8a186f2..d51488e 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs @@ -5,6 +5,7 @@ using CanteenContracts.StoragesContracts; using CanteenContracts.View; using CanteenContracts.ViewModels; using CanteenDatabaseImplement.Models; +using DocumentFormat.OpenXml.Office2019.Drawing.Model3D; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -16,17 +17,17 @@ namespace CanteenDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - public OrderCookViewModel? GetOrderCookElement(OrderCookSearchModel model) + public List? GetOrderCooksList(OrderSearchModel model) { - if (!model.Id.HasValue && (!model.OrderId.HasValue || !model.CookId.HasValue)) + if (!model.CookId.HasValue) { return null; } using var context = new CanteenDatabase(); - return context.OrderCook - .FirstOrDefault(x => x.OrderId == model.OrderId && x.CookId == model.CookId)?.GetViewModel; + var orders = context.Orders.Include(x => x.Cooks).ThenInclude(x => x.Cook).Select(x => x.GetViewModel).ToList(); + return orders.Where(x => x.OrderCooks.ContainsKey((int)model.CookId)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -61,7 +62,10 @@ namespace CanteenDatabaseImplement.Implements .ThenInclude(x => x.Cook) .Include(x => x.Tablewares) .ThenInclude(x => x.Tableware) - .Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.VisitorId.HasValue && model.VisitorId == x.VisitorId)).Select(x => x.GetViewModel).ToList(); + .Where(x => + (model.Id.HasValue && x.Id == model.Id) || + (model.VisitorId.HasValue && model.VisitorId == x.VisitorId)) + .Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs index 1d818be..ab9e013 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs @@ -52,11 +52,11 @@ namespace CanteenDatabaseImplement.Implements } using var context = new CanteenDatabase(); - return context.Products .Include(x => x.Cooks) .ThenInclude(x => x.Cook) - .Where(x => ((model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId))) + .Where(x => (model.Id.HasValue && x.Id == model.Id) || + (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)) .Select(x => x.GetViewModel).ToList(); } diff --git a/Canteen/CanteenDatabaseImplement/Models/Cook.cs b/Canteen/CanteenDatabaseImplement/Models/Cook.cs index e9493f2..b83e493 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Cook.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Cook.cs @@ -58,7 +58,7 @@ namespace CanteenDatabaseImplement.Models Id = Id, ManagerId = ManagerId, FIO = FIO, - Position = Position + Position = Position, }; } } diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index c7dac2f..b8826fe 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -474,5 +474,40 @@ namespace CanteenManagerApp.Controllers ViewBag.Model = APIClient.GetRequest>($"api/main/GetGraphic"); return View(); } + [HttpGet] + public IActionResult Report() + { + return View(new ReportBindingModel()); + } + [HttpPost] + public void ReportPdf(ReportBindingModel model) + { + model.UserId = APIClient.Manager.Id; + APIClient.PostRequest("api/main/SaveLunchesToPDF", model); + Response.Redirect("Index"); + } + + [HttpPost] + public void ReportXsl(ReportBindingModel model) + { + model.UserId = APIClient.Manager.Id; + APIClient.PostRequest("api/main/SaveOrdersToXSL", model); + Response.Redirect("Index"); + } + + [HttpPost] + public void ReportWord(ReportBindingModel model) + { + model.UserId = APIClient.Manager.Id; + APIClient.PostRequest("api/main/SaveOrdersToWORD", model); + Response.Redirect("Index"); + } + + [HttpPost] + public void ReportEmail(ReportBindingModel model) + { + APIClient.PostRequest("api/main/SaveEMAIL", model); + Response.Redirect("Index"); + } } } \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Report.cshtml b/Canteen/CanteenManagerApp/Views/Home/Report.cshtml new file mode 100644 index 0000000..f34fc8b --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/Report.cshtml @@ -0,0 +1,31 @@ +@using CanteenContracts.BindingModels; +@model ReportBindingModel + +@{ + ViewBag.Title = "Report"; +} + +

Generate Report

+ +@using (Html.BeginForm("Report", "Home", FormMethod.Post)) +{ +
+ @Html.LabelFor(m => m.FileName) + @Html.TextBoxFor(m => m.FileName) +
+ +
+ @Html.LabelFor(m => m.DateAfter) + @Html.TextBoxFor(m => m.DateAfter, new { type = "date" }) +
+ +
+ @Html.LabelFor(m => m.DateBefore) + @Html.TextBoxFor(m => m.DateBefore, new { type = "date" }) +
+ + + + + +} \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml index f65f83e..832a05f 100644 --- a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml +++ b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml @@ -34,6 +34,9 @@ + diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index d3fed55..0b520ba 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -37,7 +37,7 @@ namespace CanteenRestApi.Controllers } [HttpPost] - public void SavePDF(ReportBindingModel model) + public void SaveLunchesToPDF(ReportBindingModel model) { try { @@ -46,8 +46,8 @@ namespace CanteenRestApi.Controllers DateAfter = model.DateAfter, DateBefore = model.DateBefore, FileName = model.FileName, - VisitorId = model.VisitorId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId}), + UserId = model.UserId, + lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId}), }); } catch (Exception ex) @@ -58,7 +58,7 @@ namespace CanteenRestApi.Controllers } [HttpPost] - public IActionResult SaveXSL(ReportBindingModel model) + public void SaveCooksToXSL(ReportBindingModel model) { try { @@ -70,12 +70,9 @@ namespace CanteenRestApi.Controllers DateAfter = model.DateAfter, DateBefore = model.DateBefore, FileName = excelFilePath, - VisitorId = model.VisitorId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }), + UserId = model.UserId, + lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }), }); - - byte[] fileBytes = System.IO.File.ReadAllBytes(excelFilePath); - return File(fileBytes, "application/octet-stream", excelFileName); } catch (Exception ex) { @@ -85,7 +82,7 @@ namespace CanteenRestApi.Controllers } [HttpPost] - public void SaveWORD(ReportBindingModel model) + public void SaveCooksToWORD(ReportBindingModel model) { try { @@ -94,8 +91,47 @@ namespace CanteenRestApi.Controllers DateAfter = model.DateAfter, DateBefore = model.DateBefore, FileName = model.FileName, - VisitorId = model.VisitorId, - lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }), + 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 SaveOrdersToXSL(ReportBindingModel model) + { + try + { + _reportLogic.saveOrdersToExcel(new ReportBindingModel() + { + FileName = $"{model.FileName}.xlsx", + UserId = model.UserId, + orders = _order.ReadList(new OrderSearchModel { VisitorId = model.UserId }), + }); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } + + [HttpPost] + public void SaveOrderToWORD(ReportBindingModel model) + { + try + { + _reportLogic.saveOrdersToWord(new ReportBindingModel() + { + FileName = $"{model.FileName}.docx", + UserId = model.UserId, + lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }), }); } catch (Exception ex) diff --git a/Canteen/CanteenRestApi/Cook.docx b/Canteen/CanteenRestApi/Cook.docx new file mode 100644 index 0000000..09b976c Binary files /dev/null and b/Canteen/CanteenRestApi/Cook.docx differ diff --git a/Canteen/CanteenRestApi/Cook.docx.xlsx.xls b/Canteen/CanteenRestApi/Cook.docx.xlsx.xls new file mode 100644 index 0000000..dd56d27 Binary files /dev/null and b/Canteen/CanteenRestApi/Cook.docx.xlsx.xls differ diff --git a/Canteen/CanteenRestApi/Cook.xlsx b/Canteen/CanteenRestApi/Cook.xlsx new file mode 100644 index 0000000..1f8d8d7 Binary files /dev/null and b/Canteen/CanteenRestApi/Cook.xlsx differ diff --git a/Canteen/CanteenRestApi/Order.xlsx b/Canteen/CanteenRestApi/Order.xlsx new file mode 100644 index 0000000..c0267c0 Binary files /dev/null and b/Canteen/CanteenRestApi/Order.xlsx differ diff --git a/Canteen/CanteenRestApi/pdfReport b/Canteen/CanteenRestApi/pdfReport.pdf similarity index 100% rename from Canteen/CanteenRestApi/pdfReport rename to Canteen/CanteenRestApi/pdfReport.pdf diff --git a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs index bae65ca..0ec1cf3 100644 --- a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs +++ b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs @@ -507,31 +507,31 @@ namespace CanteenVisitorApp.Controllers [HttpPost] public void ReportPdf(ReportBindingModel model) { - model.VisitorId = APIClient.Visitor.Id; - APIClient.PostRequest("api/main/SavePDF", model); + model.UserId = APIClient.Visitor.Id; + APIClient.PostRequest("api/main/SaveLunchesToPDF", model); Response.Redirect("Index"); } [HttpPost] public void ReportXsl(ReportBindingModel model) { - model.VisitorId = APIClient.Visitor.Id; - APIClient.PostRequest("api/main/SaveXSL", model); + model.UserId = APIClient.Visitor.Id; + APIClient.PostRequest("api/main/SaveCooksToXSL", model); Response.Redirect("Index"); } [HttpPost] public void ReportWord(ReportBindingModel model) { - model.VisitorId = APIClient.Visitor.Id; - APIClient.PostRequest("api/main/SaveWORD", model); + model.UserId = APIClient.Visitor.Id; + APIClient.PostRequest("api/main/SaveCooksToWORD", model); Response.Redirect("Index"); } [HttpPost] public void ReportEmail(ReportBindingModel model) { - APIClient.PostRequest("api/main/SaveEMAIL", model); + APIClient.PostRequest("api/main/SaveCooksToEMAIL", model); Response.Redirect("Index"); } }