всякое туда сюда

This commit is contained in:
platoff aeeee 2024-04-30 15:00:58 +04:00
parent a147d23353
commit 97292269f9
6 changed files with 12 additions and 41 deletions

View File

@ -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<GuarantorLogic> 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<GuarantorViewModel>? 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("Пользователь с такими почтой или номером телефона уже есть");
}
}
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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; }

View File

@ -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