From 41fed5361d4c7e3e6b1887908f717d9d220a0185 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: Sat, 23 Mar 2024 22:10:37 +0400 Subject: [PATCH] =?UTF-8?q?=D1=8F=20=D0=B2=D1=81=D1=91=20=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=BB=20=D0=B8=20=D0=BF=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB...=20=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/HeadwaiterLogic.cs | 191 ++++++++++++++++++ .../HotelBusinessLogic.csproj | 12 +- .../AbstractSaveToWordHeadwaitre.cs | 12 ++ Hotel/HotelContracts/HotelContracts.csproj | 2 +- .../HotelDataBaseImplement.csproj | 2 +- Hotel/HotelDataModels/HotelDataModels.csproj | 2 +- Hotel/HotelView/HotelView.csproj | 2 +- 7 files changed, 216 insertions(+), 7 deletions(-) create mode 100644 Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs create mode 100644 Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaitre.cs diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs new file mode 100644 index 0000000..bab9e16 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs @@ -0,0 +1,191 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class HeadwaiterLogic : IHeadwaiterLogic + { + private readonly int _loginMaxLength = 50; + private readonly int _passwordMaxLength = 50; + private readonly int _passwordMinLength = 10; + + private readonly ILogger _logger; + private readonly IHeadwaiterStorage _headwaiterStorage; + + public HeadwaiterLogic(ILogger logger, IHeadwaiterStorage headwaiterStorage) + { + _logger = logger; + _headwaiterStorage = headwaiterStorage; + } + + public List? ReadList(HeadwaiterSearchModel? model) + { + _logger.LogInformation("ReadList. HeadwaiterSurname: {HeadwaiterSurname}. HeadwaiterName: {HeadwaiterName}. " + + "HeadwaiterPatronymic: {HeadwaiterPatronymic}. HeadwaiterLogin: {HeadwaiterLogin}. Id: {Id}.", model?.HeadwaiterSurname, model?.HeadwaiterName, model?.HeadwaiterPatronymic, model?.HeadwaiterLogin, model?.Id); + + var list = model == null ? _headwaiterStorage.GetFullList() : _headwaiterStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + + return list; + } + + public HeadwaiterViewModel? ReadElement(HeadwaiterSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadList. HeadwaiterSurname: {HeadwaiterSurname}. HeadwaiterName: {HeadwaiterName}. " + + "HeadwaiterPatronymic: {HeadwaiterPatronymic}. HeadwaiterLogin: {HeadwaiterLogin}. Id: {Id}.", model?.HeadwaiterSurname, model?.HeadwaiterName, model?.HeadwaiterPatronymic, model?.HeadwaiterLogin, model?.Id); + + var element = _headwaiterStorage.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(HeadwaiterBindingModel model) + { + CheckModel(model); + + if (_headwaiterStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public bool Update(HeadwaiterBindingModel model) + { + CheckModel(model); + + if (_headwaiterStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(HeadwaiterBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + + if (_headwaiterStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + private void CheckModel(HeadwaiterBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.HeadwaiterSurname)) + { + throw new ArgumentNullException("Нет фамилии метродотеля", nameof(model.HeadwaiterSurname)); + } + + if (string.IsNullOrEmpty(model.HeadwaiterName)) + { + throw new ArgumentNullException("Нет имени метродотеля", nameof(model.HeadwaiterName)); + } + + if (string.IsNullOrEmpty(model.HeadwaiterPatronymic)) + { + throw new ArgumentNullException("Нет отчества метродотеля", nameof(model.HeadwaiterPatronymic)); + } + + if (string.IsNullOrEmpty(model.HeadwaiterSurname)) + { + throw new ArgumentNullException("Нет фамилии метродотеля", nameof(model.HeadwaiterSurname)); + } + + if (string.IsNullOrEmpty(model.HeadwaiterLogin)) + { + throw new ArgumentNullException("Нет логина метродотеля", nameof(model.HeadwaiterLogin)); + } + + if (model.HeadwaiterLogin.Length > _loginMaxLength) + { + throw new ArgumentNullException("Логин слишком длинный", nameof(model.HeadwaiterLogin)); + } + + if (model.HeadwaiterEmail.Length > _loginMaxLength || !Regex.IsMatch(model.HeadwaiterEmail, @"([a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+)")) + { + throw new Exception($"В качестве логина должна быть указана почта и иметь длинну не более {_loginMaxLength} символов"); + } + + if (string.IsNullOrEmpty(model.HeadwaiterPassword)) + { + throw new ArgumentNullException("Нет пароля метродотеля", nameof(model.HeadwaiterPassword)); + } + + if (model.HeadwaiterPassword.Length > _passwordMaxLength || model.HeadwaiterPassword.Length < _passwordMinLength + || !Regex.IsMatch(model.HeadwaiterPassword, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$")) + { + throw new Exception($"Пароль длиной от {_passwordMinLength} до {_passwordMaxLength} должен состоять из цифр, букв и небуквенных символов"); + } + + if (string.IsNullOrEmpty(model.HeadwaiterEmail)) + { + throw new ArgumentNullException("Нет почты метродотеля", nameof(model.HeadwaiterEmail)); + } + + if (string.IsNullOrEmpty(model.HeadwaiterPhoneNumber)) + { + throw new ArgumentNullException("Нет номера телефона метродотеля", nameof(model.HeadwaiterPhoneNumber)); + } + + _logger.LogInformation("ReadList. HeadwaiterSurname: {HeadwaiterSurname}. HeadwaiterName: {HeadwaiterName}. " + + "HeadwaiterPatronymic: {HeadwaiterPatronymic}. HeadwaiterLogin: {HeadwaiterLogin}. Id: {Id}.", model?.HeadwaiterSurname, model?.HeadwaiterName, model?.HeadwaiterPatronymic, model?.HeadwaiterLogin, model?.Id); + + var element = _headwaiterStorage.GetElement(new HeadwaiterSearchModel + { + HeadwaiterEmail = model.HeadwaiterEmail + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("метродотель с таким логином уже есть"); + } + } + } +} diff --git a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj index 91adafb..65bfd43 100644 --- a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj +++ b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,8 +7,14 @@ - - + + + + + + + + diff --git a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaitre.cs b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaitre.cs new file mode 100644 index 0000000..59bc9b0 --- /dev/null +++ b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaitre.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordHeadwaitre + { + } +} diff --git a/Hotel/HotelContracts/HotelContracts.csproj b/Hotel/HotelContracts/HotelContracts.csproj index a9f6023..e4797ec 100644 --- a/Hotel/HotelContracts/HotelContracts.csproj +++ b/Hotel/HotelContracts/HotelContracts.csproj @@ -1,7 +1,7 @@  - net8.0 + net6.0 enable enable diff --git a/Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj b/Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj index b82363b..abd57db 100644 --- a/Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj +++ b/Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj @@ -1,7 +1,7 @@  - net8.0 + net6.0 enable enable diff --git a/Hotel/HotelDataModels/HotelDataModels.csproj b/Hotel/HotelDataModels/HotelDataModels.csproj index fa71b7a..27ac386 100644 --- a/Hotel/HotelDataModels/HotelDataModels.csproj +++ b/Hotel/HotelDataModels/HotelDataModels.csproj @@ -1,7 +1,7 @@  - net8.0 + net6.0 enable enable diff --git a/Hotel/HotelView/HotelView.csproj b/Hotel/HotelView/HotelView.csproj index 663fdb8..b57c89e 100644 --- a/Hotel/HotelView/HotelView.csproj +++ b/Hotel/HotelView/HotelView.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net6.0-windows enable true enable