BusinessLogics добавила, всё сломала, всё починила
This commit is contained in:
parent
e8805bb42b
commit
f12b514584
@ -3,22 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34723.18
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteDirectoryDataModels", "RouteDirectoryBusinessLogics\RouteDirectoryDataModels.csproj", "{69BE4B26-1636-4661-B3AA-A29C531223D9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteDirectoryContracts", "RouteDirectoryContracts\RouteDirectoryContracts.csproj", "{2A635E80-4C36-404E-BD93-932BB9DDCC80}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteDirectoryDatabaseImplement", "RouteDirectoryDatabaseImplement\RouteDirectoryDatabaseImplement.csproj", "{0EEFDAB4-25D2-452E-A6D7-9E24F83D72FB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteDirectoryBusinessLogics", "RouteDirectoryBusinessLogics\RouteDirectoryBusinessLogics.csproj", "{1912B63E-8ECF-4C69-AD87-14CBCC537F53}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteDirectoryDataModels", "RouteDirectoryDataModels\RouteDirectoryDataModels\RouteDirectoryDataModels.csproj", "{FC55798A-CB32-4A98-9228-7370FCD6821D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{69BE4B26-1636-4661-B3AA-A29C531223D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{69BE4B26-1636-4661-B3AA-A29C531223D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{69BE4B26-1636-4661-B3AA-A29C531223D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{69BE4B26-1636-4661-B3AA-A29C531223D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2A635E80-4C36-404E-BD93-932BB9DDCC80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2A635E80-4C36-404E-BD93-932BB9DDCC80}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2A635E80-4C36-404E-BD93-932BB9DDCC80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -27,6 +25,14 @@ Global
|
||||
{0EEFDAB4-25D2-452E-A6D7-9E24F83D72FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0EEFDAB4-25D2-452E-A6D7-9E24F83D72FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0EEFDAB4-25D2-452E-A6D7-9E24F83D72FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1912B63E-8ECF-4C69-AD87-14CBCC537F53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1912B63E-8ECF-4C69-AD87-14CBCC537F53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1912B63E-8ECF-4C69-AD87-14CBCC537F53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1912B63E-8ECF-4C69-AD87-14CBCC537F53}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FC55798A-CB32-4A98-9228-7370FCD6821D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FC55798A-CB32-4A98-9228-7370FCD6821D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FC55798A-CB32-4A98-9228-7370FCD6821D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FC55798A-CB32-4A98-9228-7370FCD6821D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,221 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RouteDirectoryContracts.BindingModels;
|
||||
using RouteDirectoryContracts.BusinessLogicsContracts;
|
||||
using RouteDirectoryContracts.SearchModels;
|
||||
using RouteDirectoryContracts.StoragesContracts;
|
||||
using RouteDirectoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RouteDirectoryBusinessLogics.BusinessLogics
|
||||
{
|
||||
public class RouteLogic : IRouteLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IRouteStorage _routeStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="routeStorage"></param>
|
||||
public RouteLogic(ILogger<RouteLogic> logger, IRouteStorage routeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_routeStorage = routeStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<RouteViewModel>? ReadList(RouteSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Route: {Name}.{Id}", model?.Id, model?.RouteNumber);
|
||||
|
||||
var list = model == null ? _routeStorage.GetFullList() : _routeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка из заданного количества элементов
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public List<RouteViewModel>? ReadList(int count)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Count: {Count}", count);
|
||||
|
||||
var list = _routeStorage.GetList(count);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public RouteViewModel? ReadElement(RouteSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Route: {Name}.{Id}", model?.Id, model?.RouteNumber);
|
||||
|
||||
var element = _routeStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Route.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Route.Id: {Id}", model.Id);
|
||||
|
||||
if (_routeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Route.Id: {Id}", model.Id);
|
||||
|
||||
if (_routeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Route.Id: {Id}", model.Id);
|
||||
|
||||
if (_routeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Delete()
|
||||
{
|
||||
_logger.LogInformation("Delete. Route");
|
||||
|
||||
if (_routeStorage.Delete() == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление всех записей
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Clear()
|
||||
{
|
||||
int count = _routeStorage.Clear();
|
||||
_logger.LogInformation("Clear. Delete {Count} Routes", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(RouteBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.RouteNumber))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано название маршрута", nameof(model.RouteNumber));
|
||||
}
|
||||
if (model.TransportId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор транспортного средства", nameof(model.TransportId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Route.Id: {Id}", model.Id);
|
||||
|
||||
var element = _routeStorage.GetElement(new RouteSearchModel
|
||||
{
|
||||
RouteNumber = model.RouteNumber
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Маршрут с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RouteDirectoryContracts.BindingModels;
|
||||
using RouteDirectoryContracts.BusinessLogicsContracts;
|
||||
using RouteDirectoryContracts.SearchModels;
|
||||
using RouteDirectoryContracts.StoragesContracts;
|
||||
using RouteDirectoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RouteDirectoryBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Расписание"
|
||||
/// </summary>
|
||||
public class ScheduleLogic : IScheduleLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IScheduleStorage _scheduleStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="scheduleStorage"></param>
|
||||
public ScheduleLogic(ILogger<ScheduleLogic> logger, IScheduleStorage scheduleStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_scheduleStorage = scheduleStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ScheduleViewModel>? ReadList(ScheduleSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Schedule.{Id}", model?.Id);
|
||||
|
||||
var list = model == null ? _scheduleStorage.GetFullList() : _scheduleStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка из заданного количества элементов
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public List<ScheduleViewModel>? ReadList(int count)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Count: {Count}", count);
|
||||
|
||||
var list = _scheduleStorage.GetList(count);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public ScheduleViewModel? ReadElement(ScheduleSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Schedule.{Id}", model?.Id);
|
||||
|
||||
var element = _scheduleStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Schedule.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(ScheduleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Schedule.Id: {Id}", model.Id);
|
||||
|
||||
if (_scheduleStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(ScheduleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Schedule.Id: {Id}", model.Id);
|
||||
|
||||
if (_scheduleStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(ScheduleBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Schedule.Id: {Id}", model.Id);
|
||||
|
||||
if (_scheduleStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Delete()
|
||||
{
|
||||
_logger.LogInformation("Delete. Schedule");
|
||||
|
||||
if (_scheduleStorage.Delete() == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление всех записей
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Clear()
|
||||
{
|
||||
int count = _scheduleStorage.Clear();
|
||||
_logger.LogInformation("Clear. Delete {Count} Schedules", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(ScheduleBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.RouteId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор маршрута", nameof(model.RouteId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Schedule.Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RouteDirectoryContracts.BindingModels;
|
||||
using RouteDirectoryContracts.BusinessLogicsContracts;
|
||||
using RouteDirectoryContracts.SearchModels;
|
||||
using RouteDirectoryContracts.StoragesContracts;
|
||||
using RouteDirectoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RouteDirectoryBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Остановка"
|
||||
/// </summary>
|
||||
public class StopLogic : IStopLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IStopStorage _stopStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="stopStorage"></param>
|
||||
public StopLogic(ILogger<StopLogic> logger, IStopStorage stopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_stopStorage = stopStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<StopViewModel>? ReadList(StopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Stop: {Name}.{Id}", model?.Id, model?.Name);
|
||||
|
||||
var list = model == null ? _stopStorage.GetFullList() : _stopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка из заданного количества элементов
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public List<StopViewModel>? ReadList(int count)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Count: {Count}", count);
|
||||
|
||||
var list = _stopStorage.GetList(count);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public StopViewModel? ReadElement(StopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Stop: {Name}.{Id}", model?.Id, model?.Name);
|
||||
|
||||
var element = _stopStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Stop.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Stop.Id: {Id}", model.Id);
|
||||
|
||||
if (_stopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Stop.Id: {Id}", model.Id);
|
||||
|
||||
if (_stopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Stop.Id: {Id}", model.Id);
|
||||
|
||||
if (_stopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Delete()
|
||||
{
|
||||
_logger.LogInformation("Delete. Stop");
|
||||
|
||||
if (_stopStorage.Delete() == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление всех записей
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Clear()
|
||||
{
|
||||
int count = _stopStorage.Clear();
|
||||
_logger.LogInformation("Clear. Delete {Count} Stops", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(StopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано название остановки", nameof(model.Name));
|
||||
}
|
||||
_logger.LogInformation("CheckModel. Stop.Id: {Id}", model.Id);
|
||||
|
||||
var element = _stopStorage.GetElement(new StopSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Остановка с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RouteDirectoryContracts.BindingModels;
|
||||
using RouteDirectoryContracts.BusinessLogicsContracts;
|
||||
using RouteDirectoryContracts.SearchModels;
|
||||
using RouteDirectoryContracts.StoragesContracts;
|
||||
using RouteDirectoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RouteDirectoryBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Транспорт"
|
||||
/// </summary>
|
||||
public class TransportTypeLogic : ITransportTypeLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly ITransportTypeStorage _transportStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="transportStorage"></param>
|
||||
public TransportTypeLogic(ILogger<TransportTypeLogic> logger, ITransportTypeStorage transportStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_transportStorage = transportStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<TransportTypeViewModel>? ReadList(TransportTypeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Transport: {Id}.{License}", model?.Id);
|
||||
|
||||
var list = model == null ? _transportStorage.GetFullList() : _transportStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка из заданного количества элементов
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public List<TransportTypeViewModel>? ReadList(int count)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Count: {Count}", count);
|
||||
|
||||
var list = _transportStorage.GetList(count);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public TransportTypeViewModel? ReadElement(TransportTypeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Transport: {Id}", model?.Id);
|
||||
|
||||
var element = _transportStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Transport.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Transport.Id: {Id}", model.Id);
|
||||
|
||||
if (_transportStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Transport.Id: {Id}", model.Id);
|
||||
|
||||
if (_transportStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Transport.Id: {Id}", model.Id);
|
||||
|
||||
if (_transportStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Delete()
|
||||
{
|
||||
_logger.LogInformation("Delete. Transport");
|
||||
|
||||
if (_transportStorage.Delete() == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление всех записей
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Clear()
|
||||
{
|
||||
int count = _transportStorage.Clear();
|
||||
_logger.LogInformation("Clear. Delete {Count} Transports", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(TransportTypeBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("CheckModel. Transport.Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RouteDirectoryContracts\RouteDirectoryContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RouteDirectoryBusinessLogics\RouteDirectoryDataModels.csproj" />
|
||||
<ProjectReference Include="..\RouteDirectoryDataModels\RouteDirectoryDataModels\RouteDirectoryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -16,8 +16,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RouteDirectoryBusinessLogics\RouteDirectoryDataModels.csproj" />
|
||||
<ProjectReference Include="..\RouteDirectoryContracts\RouteDirectoryContracts.csproj" />
|
||||
<ProjectReference Include="..\RouteDirectoryDataModels\RouteDirectoryDataModels\RouteDirectoryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user