From 1a3305de60c3a1dee3ad9673ef4ea14432c8b899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sun, 24 Mar 2024 13:51:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B4=D0=BE=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicHeadwaiter.cs | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs new file mode 100644 index 0000000..0deaa5c --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs @@ -0,0 +1,161 @@ +using HotelBusinessLogic.OfficePackage.HelperModels; +using HotelBusinessLogic.OfficePackage; +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class ReportLogicHeadwaiter : IReportHeadwaiterLogic + { + private readonly IRoomStorage _roomStorage; + private readonly ILunchStorage _lunchStorage; + private readonly IConferenceBookingStorage _conferenceBookingStorage; + private readonly AbstractSaveToExcelHeadwaiter _saveToExcel; + private readonly AbstractSaveToWordHeadwaitre _saveToWord; + private readonly AbstractSaveToPdfHeadwaiter _saveToPdf; + + public ReportLogicHeadwaiter(IRoomStorage roomStorage, ILunchStorage lunchStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf) + { + _roomStorage = roomStorage; + _lunchStorage = lunchStorage; + _conferenceBookingStorage = conferenceBookingStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + public List GetLunchRoom(List Ids) + { + if (Ids == null) + { + return new List(); + } + + var rooms = _roomStorage.GetFullList(); + + List lunches = new List(); + foreach (var memId in Ids) + { + var res = _lunchStorage.GetElement(new LunchSearchModel { Id = memId }); + if (res != null) + { + lunches.Add(res); + } + } + + var list = new List(); + foreach (var lunch in lunches) + { + var record = new ReportLunchRoomViewModel + { + LunchName = lunch.LunchName, + Rooms = new List>() + }; + + foreach (var room in rooms) + { + if (room.RoomLunches.ContainsKey(lunch.Id)) + { + record.Rooms.Add(new Tuple(room.RoomName, room.RoomPrice)); + } + } + list.Add(record); + } + return list; + } + + public List GetLunches(ReportHeadwaiterBindingModel model) + { + var listAll = new List(); + + var listRooms = _roomStorage.GetFilteredList(new RoomSearchModel + { + HeadwaiterId = model.HeadwaiterId, + + }); + + foreach (var room in listRooms) + { + foreach (var m in room.RoomLunches.Values) + { + listAll.Add(new ReportLunchesViewModel + { + RoomName = room.RoomName, + RoomPrice = room.RoomPrice, + LunchName = m.LunchName, + LunchPrice = m.LunchPrice + }); + } + } + + var listConferenceBookings = _conferenceBookingStorage.GetFilteredList(new ConferenceBookingSearchModel + { + HeadwaiterId = model.HeadwaiterId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + + foreach (var conferenceBooking in listConferenceBookings) + { + foreach (var mp in conferenceBooking.ConferenceBookingLunches.Values) + { + listAll.Add(new ReportLunchesViewModel + { + LunchName = mp.LunchName, + LunchPrice = mp.LunchPrice, + NameHall = conferenceBooking.NameHall, + BookingDate = conferenceBooking.BookingDate + + }); + } + } + + return listAll; + } + + public void SaveLunchRoomToExcelFile(ReportHeadwaiterBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfoHeadwaiter + { + FileName = model.FileName, + Title = "Список номеров", + LunchRooms = GetLunchRoom(model.Ids) + }); + } + + public void SaveLunchRoomToWordFile(ReportHeadwaiterBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoHeadwaiter + { + FileName = model.FileName, + Title = "Список номеров", + LunchRooms = GetLunchRoom(model.Ids) + }); + } + + public void SaveLunchesToPdfFile(ReportHeadwaiterBindingModel model) + { + if (model.DateFrom == null) + { + throw new ArgumentException("Дата начала не задана"); + } + + if (model.DateTo == null) + { + throw new ArgumentException("Дата окончания не задана"); + } + + _saveToPdf.CreateDoc(new PdfInfoHeadwaiter + { + FileName = model.FileName, + Title = "Список обедов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Lunches = GetLunches(model) + }); + } + } +}