недоделанное, с ошибками
This commit is contained in:
parent
a97287aaae
commit
56866b458c
@ -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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отчёт для doc/xls
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ReportOrderAssemblyViewModel> GetOrderAssemblies(List<OrderSearchModel> selectedOrders) {
|
||||||
|
//!!!исправить на filteredList
|
||||||
|
return _orderStorage.GetReportWithAssembly(selectedOrders).Select(x => new ReportOrderAssemblyViewModel
|
||||||
|
{
|
||||||
|
OrderId = x.Id,
|
||||||
|
DateCreateOrder = x.DateCreate,
|
||||||
|
OrderSum = x.Sum,
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ComputerShopContracts/BindingModels/ReportBindingModel.cs
Normal file
15
ComputerShopContracts/BindingModels/ReportBindingModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение отчёта для word/excel
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportOrderAssemblyViewModel> GetOrderAssemblies();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение отчёта для почты
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportOrderRequestAssemblyViewModel> GetOrderRequestAssemblies();
|
||||||
|
void SaveOrderAssembliesToWordFile(ReportBindingModel model);
|
||||||
|
|
||||||
|
void SaveOrderAssembliesToExcelFile(ReportBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -17,5 +17,6 @@ namespace ComputerShopContracts.StorageContracts
|
|||||||
OrderViewModel? Insert(OrderBindingModel model);
|
OrderViewModel? Insert(OrderBindingModel model);
|
||||||
OrderViewModel? Update(OrderBindingModel model);
|
OrderViewModel? Update(OrderBindingModel model);
|
||||||
OrderViewModel? Delete(OrderBindingModel model);
|
OrderViewModel? Delete(OrderBindingModel model);
|
||||||
|
List<OrderViewModel> GetReportWithAssembly(List<OrderSearchModel> model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,11 +10,13 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Implements
|
namespace ComputerShopDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
|
//id пользователя учитывается в GetFilteredList
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new ComputerShopDatabase();
|
using var context = new ComputerShopDatabase();
|
||||||
@ -70,6 +72,56 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//получение данных для отчёта сборок по выбранным заказам
|
||||||
|
public List<ReportOrderAssemblyViewModel> GetReportWithAssembly(List<OrderSearchModel> selectedModels)
|
||||||
|
{
|
||||||
|
using var context = new ComputerShopDatabase();
|
||||||
|
//id заказов, которые выбрал пользователь
|
||||||
|
List<int?> 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 элемент
|
//Поиск только по id, потому что другие поля не уникальные - нет смысла искать 1 элемент
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public class RequestStorage : IRequestStorage
|
public class RequestStorage : IRequestStorage
|
||||||
{
|
{
|
||||||
|
//id пользователя учитывается в GetFilteredList
|
||||||
public List<RequestViewModel> GetFullList()
|
public List<RequestViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new ComputerShopDatabase();
|
using var context = new ComputerShopDatabase();
|
||||||
|
@ -14,6 +14,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public class ShipmentStorage : IShipmentStorage
|
public class ShipmentStorage : IShipmentStorage
|
||||||
{
|
{
|
||||||
|
//id пользователя учитывается в GetFilteredList
|
||||||
public List<ShipmentViewModel> GetFullList()
|
public List<ShipmentViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new ComputerShopDatabase();
|
using var context = new ComputerShopDatabase();
|
||||||
|
Loading…
Reference in New Issue
Block a user