diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index a4ad3ce..69aa1bd 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -11,11 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelCont EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{E34AD471-B0B3-473F-9A52-E7BB20CA1081}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{E34AD471-B0B3-473F-9A52-E7BB20CA1081}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelRestApi", "HotelRestApi\HotelRestApi.csproj", "{1D7D511E-66E9-480F-92B9-9E1A33916DCF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelRestApi", "HotelRestApi\HotelRestApi.csproj", "{1D7D511E-66E9-480F-92B9-9E1A33916DCF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelHeadwaiterApp", "HostrelHeadwaiterApp\HotelHeadwaiterApp.csproj", "{9F25F6AF-2887-467D-B4F1-E3805772124D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelHeadwaiterApp", "HostrelHeadwaiterApp\HotelHeadwaiterApp.csproj", "{9F25F6AF-2887-467D-B4F1-E3805772124D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +39,18 @@ Global {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.Build.0 = Release|Any CPU + {E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Release|Any CPU.Build.0 = Release|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Release|Any CPU.Build.0 = Release|Any CPU + {9F25F6AF-2887-467D-B4F1-E3805772124D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F25F6AF-2887-467D-B4F1-E3805772124D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F25F6AF-2887-467D-B4F1-E3805772124D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F25F6AF-2887-467D-B4F1-E3805772124D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs index 6678497..e6a00a7 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs @@ -1,35 +1,120 @@ using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; namespace HotelBusinessLogic.BusinessLogics { public class ConferenceLogic : IConferenceLogic { + private readonly ILogger _logger; + private readonly IConferenceStorage _conferenceStorage; + + public ConferenceLogic(ILogger logger, IConferenceStorage conferenceStorage) + { + _logger = logger; + _conferenceStorage = conferenceStorage; + } public bool Create(ConferenceBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + + if (_conferenceStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; } public bool Delete(ConferenceBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_conferenceStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; } public ConferenceViewModel? ReadElement(ConferenceSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ConferenceName:{ConferenceName}.Id:{Id}", model.ConferenceName, model.Id); + + var element = _conferenceStorage.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(ConferenceSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. ConferenceName:{ConferenceName}.Id:{ Id}", model?.ConferenceName, model?.Id); + + var list = model == null ? _conferenceStorage.GetFullList() : _conferenceStorage.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(ConferenceBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + + if (_conferenceStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(ConferenceBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.ConferenceName)) + { + throw new ArgumentNullException("Нет названия конференции", nameof(model.ConferenceName)); + } + + _logger.LogInformation("Conference. ConferenceName:{ConferenceName}.StartDate:{ StartDate}. Id: { Id}", model.ConferenceName, model.StartDate, model.Id); } } } diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs index 2a54d76..7cff2b8 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs @@ -1,35 +1,135 @@ using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; namespace HotelBusinessLogic.BusinessLogics { public class MealPlanLogic : IMealPlanLogic { + private readonly ILogger _logger; + private readonly IMealPlanStorage _mealPlanStorage; + + public MealPlanLogic(ILogger logger, IMealPlanStorage mealPlanStorage) + { + _logger = logger; + _mealPlanStorage = mealPlanStorage; + } public bool Create(MealPlanBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + + if (_mealPlanStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; } public bool Delete(MealPlanBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_mealPlanStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; } public MealPlanViewModel? ReadElement(MealPlanSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. MealPlanName:{MealPlanName}.Id:{Id}", model.MealPlanName, model.Id); + + var element = _mealPlanStorage.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(MealPlanSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. MealPlanName:{MealPlanName}.Id:{ Id}", model?.MealPlanName, model?.Id); + + var list = model == null ? _mealPlanStorage.GetFullList() : _mealPlanStorage.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(MealPlanBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + + if (_mealPlanStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(MealPlanBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.MealPlanName)) + { + throw new ArgumentNullException("Нет названия плана питания", nameof(model.MealPlanName)); + } + + if (model.MealPlanPrice<0) + { + throw new ArgumentNullException("Стоимость плана питания не может быть меньше 0", nameof(model.MealPlanPrice)); + } + + _logger.LogInformation("MealPlan. MealPlanName:{MealPlanName}.MealPlanPrice:{ MealPlanPrice}. Id: { Id}", model.MealPlanName, model.MealPlanPrice, model.Id); + + var element = _mealPlanStorage.GetElement(new MealPlanSearchModel + { + MealPlanName = model.MealPlanName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("План питания с таким названием уже есть"); + } } } } diff --git a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj index e500d7e..52fb8ae 100644 --- a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj +++ b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj @@ -6,10 +6,6 @@ enable - - - - @@ -18,4 +14,8 @@ + + + +