Upload files to 'STOBusinessLogic'

This commit is contained in:
Ivan_Starostin 2024-05-01 14:30:09 +04:00
parent 63670ccdb7
commit da69110d3f
5 changed files with 479 additions and 0 deletions

View File

@ -0,0 +1,124 @@
using Microsoft.Extensions.Logging;
using STOContracts.BindingModels;
using STOContracts.BusinessLogicsContracts;
using STOContracts.SearchModels;
using STOContracts.StorageContracts;
using STOContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShipyardBusinessLogic
{
public class CarLogic: ICarLogic
{
private readonly ILogger _logger;
private readonly ICarStorage _CarStorage;
public CarLogic(ILogger<CarLogic> logger, ICarStorage CarStorage)
{
_logger = logger;
_CarStorage = CarStorage;
}
public List<CarViewModel>? ReadList(CarSearchModel? model)
{
_logger.LogInformation("ReadList. CarNumber:{CarNumber}. Id:{ Id}", model?.CarNumber, 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 CarViewModel? ReadElement(CarSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. CarNumber:{CarNumber}.Id:{ Id}", model.CarNumber, 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(CarBindingModel model)
{
CheckModel(model);
if (_CarStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(CarBindingModel model)
{
CheckModel(model);
if (_CarStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(CarBindingModel 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(CarBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.CarNumber))
{
throw new ArgumentNullException("Нет гос номера автомобиля",
nameof(model.CarNumber));
}
if (string.IsNullOrEmpty(model.CarBrand))
{
throw new ArgumentNullException("Нет марки автомобиля",
nameof(model.CarNumber));
}
if (string.IsNullOrEmpty(model.CarModel))
{
throw new ArgumentNullException("Нет модели автомобиля",
nameof(model.CarNumber));
}
_logger.LogInformation("Car. Car:{Car}. Id: { Id}", model.CarNumber, model.Id);
var element = _CarStorage.GetElement(new CarSearchModel
{
CarNumber = model.CarNumber
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("авто с таким номером уже есть");
}
}
}
}

View File

@ -0,0 +1,106 @@
using Microsoft.Extensions.Logging;
using STOContracts.BindingModels;
using STOContracts.BusinessLogicContracts;
using STOContracts.SearchModels;
using STOContracts.StorageContracts;
using STOContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STOBusinessLogic
{
public class CarPartLogic: ICarPartLogic
{
private readonly ILogger _logger;
private readonly ICarPartStorage _CarPartStorage;
public CarPartLogic(ILogger<CarPartLogic> logger, ICarPartStorage CarPartStorage)
{
_logger = logger;
_CarPartStorage = CarPartStorage;
}
public List<CarPartViewModel>? ReadList(CarPartSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _CarPartStorage.GetFullList() : _CarPartStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public CarPartViewModel? ReadElement(CarPartSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement.Id:{ Id}", model.Id);
var element = _CarPartStorage.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(CarPartBindingModel model)
{
CheckModel(model);
if (_CarPartStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(CarPartBindingModel model)
{
CheckModel(model);
if (_CarPartStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(CarPartBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_CarPartStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(CarPartBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.CarPartName))
{
throw new ArgumentNullException("Нет запчасти",
nameof(model.CarPartName));
}
_logger.LogInformation("CarPart. CarPart:{CarPartName}. Id: { Id}", model.CarPartName, model.Id);
}
}
}

View File

@ -0,0 +1,124 @@
using Microsoft.Extensions.Logging;
using STOContracts.BindingModels;
using STOContracts.BusinessLogicContracts;
using STOContracts.SearchModels;
using STOContracts.StorageContracts;
using STOContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STOBusinessLogic
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _ClientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage ClientStorage)
{
_logger = logger;
_ClientStorage = ClientStorage;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. ClientEmail:{Email}. Id:{ Id}", model?.Email, model?.Id);
var list = model == null ? _ClientStorage.GetFullList() : _ClientStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientEmail:{Email}.Id:{ Id}", model.Email, model.Id);
var element = _ClientStorage.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(ClientBindingModel model)
{
CheckModel(model);
if (_ClientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_ClientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_ClientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет email",
nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля",
nameof(model.Password));
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет ФИО",
nameof(model.ClientFIO));
}
_logger.LogInformation("Client. ClientEmail:{Email}. Id: { Id}", model.Email, model.Id);
var element = _ClientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("работник с такой почтой уже есть");
}
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\STOContracts\STOContracts\STOContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,106 @@
using Microsoft.Extensions.Logging;
using STOContracts.BindingModels;
using STOContracts.BusinessLogicsContracts;
using STOContracts.SearchModels;
using STOContracts.StorageContracts;
using STOContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STOBusinessLogic
{
public class ServiceLogic: IServiceLogic
{
private readonly ILogger _logger;
private readonly IServiceStorage _ServiceStorage;
public ServiceLogic(ILogger<ServiceLogic> logger, IServiceStorage ServiceStorage)
{
_logger = logger;
_ServiceStorage = ServiceStorage;
}
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _ServiceStorage.GetFullList() : _ServiceStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ServiceViewModel? ReadElement(ServiceSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement.Id:{ Id}", model.Id);
var element = _ServiceStorage.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(ServiceBindingModel model)
{
CheckModel(model);
if (_ServiceStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ServiceBindingModel model)
{
CheckModel(model);
if (_ServiceStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ServiceBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_ServiceStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ServiceBindingModel 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("CarPart. Id: { Id}", model.Id);
}
}
}