From 0f22fca83f1a0f05e807f7e33b778f566262ab0c Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Thu, 6 Apr 2023 17:58:51 +0400 Subject: [PATCH] =?UTF-8?q?BusinessLogic=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B0=D0=BD=D0=B8=D0=B7=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hotel/Hotel.sln | 8 +- .../BusinessLogics/ConferenceLogic.cs | 35 ++++ .../BusinessLogics/MealPlanLogic.cs | 35 ++++ .../BusinessLogics/MemberLogic.cs | 125 +++++++++++++ .../BusinessLogics/OrganiserLogic.cs | 171 ++++++++++++++++++ .../HotelBusinessLogic.csproj | 21 +++ 6 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/MemberLogic.cs create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/OrganiserLogic.cs create mode 100644 Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index 22461ca..b71a99c 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataModels", "HotelDat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{234B3526-A74E-43D2-9333-E74B4FF9A356}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}" +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}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ 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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs new file mode 100644 index 0000000..6678497 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs @@ -0,0 +1,35 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.ViewModels; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class ConferenceLogic : IConferenceLogic + { + public bool Create(ConferenceBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(ConferenceBindingModel model) + { + throw new NotImplementedException(); + } + + public ConferenceViewModel? ReadElement(ConferenceSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(ConferenceSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(ConferenceBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs new file mode 100644 index 0000000..2a54d76 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs @@ -0,0 +1,35 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.ViewModels; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class MealPlanLogic : IMealPlanLogic + { + public bool Create(MealPlanBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(MealPlanBindingModel model) + { + throw new NotImplementedException(); + } + + public MealPlanViewModel? ReadElement(MealPlanSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(MealPlanSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(MealPlanBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/MemberLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/MemberLogic.cs new file mode 100644 index 0000000..e536367 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/MemberLogic.cs @@ -0,0 +1,125 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class MemberLogic : IMemberLogic + { + private readonly ILogger _logger; + private readonly IMemberStorage _memberStorage; + + public MemberLogic(ILogger logger, IMemberStorage memberStorage) + { + _logger = logger; + _memberStorage = memberStorage; + } + + public bool Create(MemberBindingModel model) + { + CheckModel(model); + + if (_memberStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(MemberBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_memberStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public MemberViewModel? ReadElement(MemberSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. MemberFIO:{MemberFIO}.Id:{Id}", model.MemberFIO, model.Id); + + var element = _memberStorage.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(MemberSearchModel? model) + { + _logger.LogInformation("ReadList. MemberFIO:{MemberFIO}.Id:{ Id}", model?.MemberFIO, model?.Id); + + var list = model == null ? _memberStorage.GetFullList() : _memberStorage.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(MemberBindingModel model) + { + CheckModel(model); + + if (_memberStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + private void CheckModel(MemberBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.MemberFIO)) + { + throw new ArgumentNullException("Нет ФИО участника", nameof(model.MemberFIO)); + } + + if (string.IsNullOrEmpty(model.Citizenship)) + { + throw new ArgumentNullException("Не указано гражданство участника", nameof(model.Citizenship)); + } + + _logger.LogInformation("Member. MemberFIO:{MemberFIO}.Citizenship:{ Citizenship}. Id: { Id}", model.MemberFIO, model.Citizenship, model.Id); + } + } +} diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/OrganiserLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/OrganiserLogic.cs new file mode 100644 index 0000000..049b838 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/OrganiserLogic.cs @@ -0,0 +1,171 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class OrganiserLogic : IOrganiserLogic + { + private readonly int _loginMaxLength = 50; + private readonly int _passwordMaxLength = 50; + private readonly int _passwordMinLength = 10; + + private readonly ILogger _logger; + private readonly IOrganiserStorage _organiserStorage; + + public OrganiserLogic(ILogger logger, IOrganiserStorage organiserStorage) + { + _logger = logger; + _organiserStorage = organiserStorage; + } + + public bool Create(OrganiserBindingModel model) + { + CheckModel(model); + + if (_organiserStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public bool Delete(OrganiserBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + + if (_organiserStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + public OrganiserViewModel? ReadElement(OrganiserSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}.", model.OrganiserFIO, model.OrganiserLogin, model.Id); + + var element = _organiserStorage.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(OrganiserSearchModel? model) + { + _logger.LogInformation("ReadList. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}.", model?.OrganiserFIO, model?.OrganiserLogin, model?.Id); + + var list = model == null ? _organiserStorage.GetFullList() : _organiserStorage.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(OrganiserBindingModel model) + { + CheckModel(model); + + if (_organiserStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(OrganiserBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.OrganiserFIO)) + { + throw new ArgumentNullException("Нет ФИО организатора", nameof(model.OrganiserFIO)); + } + + if (string.IsNullOrEmpty(model.OrganiserLogin)) + { + throw new ArgumentNullException("Нет логина организатора", nameof(model.OrganiserLogin)); + } + + if (model.OrganiserLogin.Length>_loginMaxLength) + { + throw new ArgumentNullException("Логин слишком длинный", nameof(model.OrganiserLogin)); + } + + if (string.IsNullOrEmpty(model.OrganiserNumber)) + { + throw new ArgumentNullException("Нет номера телефона организатора", nameof(model.OrganiserNumber)); + } + + if (string.IsNullOrEmpty(model.OrganiserEmail)) + { + throw new ArgumentNullException("Нет почты организатора", nameof(model.OrganiserEmail)); + } + + if (string.IsNullOrEmpty(model.OrganiserPassword)) + { + throw new ArgumentNullException("Нет пароля организатора", nameof(model.OrganiserPassword)); + } + + if (model.OrganiserPassword.Length < _passwordMinLength) + { + throw new ArgumentNullException("Пароль слишком короткий", nameof(model.OrganiserPassword)); + } + + if (model.OrganiserPassword.Length > _passwordMaxLength) + { + throw new ArgumentNullException("Пароль слишком длинный", nameof(model.OrganiserPassword)); + } + + _logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id); + + var element = _organiserStorage.GetElement(new OrganiserSearchModel + { + OrganiserLogin = model.OrganiserLogin + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Организатор с таким логином уже есть"); + } + } + } +} diff --git a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj new file mode 100644 index 0000000..e500d7e --- /dev/null +++ b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + +