diff --git a/Subd/BusinessLogic/BusinessLogic.csproj b/Subd/BusinessLogic/BusinessLogic.csproj new file mode 100644 index 0000000..d446313 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Subd/BusinessLogic/BusinessLogic/CarBL.cs b/Subd/BusinessLogic/BusinessLogic/CarBL.cs new file mode 100644 index 0000000..2651927 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/CarBL.cs @@ -0,0 +1,109 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessBL.BusinessBL +{ + public class CarBL : ICarLogic + { + private readonly ILogger _logger; + private readonly ICarStorage _carStorage; + public CarBL(ILogger logger, ICarStorage carStorage) + { + _logger = logger; + _carStorage = carStorage; + } + public List? ReadList(CarSM? model) + { + _logger.LogInformation("ReadList. CarName:{CarName}.Id:{ Id}", model?.Model, model?.Id); + var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public CarVM? ReadElement(CarSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. CarName:{CarName}. Id:{ Id}", model.Model, model.Id); + var element = _carStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(CarBM model) + { + CheckModel(model); + if (_carStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(CarBM model) + { + CheckModel(model); + if (_carStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(CarBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_carStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(CarBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Model)) + { + throw new ArgumentNullException("Нет названия машины", nameof(model.Model)); + } + if (model.Tonnage <= 0) + { + throw new ArgumentNullException("Грузоподъемность должна быть больше 0", nameof(model.Tonnage)); + } + if (model.StatusId <= 0) + { + throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); + } + + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs b/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs new file mode 100644 index 0000000..9765ef7 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs @@ -0,0 +1,115 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class CompanyBL : ICompanyLogic + { + private readonly ILogger _logger; + private readonly ICompanyStorage _companyStorage; + public CompanyBL(ILogger logger, ICompanyStorage companyStorage) + { + _logger = logger; + _companyStorage = companyStorage; + } + public List? ReadList(CompanySM? model) + { + _logger.LogInformation("ReadList. CompanyName:{CompanyName}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _companyStorage.GetFullList() : _companyStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public CompanyVM? ReadElement(CompanySM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. CompanyName:{CompanyName}. Id:{ Id}", model.Title, model.Id); + var element = _companyStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(CompanyBM model) + { + CheckModel(model); + if (_companyStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(CompanyBM model) + { + CheckModel(model); + if (_companyStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(CompanyBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_companyStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(CompanyBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Нет названия ", nameof(model.Title)); + } + + if (model.StatusId <= 0) + { + throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); + } + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Title); + var element = _companyStorage.GetElement(new CompanySM + { + Id = model.Id, + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой компания уже есть"); + } + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/HumanBL.cs b/Subd/BusinessLogic/BusinessLogic/HumanBL.cs new file mode 100644 index 0000000..9a382de --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/HumanBL.cs @@ -0,0 +1,120 @@ +using BusinessBL.BusinessBL; +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using DataBase.Implements; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class HumanBL : IHumanLogic + { + private readonly ILogger _logger; + private readonly IHumanStorage _humanStorage; + public HumanBL(ILogger logger, IHumanStorage humanStorage) + { + _logger = logger; + _humanStorage = humanStorage; + } + public List? ReadList(HumanSM? model) + { + _logger.LogInformation("ReadList. HumanName:{HumanName}.Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _humanStorage.GetFullList() : _humanStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public HumanVM? ReadElement(HumanSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. HumanName:{HumanName}. Id:{ Id}", model.Name, model.Id); + var element = _humanStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(HumanBM model) + { + CheckModel(model); + if (_humanStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(HumanBM model) + { + CheckModel(model); + if (_humanStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(HumanBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_humanStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(HumanBM 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.Phone)) + { + throw new ArgumentNullException("Нет номера телефона", nameof(model.Phone)); + } + if (model.StatusId <= 0) + { + throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); + } + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Name); + var element = _humanStorage.GetElement(new HumanSM + { + Id = model.Id, + Phone = model.Phone + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой водитель уже есть"); + } + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs b/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs new file mode 100644 index 0000000..60de938 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs @@ -0,0 +1,115 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using DataBase.Implements; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class PlaceBL : IPlaceLogic + { + private readonly ILogger _logger; + private readonly IPlaceStorage _placeStorage; + public PlaceBL(ILogger logger, IPlaceStorage placeStorage) + { + _logger = logger; + _placeStorage = placeStorage; + } + + public PlaceVM? ReadElement(PlaceSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _placeStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(PlaceBM model) + { + CheckModel(model); + if (_placeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PlaceBM model) + { + CheckModel(model); + if (_placeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PlaceBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_placeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PlaceBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Нет названия ", nameof(model.Title)); + } + + + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Title); + var element = _placeStorage.GetElement(new PlaceSM + { + Id = model.Id, + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой статус уже есть"); + } + } + + public List? ReadList(PlaceSM model) + { + _logger.LogInformation("ReadList. CarName:{CarName}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _placeStorage.GetFullList() : _placeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/RouteBL.cs b/Subd/BusinessLogic/BusinessLogic/RouteBL.cs new file mode 100644 index 0000000..3ad50d0 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/RouteBL.cs @@ -0,0 +1,121 @@ +using BusinessBL.BusinessBL; +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using DataBase.Implements; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class RouteBL : IRouteLogic + { + private readonly ILogger _logger; + private readonly IRouteStorage _routeStorage; + public RouteBL(ILogger logger, IRouteStorage routeStorage) + { + _logger = logger; + _routeStorage = routeStorage; + } + public List? ReadList(RouteSM? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _routeStorage.GetFullList() : _routeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public RouteVM? ReadElement(RouteSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _routeStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(RouteBM model) + { + CheckModel(model); + if (_routeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(RouteBM model) + { + CheckModel(model); + if (_routeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(RouteBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_routeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(RouteBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Length <= 0) + { + throw new ArgumentNullException("Нет длины маршрута", nameof(model.Length)); + } + if (model.PlaceStart <= 0) + { + throw new ArgumentNullException("нет т-ки отправления", nameof(model.PlaceStart)); + } + if (model.PlaceStart <= 0) + { + throw new ArgumentNullException("нет т-ки назначения", nameof(model.PlaceEnd)); + } + + var element = _routeStorage.GetElement(new RouteSM + { + Id = model.Id, + Start = model.PlaceStart, + End = model.PlaceEnd + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой маршрут уже есть"); + } + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/StatusBL.cs b/Subd/BusinessLogic/BusinessLogic/StatusBL.cs new file mode 100644 index 0000000..fbee975 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/StatusBL.cs @@ -0,0 +1,112 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class StatusBL : IStatusLogic + { + private readonly ILogger _logger; + private readonly IStatusStorage _statusStorage; + public StatusBL(ILogger logger, IStatusStorage statusStorage) + { + _logger = logger; + _statusStorage = statusStorage; + } + public List? ReadList() + { + _logger.LogInformation("ReadList"); + var list = _statusStorage.GetFullList() ; + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public StatusVM? ReadElement(StatusSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _statusStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(StatusBM model) + { + CheckModel(model); + if (_statusStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(StatusBM model) + { + CheckModel(model); + if (_statusStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(StatusBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_statusStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(StatusBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Нет названия ", nameof(model.Title)); + } + + + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Title); + var element = _statusStorage.GetElement(new StatusSM + { + Id = model.Id, + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой статус уже есть"); + } + } + } +} diff --git a/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs new file mode 100644 index 0000000..57b48e5 --- /dev/null +++ b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs @@ -0,0 +1,112 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class VoyageBL : IVoyageLogic + { + private readonly ILogger _logger; + private readonly IVoyageStorage _voyageStorage; + public VoyageBL(ILogger logger, IVoyageStorage voyageStorage) + { + _logger = logger; + _voyageStorage = voyageStorage; + } + public List? ReadList(VoyageSM? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _voyageStorage.GetFullList() : _voyageStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public VoyageVM? ReadElement(VoyageSM model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _voyageStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(VoyageBM model) + { + CheckModel(model); + if (_voyageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(VoyageBM model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_voyageStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(VoyageBM model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.CarId <= 0) + { + throw new ArgumentNullException("Нет машины", nameof(model.CarId)); + } + if (model.CompanyId <= 0) + { + throw new ArgumentNullException("нет заказчкика", nameof(model.CompanyId)); + } + if (model.HumanId <= 0) + { + throw new ArgumentNullException("нет водилы", nameof(model.HumanId)); + } + if (model.HumanId <= 0) + { + throw new ArgumentNullException("нет водилы", nameof(model.HumanId)); + } + if (!model.DateEnd.HasValue) + { + throw new ArgumentNullException("нет дедлайна", nameof(model.HumanId)); + } + if (!model.DateStart.HasValue) + { + throw new ArgumentNullException("нет даты выезда", nameof(model.HumanId)); + } + + } + } +} diff --git a/Subd/Contracts/BusinessLogic/IVoyageLogic.cs b/Subd/Contracts/BusinessLogic/IVoyageLogic.cs index 8561059..2073eb2 100644 --- a/Subd/Contracts/BusinessLogic/IVoyageLogic.cs +++ b/Subd/Contracts/BusinessLogic/IVoyageLogic.cs @@ -14,7 +14,7 @@ namespace Contracts.BusinessLogic List? ReadList(VoyageSM model); VoyageVM? ReadElement(VoyageSM model); bool Create(VoyageBM model); - bool Update(VoyageBM model); + bool Delete(VoyageBM model); } } diff --git a/Subd/Contracts/SearchModel/HumanSM.cs b/Subd/Contracts/SearchModel/HumanSM.cs index abcd7ab..1152a28 100644 --- a/Subd/Contracts/SearchModel/HumanSM.cs +++ b/Subd/Contracts/SearchModel/HumanSM.cs @@ -10,6 +10,7 @@ namespace Contracts.SearchModel { public string? Name { get; set; } public int? Id { get; set; } + public string? Phone { get; set; } public int? StatusId { get; set; } } } diff --git a/Subd/Contracts/SearchModel/RouteSM.cs b/Subd/Contracts/SearchModel/RouteSM.cs index a299c6f..cbfd662 100644 --- a/Subd/Contracts/SearchModel/RouteSM.cs +++ b/Subd/Contracts/SearchModel/RouteSM.cs @@ -10,5 +10,7 @@ namespace Contracts.SearchModel { public int? Length { get; set; } public int? Id { get; set; } + public int? Start { get; set; } + public int? End { get; set; } } } diff --git a/Subd/Contracts/SearchModel/StatusSM.cs b/Subd/Contracts/SearchModel/StatusSM.cs index 2a37c0a..a8bcc5c 100644 --- a/Subd/Contracts/SearchModel/StatusSM.cs +++ b/Subd/Contracts/SearchModel/StatusSM.cs @@ -9,5 +9,6 @@ namespace Contracts.SearchModel public class StatusSM { public int? Id { get; set; } + public string? Title { get; set; } } } diff --git a/Subd/DataBase/Implements/CompanyStorage.cs b/Subd/DataBase/Implements/CompanyStorage.cs index 1e07b8e..0143c57 100644 --- a/Subd/DataBase/Implements/CompanyStorage.cs +++ b/Subd/DataBase/Implements/CompanyStorage.cs @@ -39,13 +39,13 @@ namespace DataBase.Implements public CompanyVM? GetElement(CompanySM model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Title)) { return null; } using var context = new LogisticContext(); return context.Companies - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title))) ?.GetViewModel; } diff --git a/Subd/DataBase/Implements/HumanStorage.cs b/Subd/DataBase/Implements/HumanStorage.cs index b0d3a42..3542bb0 100644 --- a/Subd/DataBase/Implements/HumanStorage.cs +++ b/Subd/DataBase/Implements/HumanStorage.cs @@ -39,13 +39,13 @@ namespace DataBase.Implements public HumanVM? GetElement(HumanSM model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Phone)) { return null; } using var context = new LogisticContext(); return context.Humans - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Phone) && x.Phone.Equals(model.Phone))) ?.GetViewModel; } diff --git a/Subd/DataBase/Implements/RouteStorage.cs b/Subd/DataBase/Implements/RouteStorage.cs index 9b40b4a..ffeef52 100644 --- a/Subd/DataBase/Implements/RouteStorage.cs +++ b/Subd/DataBase/Implements/RouteStorage.cs @@ -24,28 +24,39 @@ namespace DataBase.Implements public List GetFilteredList(RouteSM model) { - if (model.Length.HasValue) + if (!model.Length.HasValue && !model.Start.HasValue && !model.End.HasValue) { return new(); } using var context = new LogisticContext(); + if(model.Length.HasValue) return context.Routes .FromSqlRaw("Select * FROM Route WHERE Length <= {0}", model.Length) .ToList() .Select(x => x.GetViewModel) .ToList(); - + else if(model.Start.HasValue) + return context.Routes + .FromSqlRaw("Select * FROM Route WHERE PlaceStart = {0} ", model.Start) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + return context.Routes + .FromSqlRaw("Select * FROM Route WHERE PlaceEnd = {0} ", model.End) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public RouteVM? GetElement(RouteSM model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.Start.HasValue && !model.End.HasValue) { return null; } using var context = new LogisticContext(); return context.Routes - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.Start.HasValue && model.End.HasValue && x.PlaceEnd == model.End && x.PlaceStart == model.Start )) ?.GetViewModel; } diff --git a/Subd/DataBase/Implements/StatusStorage.cs b/Subd/DataBase/Implements/StatusStorage.cs index f4161e7..701592b 100644 --- a/Subd/DataBase/Implements/StatusStorage.cs +++ b/Subd/DataBase/Implements/StatusStorage.cs @@ -26,13 +26,13 @@ namespace DataBase.Implements public StatusVM? GetElement(StatusSM model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Title)) { return null; } using var context = new LogisticContext(); return context.Statuses - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title))) ?.GetViewModel; } diff --git a/Subd/Subd.sln b/Subd/Subd.sln index 9daa5b0..72aaa19 100644 --- a/Subd/Subd.sln +++ b/Subd/Subd.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBase", "DataBase\DataBa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{6ED0D589-EC71-42CE-A20E-C7C1E036F26B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}.Release|Any CPU.Build.0 = Release|Any CPU + {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE