names fixed

This commit is contained in:
VictoriaPresnyakova 2023-03-20 14:13:00 +04:00
parent 19e7195e9a
commit 48603bba79
3 changed files with 134 additions and 3 deletions

View File

@ -0,0 +1,131 @@
using JewelryStoreBusinessLogic.OfficePackage;
using JewelryStoreBusinessLogic.OfficePackage.HelperModels;
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JewelryStoreBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
private readonly IJewelStorage _jewelStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IJewelStorage jewelStorage, IComponentStorage
componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
AbstractSaveToPdf saveToPdf)
{
_jewelStorage = jewelStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
public List<ReportJewelComponentViewModel> GetJewelComponent()
{
var components = _componentStorage.GetFullList();
var jewels = _jewelStorage.GetFullList();
var list = new List<ReportJewelComponentViewModel>();
foreach (var component in components)
{
var record = new ReportJewelComponentViewModel
{
ComponentName = component.ComponentName,
Jewels = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var jewel in jewels)
{
if (jewel.JewelComponents.ContainsKey(component.Id))
{
record.Jewels.Add(new Tuple<string,
int>(jewel.JewelName, jewel.JewelComponents[component.Id].Item2));
record.TotalCount +=
jewel.JewelComponents[component.Id].Item2;
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel
{
DateFrom
= model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
JewelName = x.JewelName,
Sum = x.Sum
})
.ToList();
}
/// <summary>
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveComponentsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список компонент",
Components = _componentStorage.GetFullList()
});
}
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveJewelComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список компонент",
JewelComponents = GetJewelComponent()
});
}
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}

View File

@ -11,7 +11,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public List<ReportJewelComponentViewModel> ProductJewels public List<ReportJewelComponentViewModel> JewelComponents
{ {
get; get;
set; set;

View File

@ -8,8 +8,8 @@ namespace JewelryStoreContracts.ViewModels
{ {
public class ReportJewelComponentViewModel public class ReportJewelComponentViewModel
{ {
public string JewelName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
public int TotalCount { get; set; } public int TotalCount { get; set; }
public List<Tuple<string, int>> Products { get; set; } = new(); public List<Tuple<string, int>> Jewels { get; set; } = new();
} }
} }