BusinessLogics

This commit is contained in:
parent 15c9409f76
commit 58fe126791
14 changed files with 926 additions and 34 deletions

View File

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideDataModels", "Rou
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideContracts", "RouteGuideContracts\RouteGuideContracts.csproj", "{895094AD-E3AC-4E1F-83DC-283E65EB072F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideDatabaseImplement", "RouteGuideDatabaseImplement\RouteGuideDatabaseImplement.csproj", "{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideDatabaseImplement", "RouteGuideDatabaseImplement\RouteGuideDatabaseImplement.csproj", "{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideBusinessLogics", "RouteGuideBusinessLogics\RouteGuideBusinessLogics.csproj", "{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Release|Any CPU.Build.0 = Release|Any CPU
{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,177 @@
using Microsoft.Extensions.Logging;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.SearchModels;
using RouteGuideContracts.StoragesContracts;
using RouteGuideContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideBusinessLogics.BusinessLogics
{
/// <summary>
/// Бизнес-логика для сущности "Водитель"
/// </summary>
public class DriverLogic : IDriverLogic
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Хранилище
/// </summary>
private readonly IDriverStorage _driverStorage;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
/// <param name="driverStorage"></param>
public DriverLogic(ILogger<DriverLogic> logger, IDriverStorage driverStorage)
{
_logger = logger;
_driverStorage = driverStorage;
}
/// <summary>
/// Получение списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<DriverViewModel>? ReadList(DriverSearchModel? model)
{
_logger.LogInformation("ReadList. Driver.Id: {Id}", model?.Id);
var list = model == null ? _driverStorage.GetFullList() : _driverStorage.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="model"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public DriverViewModel? ReadElement(DriverSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Driver.Id: {Id}", model?.Id);
var element = _driverStorage.GetElement(model!);
if (element == null)
{
_logger.LogWarning("ReadElement. Element not found");
return null;
}
_logger.LogInformation("ReadElement. Find Driver.Id: {Id}", element.Id);
return element;
}
/// <summary>
/// Создание записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Create(DriverBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Create. Driver.Id: {Id}", model.Id);
if (_driverStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
/// <summary>
/// Изменение записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Update(DriverBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Update. Driver.Id: {Id}", model.Id);
if (_driverStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
/// <summary>
/// Удаление записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Delete(DriverBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Driver.Id: {Id}", model.Id);
if (_driverStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
/// <summary>
/// Проверка модели
/// </summary>
/// <param name="model"></param>
/// <param name="withParams"></param>
private void CheckModel(DriverBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FullName))
{
throw new ArgumentNullException("Не указано ФИО водителя", nameof(model.FullName));
}
if (string.IsNullOrEmpty(model.Phone))
{
throw new ArgumentNullException("Не указан номер телефона водителя", nameof(model.Phone));
}
_logger.LogInformation("CheckModel. Driver.Id: {Id}", model.Id);
var element = _driverStorage.GetElement(new DriverSearchModel
{
Phone = model.Phone
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Водитель с таким номером телефона уже существует");
}
}
}
}

View File

@ -0,0 +1,177 @@
using Microsoft.Extensions.Logging;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.SearchModels;
using RouteGuideContracts.StoragesContracts;
using RouteGuideContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideBusinessLogics.BusinessLogics
{
/// <summary>
/// Бизнес-логика для сущности "Маршрут"
/// </summary>
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?.Name);
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="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?.Name);
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>
/// <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.Name))
{
throw new ArgumentNullException("Не указано название маршрута", nameof(model.Name));
}
if (model.TransportId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор транспортного средства", nameof(model.TransportId));
}
_logger.LogInformation("CheckModel. Route.Id: {Id}", model.Id);
var element = _routeStorage.GetElement(new RouteSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Маршрут с таким названием уже существует");
}
}
}
}

View File

@ -0,0 +1,164 @@
using Microsoft.Extensions.Logging;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.SearchModels;
using RouteGuideContracts.StoragesContracts;
using RouteGuideContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideBusinessLogics.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="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>
/// <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);
}
}
}

View File

@ -0,0 +1,181 @@
using Microsoft.Extensions.Logging;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.SearchModels;
using RouteGuideContracts.StoragesContracts;
using RouteGuideContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideBusinessLogics.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="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>
/// <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));
}
if (string.IsNullOrEmpty(model.Street))
{
throw new ArgumentNullException("Не указано название улицы", nameof(model.Street));
}
if (model.Number <= 0)
{
throw new ArgumentNullException("Не указан номер дома", nameof(model.Number));
}
_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("Остановка с таким названием уже существует");
}
}
}
}

View File

@ -0,0 +1,181 @@
using Microsoft.Extensions.Logging;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.SearchModels;
using RouteGuideContracts.StoragesContracts;
using RouteGuideContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideBusinessLogics.BusinessLogics
{
/// <summary>
/// Бизнес-логика для сущности "Транспорт"
/// </summary>
public class TransportLogic : ITransportLogic
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Хранилище
/// </summary>
private readonly ITransportStorage _transportStorage;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
/// <param name="transportStorage"></param>
public TransportLogic(ILogger<TransportLogic> logger, ITransportStorage transportStorage)
{
_logger = logger;
_transportStorage = transportStorage;
}
/// <summary>
/// Получение списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<TransportViewModel>? ReadList(TransportSearchModel? model)
{
_logger.LogInformation("ReadList. Transport: {Id}.{License}", model?.Id, model?.License);
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="model"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public TransportViewModel? ReadElement(TransportSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Transport: {Id}.{License}", model?.Id, model?.License);
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(TransportBindingModel 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(TransportBindingModel 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(TransportBindingModel 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>
/// <param name="model"></param>
/// <param name="withParams"></param>
private void CheckModel(TransportBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.License))
{
throw new ArgumentNullException("Не указан номерной знак транспортного средства", nameof(model.License));
}
if (model.Capacity <= 0)
{
throw new ArgumentNullException("Вместимость транспортного средства должна быть положительным числом", nameof(model.Capacity));
}
if (model.DriverId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор водителя", nameof(model.DriverId));
}
_logger.LogInformation("CheckModel. Transport.Id: {Id}", model.Id);
var element = _transportStorage.GetElement(new TransportSearchModel
{
License = model.License
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Транспортное средство с таким номерным знаком уже есть");
}
}
}
}

View File

@ -1,7 +0,0 @@
namespace RouteGuideBusinessLogics
{
public class Class1
{
}
}

View File

@ -6,4 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RouteGuideContracts\RouteGuideContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -15,44 +15,38 @@ namespace RouteGuideContracts.BusinessLogicsContracts
public interface IStopLogic
{
/// <summary>
/// Получение полного списка
/// </summary>
/// <returns></returns>
List<StopViewModel> GetFullList();
/// <summary>
/// Получение фильтрованного списка
/// Получение списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
List<StopViewModel> GetFilteredList(StopSearchModel model);
List<StopViewModel>? ReadList(StopSearchModel? model);
/// <summary>
/// Получение элемента
/// Получение отдельной записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
StopViewModel? GetElement(StopSearchModel model);
StopViewModel? ReadElement(StopSearchModel model);
/// <summary>
/// Добавление элемента
/// Создание записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
StopViewModel? Insert(StopBindingModel model);
bool Create(StopBindingModel model);
/// <summary>
/// Редактирование элемента
/// Изменение записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
StopViewModel? Update(StopBindingModel model);
bool Update(StopBindingModel model);
/// <summary>
/// Удаление элемента
/// Удаление записи
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
StopViewModel? Delete(StopBindingModel model);
bool Delete(StopBindingModel model);
}
}

View File

@ -16,5 +16,10 @@ namespace RouteGuideContracts.SearchModels
/// Идентификатор
/// </summary>
public int? Id { get; set; }
/// <summary>
/// Номер телефона водителя
/// </summary>
public string? Phone { get; set; }
}
}

View File

@ -35,14 +35,14 @@ namespace RouteGuideDatabaseImplement.Implements
/// <returns></returns>
public List<DriverViewModel> GetFilteredList(DriverSearchModel model)
{
if (!model.Id.HasValue)
if (string.IsNullOrEmpty(model.Phone))
{
return new();
}
using var context = new RouteGuideDatabase();
return context.Drivers
.Where(x => x.Id == model.Id)
.Where(x => x.Phone.Contains(model.Phone))
.Select(x => x.GetViewModel)
.ToList();
}
@ -54,14 +54,14 @@ namespace RouteGuideDatabaseImplement.Implements
/// <returns></returns>
public DriverViewModel? GetElement(DriverSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Phone))
{
return null;
}
using var context = new RouteGuideDatabase();
return context.Drivers
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Phone) && x.Phone.Contains(model.Phone)) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}

View File

@ -40,7 +40,7 @@ namespace RouteGuideDatabaseImplement.Implements
/// <returns></returns>
public List<RouteViewModel> GetFilteredList(RouteSearchModel model)
{
if (!model.Id.HasValue)
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
@ -51,7 +51,7 @@ namespace RouteGuideDatabaseImplement.Implements
.Include(x => x.Stops)
.ThenInclude(x => x.Stop)
.ToList()
.Where(x => x.Id == model.Id)
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -35,14 +35,14 @@ namespace RouteGuideDatabaseImplement.Implements
/// <returns></returns>
public List<StopViewModel> GetFilteredList(StopSearchModel model)
{
if (!model.Id.HasValue)
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new RouteGuideDatabase();
return context.Stops
.Where(x => x.Id == model.Id)
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
@ -54,14 +54,14 @@ namespace RouteGuideDatabaseImplement.Implements
/// <returns></returns>
public StopViewModel? GetElement(StopSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name))
{
return null;
}
using var context = new RouteGuideDatabase();
return context.Stops
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}

View File

@ -8,4 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
</Project>