partially done reports
This commit is contained in:
parent
3e15c7b642
commit
8708d8b6d0
@ -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<ReportLunchesPCView>();
|
||||
|
||||
// Получаем список обедов (сущность 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<CookViewModel>()
|
||||
};
|
||||
|
||||
// Получаем связанные заказы (сущность 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<CookViewModel> GetCooksByLanches(ReportBindingModel model)
|
||||
public List<ReportCookView> GetCooksByLanches(ReportBindingModel model)
|
||||
{
|
||||
var list = new List<CookViewModel>();
|
||||
var listCookIds = new List<int>();
|
||||
foreach (var lunch in model.lunches)
|
||||
var list = new List<ReportCookView>();
|
||||
|
||||
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)
|
||||
{
|
||||
listCookIds.AddRange(elem.ProductCooks.Keys.ToList());
|
||||
var record = new ReportCookView
|
||||
{
|
||||
Lunch = lunch,
|
||||
Cooks = new List<CookViewModel>()
|
||||
};
|
||||
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 = listCookIds.Distinct().ToList().Select(rec => cookStorage.GetElement(new CookSearchModel { Id = rec })).ToList();
|
||||
}
|
||||
|
||||
list.Add(record);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<ReportOrderView> GetOrdersByProducts(ReportBindingModel model)
|
||||
{
|
||||
var list = new List<ReportOrderView>();
|
||||
|
||||
var products = productStorage.GetFilteredList(new ProductSearchModel
|
||||
{
|
||||
ManagerId = model.UserId
|
||||
});
|
||||
|
||||
foreach (var product in products)
|
||||
{
|
||||
var record = new ReportOrderView
|
||||
{
|
||||
Product = product,
|
||||
Orders = new List<OrderViewModel>()
|
||||
};
|
||||
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);
|
||||
}
|
||||
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)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,13 +27,30 @@ 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,
|
||||
Text = $"Обед: {reportCookView.Lunch.LunchName}, {reportCookView.Lunch.DateCreate}",
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A" + 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
|
||||
@ -56,6 +74,73 @@ namespace CanteenBusinessLogic.OfficePackage
|
||||
});
|
||||
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);
|
||||
}
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
|
@ -10,24 +10,58 @@ 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
|
||||
}
|
||||
});
|
||||
|
||||
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",
|
||||
@ -35,11 +69,18 @@ namespace CanteenBusinessLogic.OfficePackage
|
||||
}
|
||||
});
|
||||
}
|
||||
SaveWord(info);
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public List<CookViewModel> Cooks { get; set; }
|
||||
public List<ReportCookView> Cooks { get; set; }
|
||||
public List<ReportOrderView> Orders { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public List<CookViewModel> Cooks { get; set; }
|
||||
public List<ReportCookView> Cooks { get; set; }
|
||||
public List<ReportOrderView> Orders { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace CanteenContracts.BindingModels
|
||||
public DateTime? DateAfter { get; set; }
|
||||
public DateTime? DateBefore { get; set; }
|
||||
public List<LunchViewModel>? lunches { get; set; }
|
||||
public int VisitorId { get; set; }
|
||||
public List<OrderViewModel>? orders { get; set; }
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,12 @@ namespace CanteenContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
List<CookViewModel> GetCooksByLanches(ReportBindingModel model);
|
||||
public List<ReportCookView> GetCooksByLanches(ReportBindingModel model);
|
||||
List<ReportLunchesPCView> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace CanteenContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? VisitorId { get; set; }
|
||||
public int? CookId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace CanteenContracts.StoragesContracts
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderCookViewModel? GetOrderCookElement(OrderCookSearchModel model);
|
||||
List<OrderViewModel>? GetOrderCooksList(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
|
15
Canteen/CanteenContracts/ViewModels/ReportCookView.cs
Normal file
15
Canteen/CanteenContracts/ViewModels/ReportCookView.cs
Normal file
@ -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<CookViewModel> Cooks { get; set; }
|
||||
}
|
||||
}
|
15
Canteen/CanteenContracts/ViewModels/ReportOrderView.cs
Normal file
15
Canteen/CanteenContracts/ViewModels/ReportOrderView.cs
Normal file
@ -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<OrderViewModel> Orders { get; set; }
|
||||
public ProductViewModel Product { get; set; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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<CookViewModel> 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();
|
||||
}
|
||||
|
@ -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<OrderViewModel>? 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<OrderViewModel> GetFullList()
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace CanteenDatabaseImplement.Models
|
||||
Id = Id,
|
||||
ManagerId = ManagerId,
|
||||
FIO = FIO,
|
||||
Position = Position
|
||||
Position = Position,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -474,5 +474,40 @@ namespace CanteenManagerApp.Controllers
|
||||
ViewBag.Model = APIClient.GetRequest<List<GraphicViewModel>>($"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");
|
||||
}
|
||||
}
|
||||
}
|
31
Canteen/CanteenManagerApp/Views/Home/Report.cshtml
Normal file
31
Canteen/CanteenManagerApp/Views/Home/Report.cshtml
Normal file
@ -0,0 +1,31 @@
|
||||
@using CanteenContracts.BindingModels;
|
||||
@model ReportBindingModel
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Report";
|
||||
}
|
||||
|
||||
<h2>Generate Report</h2>
|
||||
|
||||
@using (Html.BeginForm("Report", "Home", FormMethod.Post))
|
||||
{
|
||||
<div>
|
||||
@Html.LabelFor(m => m.FileName)
|
||||
@Html.TextBoxFor(m => m.FileName)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@Html.LabelFor(m => m.DateAfter)
|
||||
@Html.TextBoxFor(m => m.DateAfter, new { type = "date" })
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@Html.LabelFor(m => m.DateBefore)
|
||||
@Html.TextBoxFor(m => m.DateBefore, new { type = "date" })
|
||||
</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>
|
||||
}
|
@ -34,6 +34,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчеты</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Graphic">Графики</a>
|
||||
</li>
|
||||
|
@ -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)
|
||||
|
BIN
Canteen/CanteenRestApi/Cook.docx
Normal file
BIN
Canteen/CanteenRestApi/Cook.docx
Normal file
Binary file not shown.
BIN
Canteen/CanteenRestApi/Cook.docx.xlsx.xls
Normal file
BIN
Canteen/CanteenRestApi/Cook.docx.xlsx.xls
Normal file
Binary file not shown.
BIN
Canteen/CanteenRestApi/Cook.xlsx
Normal file
BIN
Canteen/CanteenRestApi/Cook.xlsx
Normal file
Binary file not shown.
BIN
Canteen/CanteenRestApi/Order.xlsx
Normal file
BIN
Canteen/CanteenRestApi/Order.xlsx
Normal file
Binary file not shown.
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user