This commit is contained in:
Кашин Максим 2023-04-07 01:49:47 +04:00
commit 98352f0c47
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,124 @@
using DocumentFormat.OpenXml.Bibliography;
using HotelBusinessLogic.OfficePackage;
using HotelBusinessLogic.OfficePackage.HelperModels;
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using System.Reflection;
namespace HotelBusinessLogic.BusinessLogics
{
public class ReportLogicOrganiser : IReportOrganiserLogic
{
private readonly IMealPlanStorage _mealPlanStorage;
private readonly IMemberStorage _memberStorage;
private readonly IConferenceStorage _conferenceStorage;
private readonly AbstractSaveToExcelOrganiser _saveToExcel;
private readonly AbstractSaveToWordOrganiser _saveToWord;
private readonly AbstractSaveToPdfOrganiser _saveToPdf;
public ReportLogicOrganiser(IMealPlanStorage mealPlanStorage, IMemberStorage memberStorage, IConferenceStorage conferenceStorage, AbstractSaveToExcelOrganiser saveToExcel, AbstractSaveToWordOrganiser saveToWord, AbstractSaveToPdfOrganiser saveToPdf)
{
_mealPlanStorage = mealPlanStorage;
_memberStorage = memberStorage;
_conferenceStorage = conferenceStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportMemberConferenceViewModel> GetMemberConference()
{
var conferences = _conferenceStorage.GetFullList();
var members = _memberStorage.GetFullList();
var list = new List<ReportMemberConferenceViewModel>();
foreach (var member in members)
{
var record = new ReportMemberConferenceViewModel
{
MemberFIO = member.MemberFIO,
Conferences = new List<Tuple<string, DateTime>>()
};
foreach (var conference in conferences)
{
if (conference.ConferenceMembers.ContainsKey(member.Id))
{
record.Conferences.Add(new Tuple<string, DateTime>(conference.ConferenceName, conference.StartDate));
}
}
list.Add(record);
}
return list;
}
public List<ReportMembersViewModel> GetMembers(ReportBindingModel model)
{
var listAll = new List<ReportMembersViewModel>();
var listСonferences = _conferenceStorage.GetFilteredList(new ConferenceSearchModel
{
OrganiserId = model.OrganiserId,
DateFrom = model.DateFrom,
DateTo = model.DateTo
});
foreach (var conference in listСonferences)
{
foreach (var c in conference.ConferenceMembers)
{
listAll.Add(new ReportMembersViewModel
{
StartDate = conference.StartDate,
ConferenceName = conference.ConferenceName,
MemberFIO=c.Value.MemberFIO
});
}
}
var listMealPlans = _mealPlanStorage.GetFilteredList(new MealPlanSearchModel());
foreach (var mealPlan in listMealPlans)
{
listAll.Add(new ReportMembersViewModel
{
MealPlanName = mealPlan.MealPlanName,
MealPlanPrice = mealPlan.MealPlanPrice
});
}
return listAll;
}
public void SaveMemberConferenceToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfoOrganiser
{
FileName = model.FileName,
Title = "Список изделий",
MemberConferences = GetMemberConference()
});
}
public void SaveMemberConferenceToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoOrganiser
{
FileName = model.FileName,
Title = "Список участников",
MemberConferences = GetMemberConference()
}) ;
}
public void SaveMembersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfoOrganiser
{
FileName = model.FileName,
Title = "Список участников",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Members = GetMembers(model)
});
}
}
}

View File

@ -5,5 +5,6 @@
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int OrganiserId { get; set; }
}
}