diff --git a/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs
new file mode 100644
index 0000000..3ef3fb0
--- /dev/null
+++ b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs
@@ -0,0 +1,41 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicContracts;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.StorageContracts;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopBusinessLogic.BusinessLogics
+{
+ public class ReportImplementerLogic : IReportImplementerLogic
+ {
+ private readonly IAssemblyStorage _assemblyStorage;
+ private readonly IRequestStorage _requestStorage;
+ private readonly IOrderStorage _orderStorage;
+
+ public ReportImplementerLogic(IAssemblyStorage assemblyStorage, IRequestStorage requestStorage, IOrderStorage orderStorage)
+ {
+ _assemblyStorage = assemblyStorage;
+ _requestStorage = requestStorage;
+ _orderStorage = orderStorage;
+ }
+ ///
+ /// Отчёт для doc/xls
+ ///
+ ///
+ public List GetOrderAssemblies(List selectedOrders) {
+ //!!!исправить на filteredList
+ return _orderStorage.GetReportWithAssembly(selectedOrders).Select(x => new ReportOrderAssemblyViewModel
+ {
+ OrderId = x.Id,
+ DateCreateOrder = x.DateCreate,
+ OrderSum = x.Sum,
+
+ });
+ }
+ }
+}
diff --git a/ComputerShopContracts/BindingModels/ReportBindingModel.cs b/ComputerShopContracts/BindingModels/ReportBindingModel.cs
new file mode 100644
index 0000000..5edb012
--- /dev/null
+++ b/ComputerShopContracts/BindingModels/ReportBindingModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.BindingModels
+{
+ public class ReportBindingModel
+ {
+ public string FileName { get; set; } = string.Empty;
+ public DateTime? DateFrom { get; set; }
+ public DateTime? DateTo { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs
new file mode 100644
index 0000000..9198ee4
--- /dev/null
+++ b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs
@@ -0,0 +1,28 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.BusinessLogicContracts
+{
+ public interface IReportImplementerLogic
+ {
+ ///
+ /// Получение отчёта для word/excel
+ ///
+ ///
+ List GetOrderAssemblies();
+
+ ///
+ /// Получение отчёта для почты
+ ///
+ ///
+ List GetOrderRequestAssemblies();
+ void SaveOrderAssembliesToWordFile(ReportBindingModel model);
+
+ void SaveOrderAssembliesToExcelFile(ReportBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/StorageContracts/IOrderStorage.cs b/ComputerShopContracts/StorageContracts/IOrderStorage.cs
index add00ea..e2ec1f1 100644
--- a/ComputerShopContracts/StorageContracts/IOrderStorage.cs
+++ b/ComputerShopContracts/StorageContracts/IOrderStorage.cs
@@ -17,5 +17,6 @@ namespace ComputerShopContracts.StorageContracts
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
+ List GetReportWithAssembly(List model);
}
}
diff --git a/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs
new file mode 100644
index 0000000..8c457c5
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs
@@ -0,0 +1,23 @@
+using ComputerShopDataModels.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.ViewModels
+{
+ public class ReportOrderAssemblyViewModel
+ {
+ //!!!мб тут хранить списки промежуточных сущностей
+ public int OrderId { get; set; }
+ public DateTime DateCreateOrder { get; set; }
+ public double OrderSum { get; set; }
+
+ public OrderStatus OrderStatus { get; set; }
+
+ public string AssemblyName { get; set; }
+ public string AssemblyCategory { get; set; }
+ public double AssemblyCost { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs
new file mode 100644
index 0000000..fd9027d
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs
@@ -0,0 +1,25 @@
+using ComputerShopDataModels.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.ViewModels
+{
+ public class ReportOrderRequestAssemblyViewModel
+ {
+ //!!!мб тут хранить списки промежуточных сущностей
+ public int OrderID { get; set; }
+ public DateTime DateCreateOrder { get; set; }
+ public double OrderSum { get; set; }
+
+ public OrderStatus OrderStatus { get; set; }
+ public int RequestId { get; set; }
+ public string ClientFIO { get; set; }
+ public DateTime DateRequest { get; set; }
+ public string AssemblyName { get; set; }
+ public string AssemblyCategory { get; set; }
+ public double AssemblyCost { get; set; }
+ }
+}
diff --git a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
index 80e005a..3999933 100644
--- a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
+++ b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
@@ -10,11 +10,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace ComputerShopDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
+ //id пользователя учитывается в GetFilteredList
public List GetFullList()
{
using var context = new ComputerShopDatabase();
@@ -70,6 +72,56 @@ namespace ComputerShopDatabaseImplement.Implements
.ToList();
}
+ //получение данных для отчёта сборок по выбранным заказам
+ public List GetReportWithAssembly(List selectedModels)
+ {
+ using var context = new ComputerShopDatabase();
+ //id заказов, которые выбрал пользователь
+ List id_of_selected_models = selectedModels.Select(x => x.Id).ToList();
+
+ //те заказы из бд, которые выбрал пользователь и имеют сборку
+ return context.Orders.Include(x => x.Requests)
+ .ThenInclude(x => x.Request)
+ .ThenInclude(x => x.Assembly)
+ .Where(x => id_of_selected_models.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null))
+
+
+
+ context.Orders
+ .Where(x => id_of_selected_models.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null))
+ foreach (var selectedModel in selectedModels)
+ {
+ //заказ, у которого должна быть сборка
+ var order = context.Orders.FirstOrDefault(x => x.Id == selectedModel.Id && x.Requests.Any(r => r.Request.Assembly != null));
+ //если у заказа нет сборки, то его не надо обрабатывать
+ if (order == null)
+ {
+ continue;
+ }
+
+ }
+ var ordersWithAssemblies = selectedModels
+
+ //возвращение тех заказов, кот. принадлежат пользователю и кот. имеют сборку в соответствующей заявке
+ return context.Orders
+ .Where(x => x.UserId == model.UserId && x.Requests.Any(r => r.Request.Assembly != null))
+ .Include(x => x.Requests)
+ .ThenInclude(x => x.Request)
+ .ThenInclude(x => x.Assembly)
+ .ToList()
+ .Select(x => new ReportOrderAssemblyViewModel
+ {
+ OrderId = x.Id,
+ DateCreateOrder = x.DateCreate,
+ OrderSum = x.Sum,
+ OrderStatus = x.Status,
+ AssemblyName = x.Requests.FirstOrDefault(r => r.Request.Assembly != null)?.Request.Assembly.AssemblyName,
+
+
+ })
+ .ToList();
+ }
+
//Поиск только по id, потому что другие поля не уникальные - нет смысла искать 1 элемент
public OrderViewModel? GetElement(OrderSearchModel model)
{
diff --git a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs
index e87e5d9..5ab8ec6 100644
--- a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs
+++ b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs
@@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements
{
public class RequestStorage : IRequestStorage
{
+ //id пользователя учитывается в GetFilteredList
public List GetFullList()
{
using var context = new ComputerShopDatabase();
diff --git a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs
index c52ef14..11aa5d4 100644
--- a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs
+++ b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs
@@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements
{
public class ShipmentStorage : IShipmentStorage
{
+ //id пользователя учитывается в GetFilteredList
public List GetFullList()
{
using var context = new ComputerShopDatabase();