From 97292269f92390dad5322223ec56c5966b2eaaab Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Tue, 30 Apr 2024 15:00:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D1=8F=D0=BA=D0=BE=D0=B5=20=D1=82?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=20=D1=81=D1=8E=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/Guarantor/GuarantorLogic.cs | 34 +++++-------------- .../Guarantor/GuarantorBindingModel.cs | 3 -- .../Guarantor/GuarantorSearchModel.cs | 8 ++--- .../ViewModels/GuarantorViewModel.cs | 3 -- .../Models/Guarantor/IGuarantorModel.cs | 1 - .../Models/GuarantorModels/Guarantor.cs | 4 --- 6 files changed, 12 insertions(+), 41 deletions(-) diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs index f62d40e..06bff29 100644 --- a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/Guarantor/GuarantorLogic.cs @@ -3,13 +3,12 @@ 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.BusinessLogicsContracts.Guarantor; +using TravelCompanyContracts.BindingModels.Guarantor; +using TravelCompanyContracts.StoragesModels.Guarantor; using TravelCompanyContracts.SearchModels.Guarantor; +using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor { @@ -20,14 +19,12 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor private readonly IGuarantorStorage _guarantorStorage; - // Конструктор public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage) { _logger = logger; _guarantorStorage = guarantorStorage; } - // Вывод конкретного клиента public GuarantorViewModel? ReadElement(GuarantorSearchModel model) { if (model == null) @@ -47,12 +44,10 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor 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) @@ -65,7 +60,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor return list; } - // Создание клиента public bool Create(GuarantorBindingModel model) { CheckModel(model); @@ -78,7 +72,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor return true; } - // Обновление клиента public bool Update(GuarantorBindingModel model) { CheckModel(model); @@ -91,7 +84,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor return true; } - // Удаление клиента public bool Delete(GuarantorBindingModel model) { CheckModel(model, false); @@ -105,7 +97,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor return true; } - // Проверка входного аргумента для методов Insert, Update и Delete public void CheckModel(GuarantorBindingModel model, bool withParams = true) { if (model == null) @@ -113,7 +104,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor throw new ArgumentNullException(nameof(model)); } - // При удалении параметру withParams передаём false if (!withParams) { return; @@ -136,11 +126,7 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor { throw new ArgumentNullException("Нет отчества пользователя", nameof(model.Patronymic)); } - // Проверка на наличие логина - if (string.IsNullOrEmpty(model.Login)) - { - throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); - } + // Проверка на наличие эл. почты if (string.IsNullOrEmpty(model.Email)) { @@ -159,21 +145,19 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.Guarantor 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); + _logger.LogInformation("Client. Name:{Name}.Surname:{Surname}.Patronymic:{Patronymic}.Email:{Email}.Password:{Password}.Mobeliphone:{MobilePhone}.Id:{Id}", + model.Name, model.Surname, model.Patronymic, model.Email, model.Password, model.MobilePhone, model.Id); - // Для проверка на наличие такого же аккаунта var element = _guarantorStorage.GetElement(new GuarantorSearchModel { Email = model.Email, + MobilePhone = model.MobilePhone, }); - // Если элемент найден и его Id не совпадает с Id переданного объекта if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Клиент с такой почтой уже есть"); + throw new InvalidOperationException("Пользователь с такими почтой или номером телефона уже есть"); } } - } } diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs index 2a7593a..a888110 100644 --- a/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs +++ b/TravelCompany/TravelCompanyContracts/BindingModels/Guarantor/GuarantorBindingModel.cs @@ -18,13 +18,10 @@ namespace TravelCompanyContracts.BindingModels.Guarantor public string Patronymic { get; set; } = string.Empty; - public string Login { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string MobilePhone { get; set; } = string.Empty; - } } diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs index c792254..7f9ff03 100644 --- a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/GuarantorSearchModel.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyContracts.SearchModels.Guarantor; namespace TravelCompanyContracts.SearchModels.Guarantor { @@ -11,10 +10,9 @@ namespace TravelCompanyContracts.SearchModels.Guarantor public class GuarantorSearchModel { public int? Id { get; set; } - public string? Surname { get; set; } - public string? Name { get; set; } - public string? Patronymic { get; set; } - public string? Login { get; set; } = string.Empty; + public string? Surname { get; set; } = string.Empty; + public string? Name { get; set; } = string.Empty; + public string? Patronymic { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty; public string? Email { get; set; } = string.Empty; public string? MobilePhone { get; set; } = string.Empty; diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/Guarantor/ViewModels/GuarantorViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/Guarantor/ViewModels/GuarantorViewModel.cs index d7177a1..d1e5496 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/Guarantor/ViewModels/GuarantorViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/Guarantor/ViewModels/GuarantorViewModel.cs @@ -22,9 +22,6 @@ namespace TravelCompanyContracts.ViewModels.Guarantor.ViewModels [DisplayName("Отчество")] public string Patronymic { get; set; } = string.Empty; - [DisplayName("Логин")] - public string Login { get; set; } = string.Empty; - [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; diff --git a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuarantorModel.cs b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuarantorModel.cs index 9a6ccd5..7e0ebbf 100644 --- a/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuarantorModel.cs +++ b/TravelCompany/TravelCompanyDataModels/Models/Guarantor/IGuarantorModel.cs @@ -11,7 +11,6 @@ namespace TravelCompanyDataModels.Models.Guarantor string Surname { get; } string Name { get; } string Patronymic { get; } - string Login { get; } string Password { get; } string Email { get; } string MobilePhone { get; } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs index 5c782a5..2bf1f6a 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs @@ -24,9 +24,6 @@ namespace TravelCompanyDatabaseImplement.Models.GuarantorModels [Required] public string Patronymic { get; set; } = string.Empty; - [Required] - public string Login { get; set; } = string.Empty; - [Required] public string Password { get; set; } = string.Empty; @@ -45,7 +42,6 @@ namespace TravelCompanyDatabaseImplement.Models.GuarantorModels Name = Name, Surname = Surname, Patronymic = Patronymic, - Login = Login, Password = Password, Email = Email, MobilePhone = MobilePhone