PIAPS_CW/BusinessLogic/BusinessLogic/ReportLogic.cs
2024-06-24 18:53:31 +04:00

75 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BusinessLogic.OfficePackage.HelperModels;
using BusinessLogic.OfficePackage;
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using Contracts.SearchModels;
namespace BusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IProductStorage _productStorage;
private readonly ISupplyStorage _supplyStorage;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf)
{
_productStorage = productStorage;
_supplyStorage = supplyStorage;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
public List<ReportSupplyProductViewModel> GetSupplyProduct()
{
var products = _productStorage.GetFullList();
var supplies = _supplyStorage.GetFullList();
var list = new List<ReportSupplyProductViewModel>();
foreach (var supply in supplies)
{
var record = new ReportSupplyProductViewModel
{
SupplyName = supply.Name,
Products = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var product in products)
{
if (supply.Products.ContainsKey(product.Id))
{
record.Products.Add(new Tuple<string, int>(product.Name, supply.Products[product.Id].Item2));
record.TotalCount += supply.Products[product.Id].Item2;
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveSuppliesToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Отчёт о поставке",
Date = model.Date!.Value,
Supply = _supplyStorage.GetElement(new SupplySearchModel()
{
Id = model.SupplyId,
})
});
}
}
}