Contractor: Reports
This commit is contained in:
parent
7bc1dc6adf
commit
2f7dac91e4
@ -23,7 +23,7 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
|
||||
public List<ReportPCByDateViewModel> GetPCs(ReportBindingModel model)
|
||||
public List<ReportPCByDateViewModel> GetPCs(ReportDateBindingModel model)
|
||||
{
|
||||
return _pcStorage.GetFilteredList(new PCSearchModel
|
||||
{
|
||||
@ -38,7 +38,7 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportProductByDateViewModel> GetProducts(ReportBindingModel model)
|
||||
public List<ReportProductByDateViewModel> GetProducts(ReportDateBindingModel model)
|
||||
{
|
||||
return _productStorage.GetFilteredList(new ProductSearchModel
|
||||
{
|
||||
@ -54,12 +54,12 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
|
||||
}
|
||||
|
||||
public void SaveProductsToPdfFile(ReportBindingModel model)
|
||||
public void SaveProductsToPdfFile(ReportDateBindingModel model)
|
||||
{
|
||||
//will be implemented in the future!
|
||||
}
|
||||
|
||||
public void SavePCsToPdfFile(ReportBindingModel model)
|
||||
public void SavePCsToPdfFile(ReportDateBindingModel model)
|
||||
{
|
||||
//will be implemented in the future!
|
||||
}
|
||||
|
125
ComputerStoreBusinessLogic/BusinessLogic/ReportOrderLogic.cs
Normal file
125
ComputerStoreBusinessLogic/BusinessLogic/ReportOrderLogic.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ReportOrderLogic : IReportOrderLogic
|
||||
{
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IConsignmentStorage _consignmentStorage;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
private readonly IPCStorage _pcStorage;
|
||||
|
||||
public ReportOrderLogic(
|
||||
IOrderStorage orderStorage,
|
||||
IConsignmentStorage consignmentStorage,
|
||||
IRequestStorage requestStorage,
|
||||
IPCStorage pcStorage)
|
||||
{
|
||||
_orderStorage = orderStorage;
|
||||
_consignmentStorage = consignmentStorage;
|
||||
_requestStorage = requestStorage;
|
||||
_pcStorage = pcStorage;
|
||||
}
|
||||
|
||||
public ReportOrderViewModel GetPCsByOrders(ReportOrderBindingModel model)
|
||||
{
|
||||
var report = new ReportOrderViewModel();
|
||||
List<OrderViewModel> orders = new List<OrderViewModel>();
|
||||
|
||||
foreach (var orderSearch in model.Orders)
|
||||
{
|
||||
var element = _orderStorage.GetElement(orderSearch);
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Selected order is not find.");
|
||||
}
|
||||
orders.Add(element);
|
||||
}
|
||||
|
||||
foreach (var order in orders)
|
||||
{
|
||||
if (order.OrderRequests == null) { continue; }
|
||||
report.OrderPCs.Add(order.ID, (new(), new()));
|
||||
|
||||
foreach (var requestRaw in order.OrderRequests)
|
||||
{
|
||||
var request = _requestStorage.GetElement(new RequestSearchModel { ID = requestRaw.ID });
|
||||
if (request == null) { throw new Exception("Request for report is not find."); }
|
||||
|
||||
var pc = _pcStorage.GetElement(new PCSearchModel { ID = request.PCID });
|
||||
if (pc == null) { throw new Exception("PC for report is not find."); }
|
||||
|
||||
report.OrderPCs[order.ID].Item1.Add(request);
|
||||
report.OrderPCs[order.ID].Item2.Add(pc);
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
public ReportOrderByDateViewModel GetOrdersByDate(ReportDateBindingModel model)
|
||||
{
|
||||
var report = new ReportOrderByDateViewModel();
|
||||
var orders = _orderStorage.GetFullList();
|
||||
foreach (var order in orders)
|
||||
{
|
||||
if (order.OrderConsignments == null && order.OrderRequests == null) { continue; }
|
||||
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
report.OrderConsignmentsAndRequests.Add(order.ID, (new(), new()));
|
||||
|
||||
if (order.OrderConsignments != null)
|
||||
{
|
||||
foreach (var consignmentRaw in order.OrderConsignments)
|
||||
{
|
||||
var consignment = _consignmentStorage.GetElement(new ConsignmentSearchModel { ID = consignmentRaw.ID });
|
||||
if (consignment == null)
|
||||
{
|
||||
throw new Exception("Consignment for create report is not found");
|
||||
}
|
||||
report.OrderConsignmentsAndRequests[order.ID].Item1.Add(consignment);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.OrderRequests != null)
|
||||
{
|
||||
foreach (var requestRaw in order.OrderRequests)
|
||||
{
|
||||
var request = _requestStorage.GetElement(new RequestSearchModel { ID = requestRaw.ID });
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("Request for create report is not found");
|
||||
}
|
||||
report.OrderConsignmentsAndRequests[order.ID].Item2.Add(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
public void SaveOrdersToExcelFile(ReportOrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportDateBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveOrdersToWordFile(ReportOrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
public class ReportDateBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
@ -0,0 +1,15 @@
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ReportOrderBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<OrderSearchModel> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -10,10 +10,10 @@ namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IEmployeeReportByDateLogic
|
||||
{
|
||||
List<ReportProductByDateViewModel> GetProducts(ReportBindingModel model);
|
||||
List<ReportPCByDateViewModel> GetPCs(ReportBindingModel model);
|
||||
List<ReportProductByDateViewModel> GetProducts(ReportDateBindingModel model);
|
||||
List<ReportPCByDateViewModel> GetPCs(ReportDateBindingModel model);
|
||||
|
||||
void SaveProductsToPdfFile(ReportBindingModel model);
|
||||
void SavePCsToPdfFile(ReportBindingModel model);
|
||||
void SaveProductsToPdfFile(ReportDateBindingModel model);
|
||||
void SavePCsToPdfFile(ReportDateBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IReportOrderLogic
|
||||
{
|
||||
ReportOrderViewModel GetPCsByOrders(ReportOrderBindingModel model);
|
||||
ReportOrderByDateViewModel GetOrdersByDate(ReportDateBindingModel model);
|
||||
void SaveOrdersToWordFile(ReportOrderBindingModel model);
|
||||
void SaveOrdersToExcelFile(ReportOrderBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportDateBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportOrderByDateViewModel
|
||||
{
|
||||
public Dictionary<int, (List<ConsignmentViewModel>, List<RequestViewModel>)> OrderConsignmentsAndRequests { get; set; } = new();
|
||||
}
|
||||
}
|
13
ComputerStoreContracts/ViewModels/ReportOrderViewModel.cs
Normal file
13
ComputerStoreContracts/ViewModels/ReportOrderViewModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportOrderViewModel
|
||||
{
|
||||
public Dictionary<int, (List<RequestViewModel>, List<PCViewModel>)> OrderPCs { get; set; } = new();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user