поручитель бизнес логика, биндингмоделс
This commit is contained in:
parent
7c6766e700
commit
006d72ab85
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TravelCompanyBusinessLogic.BusinessLogic
|
||||
namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor
|
||||
{
|
||||
internal class ContractorLogic
|
||||
{
|
@ -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<GuarantorLogic> 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<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)
|
||||
{
|
||||
_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("Клиент с такой почтой уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyContracts\TravelCompanyContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyDataModels\TravelCompanyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -14,5 +14,6 @@ namespace TravelCompanyDataModels.Models.Guarantor
|
||||
string PhoneNumber { get; }
|
||||
|
||||
double GuidePrice { get; }
|
||||
int GuarantorId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace TravelCompanyDataModels.Models.Guarantor
|
||||
|
||||
string DescriptionPlace { get; }
|
||||
|
||||
int GuarantorId { get; }
|
||||
}
|
||||
}
|
@ -10,4 +10,8 @@
|
||||
<Folder Include="Enums\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -13,6 +13,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user