diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs new file mode 100644 index 0000000..c8d2e8e --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs @@ -0,0 +1,161 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class ConferenceBookingLogic : IConferenceBookingLogic + { + private readonly ILogger _logger; + private readonly IConferenceBookingStorage _conferenceBookingStorage; + + public ConferenceBookingLogic(ILogger logger, IConferenceBookingStorage conferenceBookingStorage) + { + _logger = logger; + _conferenceBookingStorage = conferenceBookingStorage; + } + + public List? ReadList(ConferenceBookingSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + + var list = model == null ? _conferenceBookingStorage.GetFullList() : _conferenceBookingStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + + var element = _conferenceBookingStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public bool AddLunchToConferenceBooking(ConferenceBookingSearchModel model, ILunchModel lunch) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("AddLunchToConferenceBooking. NameHall:{NameHall}.Id:{ Id}", model.NameHall, model.Id); + var element = _conferenceBookingStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddLunchToConferenceBooking element not found"); + return false; + } + + _logger.LogInformation("AddLunchToConferenceBooking find. Id:{Id}", element.Id); + + element.ConferenceBookingLunches[lunch.Id] = lunch; + + _conferenceBookingStorage.Update(new() + { + Id = element.Id, + NameHall = element.NameHall, + BookingDate = element.BookingDate, + ConferenceId = element.ConferenceId, + HeadwaiterId = element.HeadwaiterId, + ConferenceBookingLunches = element.ConferenceBookingLunches + }); + + return true; + } + + public bool Create(ConferenceBookingBindingModel model) + { + CheckModel(model); + model.ConferenceBookingLunches = new(); + + var result = _conferenceBookingStorage.Insert(model); + + if (result == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(ConferenceBookingBindingModel model) + { + CheckModel(model); + + if (_conferenceBookingStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(ConferenceBookingBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + var result = _conferenceBookingStorage.Delete(model); + + if (result == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(ConferenceBookingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.NameHall)) + { + throw new ArgumentNullException("Нет названия конференции", nameof(model.NameHall)); + } + + _logger.LogInformation("ConferenceBooking. Id: { Id}", model.Id); + + } + } +} diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/LunchLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/LunchLogic.cs new file mode 100644 index 0000000..0cb41dc --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/LunchLogic.cs @@ -0,0 +1,130 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class LunchLogic : ILunchLogic + { + private readonly ILogger _logger; + private readonly ILunchStorage _lunchStorage; + + public LunchLogic(ILogger logger, ILunchStorage lunchStorage) + { + _logger = logger; + _lunchStorage = lunchStorage; + } + + public List? ReadList(LunchSearchModel? model) + { + _logger.LogInformation("ReadList. LunchName:{LunchName}.Id:{ Id}", model?.LunchName, model?.Id); + + var list = model == null ? _lunchStorage.GetFullList() : _lunchStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public LunchViewModel? ReadElement(LunchSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. LunchName:{LunchName}.Id:{Id}", model.LunchName, model.Id); + + var element = _lunchStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public bool Create(LunchBindingModel model) + { + CheckModel(model); + + var result = _lunchStorage.Insert(model); + + if (result == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(LunchBindingModel model) + { + CheckModel(model); + + if (_lunchStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(LunchBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + var result = _lunchStorage.Delete(model); + + if (result == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(LunchBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.LunchName)) + { + throw new ArgumentNullException("Нет имени обеда", nameof(model.LunchName)); + } + + if (model.LunchPrice < 0) + { + throw new ArgumentNullException("Стоимость обеда не может быть меньше 0", nameof(model.LunchPrice)); + } + + _logger.LogInformation("Lunch. LunchName:{LunchName}.LunchPrice:{ LunchPrice}. Id: { Id}", model.LunchName, model.LunchPrice, model.Id); + } + } +} diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs new file mode 100644 index 0000000..02c06c0 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/RoomLogic.cs @@ -0,0 +1,172 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class RoomLogic : IRoomLogic + { + private readonly ILogger _logger; + private readonly IRoomStorage _roomStorage; + + public RoomLogic(ILogger logger, IRoomStorage roomStorage) + { + _logger = logger; + _roomStorage = roomStorage; + } + + public List? ReadList(RoomSearchModel? model) + { + _logger.LogInformation("ReadList. RoomName:{RoomName}.Id:{ Id}", model?.RoomName, model?.Id); + + var list = model == null ? _roomStorage.GetFullList() : _roomStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public RoomViewModel? ReadElement(RoomSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. RoomName:{RoomName}.Id:{Id}", model.RoomName, model.Id); + + var element = _roomStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public bool AddLunchToRoom(RoomSearchModel model, ILunchModel lunch) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("AddLunchToRoom. RoomName:{RoomName}.Id:{ Id}", model.RoomName, model.Id); + var element = _roomStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddLunchToRoom element not found"); + return false; + } + + _logger.LogInformation("AddLunchToRoom find. Id:{Id}", element.Id); + + element.RoomLunches[lunch.Id] = lunch; + + _roomStorage.Update(new() + { + Id = element.Id, + RoomName = element.RoomName, + RoomPrice = element.RoomPrice, + RoomFrame = element.RoomFrame, + MealPlanId = element.MealPlanId, + HeadwaiterId = element.HeadwaiterId, + RoomLunches = element.RoomLunches, + }); + + return true; + } + + public bool Create(RoomBindingModel model) + { + CheckModel(model); + model.RoomLunches = new(); + + var result = _roomStorage.Insert(model); + + if (result == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(RoomBindingModel model) + { + CheckModel(model); + + if (_roomStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(RoomBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + var result = _roomStorage.Delete(model); + + if (result == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(RoomBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.RoomName)) + { + throw new ArgumentNullException("Нет названия комнате", nameof(model.RoomName)); + } + + + if (string.IsNullOrEmpty(model.RoomFrame)) + { + throw new ArgumentNullException("Нет названия корпусу", nameof(model.RoomFrame)); + } + + if (model.RoomPrice < 0) + { + throw new ArgumentNullException("Стоимость комнаты не может быть меньше 0", nameof(model.RoomPrice)); + } + + _logger.LogInformation("Room. RoomName:{RoomName}.RoomFrame:{ RoomFrame}.RoomPrice:{ RoomPrice}. Id: { Id}", model.RoomName, model.RoomFrame, model.RoomPrice, model.Id); + } + } +}