From 37eb5c1c65340c7463266ae297e077b9a94df5bc Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Fri, 7 Apr 2023 01:44:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=B4=D0=BE=D1=87=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicOrganiser.cs | 124 ++++++++++++++++++ .../BindingModels/ReportBindingModel.cs | 1 + 2 files changed, 125 insertions(+) create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs new file mode 100644 index 0000000..fdcb5bc --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicOrganiser.cs @@ -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 GetMemberConference() + { + var conferences = _conferenceStorage.GetFullList(); + var members = _memberStorage.GetFullList(); + var list = new List(); + foreach (var member in members) + { + var record = new ReportMemberConferenceViewModel + { + MemberFIO = member.MemberFIO, + Conferences = new List>() + }; + foreach (var conference in conferences) + { + if (conference.ConferenceMembers.ContainsKey(member.Id)) + { + record.Conferences.Add(new Tuple(conference.ConferenceName, conference.StartDate)); + } + } + list.Add(record); + } + return list; + } + + public List GetMembers(ReportBindingModel model) + { + var listAll = new List(); + + 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) + }); + } + } +} diff --git a/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs b/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs index bde3946..d1b48a1 100644 --- a/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs +++ b/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs @@ -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; } } }