diff --git a/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs
index 3ef3fb0..6b16867 100644
--- a/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs
+++ b/ComputerShopBusinessLogic/BusinessLogics/ReportImplementerLogic.cs
@@ -27,15 +27,26 @@ namespace ComputerShopBusinessLogic.BusinessLogics
/// Отчёт для 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,
+ public List GetReportOrdersAssemblies(List selectedOrders)
+ {
+ return _orderStorage.GetOrdersAssemblies(selectedOrders);
+ }
+ ///
+ /// Отчёт для почты/страницы
+ ///
+ ///
+ public List GetReportOrdersByDates(UserSearchModel currentUser, ReportBindingModel report)
+ {
+ return _orderStorage.GetOrdersInfoByDates(currentUser, report);
+ }
- });
+ public void SaveReportOrderAssembliesToWordFile(ReportBindingModel model)
+ {
+ throw new NotImplementedException();
+ }
+ public void SaveReportOrderAssembliesToExcelFile(ReportBindingModel model)
+ {
+ throw new NotImplementedException();
}
}
}
diff --git a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs
index 9198ee4..04360c2 100644
--- a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs
+++ b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs
@@ -1,4 +1,5 @@
using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using System;
using System.Collections.Generic;
@@ -14,15 +15,15 @@ namespace ComputerShopContracts.BusinessLogicContracts
/// Получение отчёта для word/excel
///
///
- List GetOrderAssemblies();
+ List GetReportOrdersAssemblies(List selectedOrders);
///
/// Получение отчёта для почты
///
///
- List GetOrderRequestAssemblies();
- void SaveOrderAssembliesToWordFile(ReportBindingModel model);
+ List GetReportOrdersByDates(UserSearchModel currentUser, ReportBindingModel report);
+ void SaveReportOrderAssembliesToWordFile(ReportBindingModel model);
- void SaveOrderAssembliesToExcelFile(ReportBindingModel model);
+ void SaveReportOrderAssembliesToExcelFile(ReportBindingModel model);
}
}
diff --git a/ComputerShopContracts/StorageContracts/IOrderStorage.cs b/ComputerShopContracts/StorageContracts/IOrderStorage.cs
index e2ec1f1..607c173 100644
--- a/ComputerShopContracts/StorageContracts/IOrderStorage.cs
+++ b/ComputerShopContracts/StorageContracts/IOrderStorage.cs
@@ -17,6 +17,8 @@ namespace ComputerShopContracts.StorageContracts
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
- List GetReportWithAssembly(List model);
+ //получение данных о заказах для отчётов
+ List GetOrdersAssemblies(List model);
+ List GetOrdersInfoByDates(UserSearchModel currentUser, ReportBindingModel report);
}
}
diff --git a/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs
index 8c457c5..50b3125 100644
--- a/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs
+++ b/ComputerShopContracts/ViewModels/ReportOrderAssemblyViewModel.cs
@@ -1,4 +1,5 @@
using ComputerShopDataModels.Enums;
+using ComputerShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,15 +10,13 @@ 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; }
+ //данные о сборках
+ public List<(string AssemblyName, string AssemblyCategory, double AssemblyPrice)> Assemblies { get; set; }
}
}
diff --git a/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs
deleted file mode 100644
index fd9027d..0000000
--- a/ComputerShopContracts/ViewModels/ReportOrderRequestAssemblyViewModel.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-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/ComputerShopContracts/ViewModels/ReportOrdersViewModel.cs b/ComputerShopContracts/ViewModels/ReportOrdersViewModel.cs
new file mode 100644
index 0000000..baa5bb2
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/ReportOrdersViewModel.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 ReportOrdersViewModel
+ {
+ public int OrderId { get; set; }
+ public DateTime DateCreateOrder { get; set; }
+ public double OrderSum { get; set; }
+ public OrderStatus OrderStatus { get; set; }
+
+ //данные заявок
+ public List<(int RequestId, string ClientFIO, DateTime DateRequest)> Requests { get; set; }
+
+ //данные сборок
+ public List<(string AssemblyName, string AssemblyCategory, double AssemblyPrice)> Assemblies { get; set; }
+ }
+}
diff --git a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
index 3999933..580be1a 100644
--- a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
+++ b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs
@@ -3,6 +3,7 @@ using ComputerShopContracts.SearchModels;
using ComputerShopContracts.StorageContracts;
using ComputerShopContracts.ViewModels;
using ComputerShopDatabaseImplement.Models;
+using ComputerShopDataModels.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
@@ -72,8 +73,8 @@ namespace ComputerShopDatabaseImplement.Implements
.ToList();
}
- //получение данных для отчёта сборок по выбранным заказам
- public List GetReportWithAssembly(List selectedModels)
+ //получение данных сборок по выбранным заказам для отчёта (doc/xls)
+ public List GetOrdersAssemblies(List selectedModels)
{
using var context = new ComputerShopDatabase();
//id заказов, которые выбрал пользователь
@@ -84,30 +85,6 @@ namespace ComputerShopDatabaseImplement.Implements
.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
{
@@ -115,9 +92,28 @@ namespace ComputerShopDatabaseImplement.Implements
DateCreateOrder = x.DateCreate,
OrderSum = x.Sum,
OrderStatus = x.Status,
- AssemblyName = x.Requests.FirstOrDefault(r => r.Request.Assembly != null)?.Request.Assembly.AssemblyName,
-
+ Assemblies = x.Requests.Select(r => (r.Request.Assembly.AssemblyName, r.Request.Assembly.Category, r.Request.Assembly.Price)).ToList(),
+ })
+ .ToList();
+ }
+ //получение заказов (все, что создал сам пользователь) за период с расшифровкой по заявкам и сборкам для отчёта (почта/страница)
+ public List GetOrdersInfoByDates(UserSearchModel currentUser, ReportBindingModel report)
+ {
+ using var context = new ComputerShopDatabase();
+ return context.Orders.Include(x => x.Requests)
+ .ThenInclude(x => x.Request)
+ .ThenInclude(x => x.Assembly)
+ .Where(x => x.UserId == currentUser.Id && x.DateCreate >= report.DateFrom && x.DateCreate <= report.DateTo)
+ .ToList()
+ .Select(x => new ReportOrdersViewModel
+ {
+ OrderId = x.Id,
+ DateCreateOrder = x.DateCreate,
+ OrderSum = x.Sum,
+ OrderStatus = x.Status,
+ Requests = x.Requests.Select(r => (r.Request.Id, r.Request.ClientFIO, r.Request.DateRequest)).ToList(),
+ Assemblies = x.Requests.Select(r => (r.Request.Assembly.AssemblyName, r.Request.Assembly.Category, r.Request.Assembly.Price)).ToList(),
})
.ToList();
}
diff --git a/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopDatabaseImplement/Models/Order.cs
index 11476f8..2b81b1a 100644
--- a/ComputerShopDatabaseImplement/Models/Order.cs
+++ b/ComputerShopDatabaseImplement/Models/Order.cs
@@ -64,9 +64,9 @@ namespace ComputerShopDatabaseImplement.Models
}
//отдельный метод изменения стоимости заказа (+ или -) на стоимость сборки внутри заявки (после действий с заявками, кот. привязаны к заказу)
- public void ChangeSum(double cost_of_assembly, bool justUpdate = false)
+ public void ChangeSum(double price_of_assembly, bool justUpdate = false)
{
- Sum += cost_of_assembly;
+ Sum += price_of_assembly;
}
public OrderViewModel GetViewModel => new()
diff --git a/ComputerShopDatabaseImplement/Models/Request.cs b/ComputerShopDatabaseImplement/Models/Request.cs
index 84cd5c6..d23b86d 100644
--- a/ComputerShopDatabaseImplement/Models/Request.cs
+++ b/ComputerShopDatabaseImplement/Models/Request.cs
@@ -95,7 +95,7 @@ namespace ComputerShopDatabaseImplement.Models
{
var currentRequest = context.Requests.First(x => x.Id == Id);
//стоимость сборки, связанной с заявкой (или 0, если заявка не связана со сборкой)
- double cost_of_assembly = (currentRequest.Assembly.Price != null) ? currentRequest.Assembly.Price : 0;
+ double price_of_assembly = (currentRequest.Assembly.Price != null) ? currentRequest.Assembly.Price : 0;
var requestOrders = context.RequestOrders.Where(x => x.RequestId == model.Id).ToList();
@@ -108,7 +108,7 @@ namespace ComputerShopDatabaseImplement.Models
context.RequestOrders.Remove(delOrder);
var order = context.Orders.First(x => x.Id == delOrder.OrderId);
//вычитание из стоимости соответствующего заказа стоимость соответствующей сборки
- order.ChangeSum(-cost_of_assembly);
+ order.ChangeSum(-price_of_assembly);
context.SaveChanges();
}
}
@@ -123,7 +123,7 @@ namespace ComputerShopDatabaseImplement.Models
Order = order
});
//увеличение стоимости заказа, с которым связываем заявку, на стоимость сборки
- order.ChangeSum(cost_of_assembly);
+ order.ChangeSum(price_of_assembly);
context.SaveChanges();
}
_requestOrders = null;
@@ -134,7 +134,7 @@ namespace ComputerShopDatabaseImplement.Models
public void ConnectAssembly(ComputerShopDatabase context, RequestBindingModel model)
{
//стоимость старой сборки (или 0, если её не было)
- double cost_of_old_assembly = (Assembly.Price != null) ? Assembly.Price : 0;
+ double price_of_old_assembly = (Assembly.Price != null) ? Assembly.Price : 0;
AssemblyId = model.AssemblyId;
Assembly = context.Assemblies.First(x => x.Id == model.AssemblyId);
@@ -143,7 +143,7 @@ namespace ComputerShopDatabaseImplement.Models
{
var connectedOrder = context.Orders.First(x => x.Id == request_order.Key);
//вычитание из стоимости заказа старой сборки
- connectedOrder.ChangeSum(-cost_of_old_assembly);
+ connectedOrder.ChangeSum(-price_of_old_assembly);
//прибавление стоимости новой сборки
connectedOrder.ChangeSum(Assembly.Price);
context.SaveChanges();