From 71527f67a34f4d916cc51ad3f2945b5be740d22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Fri, 7 Apr 2023 00:34:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20ConferenceBookingLogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ConferenceBookingLogic.cs | 121 ++++++++++++++++++ .../IConferenceBookingLogic.cs | 2 +- 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs new file mode 100644 index 0000000..6641d02 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs @@ -0,0 +1,121 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 bool Create(ConferenceBookingBindingModel model) + { + CheckModel(model); + + if (_conferenceBookingStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(ConferenceBookingBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_conferenceBookingStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + 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 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 bool Update(ConferenceBookingBindingModel model) + { + CheckModel(model); + + if (_conferenceBookingStorage.Update(model) == null) + { + _logger.LogWarning("Update 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; + } + + _logger.LogInformation("ConferenceBooking. Id: { Id}", model.Id); + + } + } +} diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs index 7ab0d31..aefd781 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs @@ -7,7 +7,7 @@ namespace HotelContracts.BusinessLogicsContracts public interface IConferenceBookingLogic { List? ReadList(ConferenceBookingSearchModel? model); - MealPlanViewModel? ReadElement(MealPlanSearchModel model); + ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model); bool Create(ConferenceBookingBindingModel model); bool Update(ConferenceBookingBindingModel model); bool Delete(ConferenceBookingBindingModel model);