CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportLogic.cs

89 lines
2.9 KiB
C#

using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
using ElectronicsShopBusinessLogic.OfficePackage;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IProductStorage _productStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
public ReportLogic(IProductStorage productStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord)
{
_productStorage = productStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
}
public List<ReportProductsViewModel> GetProduct()
{
var productsList = _productStorage.GetFullList();
var list = new List<ReportProductsViewModel>();
foreach (var product in productsList)
{
var record = new ReportProductsViewModel
{
CostItemID = product.CostItemID,
ProductName = product.ProductName,
Price = product.Price,
CostItemName = product.CostItemName,
};
list.Add(record);
}
return list;
}
public List<ReportOrdersVeiwModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
.Select(x => new ReportOrdersVeiwModel
{
ID = x.ID,
ClientID = x.ClientID,
DateCreate = x.DateCreate,
ProductList = x.ProductList,
Sum = x.Sum
})
.ToList();
}
public void SaveListToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список продуктов",
ListProduct = _productStorage.GetFullList()
});
}
public void SaveProductToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список Заказов",
Orders = GetOrders(model),// мейби нет
});
}
}
}