diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ContractorLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Contractor/ContractorLogic.cs similarity index 73% rename from TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ContractorLogic.cs rename to TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Contractor/ContractorLogic.cs index 0d6486d..1e99bbf 100644 --- a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ContractorLogic.cs +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Contractor/ContractorLogic.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyBusinessLogic.BusinessLogic +namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor { internal class ContractorLogic { diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs new file mode 100644 index 0000000..f62d40e --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.BusinessLogicsContracts.Guarantor; +using TravelCompanyContracts.StoragesModels.Guarantor; +using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; +using TravelCompanyContracts.BindingModels.Guarantor; +using TravelCompanyContracts.BindingModels; +using Microsoft.Extensions.Logging; +using TravelCompanyContracts.SearchModels.Guarantor; + +namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor +{ + // класс бизнес-логики для Поручителей + public class GuarantorLogic : IGuarantorLogic + { + private readonly ILogger _logger; + + private readonly IGuarantorStorage _guarantorStorage; + + // Конструктор + public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage) + { + _logger = logger; + _guarantorStorage = guarantorStorage; + } + + // Вывод конкретного клиента + public GuarantorViewModel? ReadElement(GuarantorSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Surname:{Surname}.Name:{Name}.Patronymic:{Patronymic}.Id:{Id}", model.Surname, model.Name, model.Patronymic, model.Id); + var element = _guarantorStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("Read element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + // Вывод отфильтрованного списка + public List? ReadList(GuarantorSearchModel model) + { + _logger.LogInformation("ReadList. ClientId:{Id}", model?.Id); + + // list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + // Создание клиента + public bool Create(GuarantorBindingModel model) + { + CheckModel(model); + if (_guarantorStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + // Обновление клиента + public bool Update(GuarantorBindingModel model) + { + CheckModel(model); + if (_guarantorStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + // Удаление клиента + public bool Delete(GuarantorBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_guarantorStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + // Проверка входного аргумента для методов Insert, Update и Delete + public void CheckModel(GuarantorBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // При удалении параметру withParams передаём false + if (!withParams) + { + return; + } + + // Проверка на наличие имени клиента + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name)); + } + + // Проверка на наличие фамилии клиента + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Surname)); + } + + // Проверка на наличие отчества клиента + if (string.IsNullOrEmpty(model.Patronymic)) + { + throw new ArgumentNullException("Нет отчества пользователя", nameof(model.Patronymic)); + } + // Проверка на наличие логина + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); + } + // Проверка на наличие эл. почты + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + + // Проверка на наличие пароля + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + + // Проверка на наличие мобильного телефона + if (string.IsNullOrEmpty(model.MobilePhone)) + { + throw new ArgumentNullException("Нет моб.телефона пользователя", nameof(model.MobilePhone)); + } + + _logger.LogInformation("Client. Name:{Name}.Surname:{Surname}.Patronymic:{Patronymic}.Login:{Login}.Email:{Email}.Password:{Password}.Mobeliphone:{MobilePhone}.Id:{Id}", + model.Name, model.Surname, model.Patronymic, model.Login, model.Email, model.Password, model.MobilePhone, model.Id); + + // Для проверка на наличие такого же аккаунта + var element = _guarantorStorage.GetElement(new GuarantorSearchModel + { + Email = model.Email, + }); + + // Если элемент найден и его Id не совпадает с Id переданного объекта + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с такой почтой уже есть"); + } + } + + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuideLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuideLogic.cs new file mode 100644 index 0000000..62baa31 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuideLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor +{ + internal class GuideLogic + { + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/PlaceLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/PlaceLogic.cs new file mode 100644 index 0000000..5a39578 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/PlaceLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor +{ + internal class PlaceLogic + { + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/GuarantorLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/TripLogic.cs similarity index 60% rename from TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/GuarantorLogic.cs rename to TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/TripLogic.cs index 1cc14dd..c2d8f9c 100644 --- a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/GuarantorLogic.cs +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/TripLogic.cs @@ -4,11 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyBusinessLogic.BusinessLogic +namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor { - public class GuarantorLogic + internal class TripLogic { - - } } diff --git a/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj index bb126aa..8842a17 100644 --- a/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj +++ b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs index 1528ade..2a7593a 100644 --- a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs +++ b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TravelCompanyDataModels.Models.Guarantor; +// using TravelCompanyDataModels.Enums; namespace TravelCompanyContracts.BindingModels.Guarantor { diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuideBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuideBindingModel.cs index 89d7614..8b4ad56 100644 --- a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuideBindingModel.cs +++ b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuideBindingModel.cs @@ -10,10 +10,11 @@ namespace TravelCompanyContracts.BindingModels.Guarantor public class GuideBindingModel : IGuideModel { public int Id { get; set; } - public string GuideFIO { get; set; } + public string GuideFIO { get; set; } = string.Empty; - public string PhoneNumber { get; set; } + public string PhoneNumber { get; set; } = string.Empty; - public string GuidePrice { get; set; } + public double GuidePrice { get; set; } + public int GuarantorId { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/PlaceBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/PlaceBindingModel.cs new file mode 100644 index 0000000..8c87768 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/PlaceBindingModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyDataModels.Models.Guarantor; + +namespace TravelCompanyContracts.BindingModels.Guarantor +{ + public class PlaceBindingModel : IPlaceModel + { + public int Id { get; set; } + + public string NamePlace { get; set; } = string.Empty; + + public string DescriptionPlace { get; set; } = string.Empty; + + public int GuarantorId { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/TripBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/TripBindingModel.cs new file mode 100644 index 0000000..33e52ee --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/TripBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyDataModels.Models.Guarantor; + +namespace TravelCompanyContracts.BindingModels.Guarantor +{ + public class TripBindingModel : ITripModel + { + public int Id { get; set; } + public string TripName { get; set; } = string.Empty; + public DateTime TripDate { get; set; } + public int GuarantorId { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs index 78f9f63..c792254 100644 --- a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.SearchModels.Guarantor; namespace TravelCompanyContracts.SearchModels.Guarantor { @@ -10,12 +11,9 @@ namespace TravelCompanyContracts.SearchModels.Guarantor public class GuarantorSearchModel { public int? Id { get; set; } - - public string? Name { get; set; } = string.Empty; - - public string? Surname { get; set; } = string.Empty; - - public string? Patronymic { get; set; } = string.Empty; + public string? Surname { get; set; } + public string? Name { get; set; } + public string? Patronymic { get; set; } public string? Login { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty; public string? Email { get; set; } = string.Empty; diff --git a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj index 78baecb..8c837ed 100644 --- a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj +++ b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuideModel.cs b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuideModel.cs index 1f76518..965ea37 100644 --- a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuideModel.cs +++ b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuideModel.cs @@ -14,5 +14,6 @@ namespace TravelCompanyDataModels.Models.Guarantor string PhoneNumber { get; } double GuidePrice { get; } + int GuarantorId { get; } } } diff --git a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IPlaceModel.cs b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IPlaceModel.cs index 6418254..5f13656 100644 --- a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IPlaceModel.cs +++ b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IPlaceModel.cs @@ -12,5 +12,6 @@ namespace TravelCompanyDataModels.Models.Guarantor string DescriptionPlace { get; } + int GuarantorId { get; } } } \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj index b6a7529..9e9a7b3 100644 --- a/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj +++ b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj index 51e81d3..e28f94a 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -13,6 +13,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +