исправления3
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HookArmsContract\HookArmsContract.csproj" />
|
||||
<ProjectReference Include="..\HookArmsDatabase\HookArmsDatabase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class CarBusinessLogic : ICarBusinessLogic
|
||||
{
|
||||
private readonly ICarStorageContract _storage;
|
||||
private readonly ICustomerStorageContract _customerStorage;
|
||||
private readonly ILogger<CarBusinessLogic> _logger;
|
||||
|
||||
public CarBusinessLogic(
|
||||
ICarStorageContract storage,
|
||||
ICustomerStorageContract customerStorage,
|
||||
ILogger<CarBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_customerStorage = customerStorage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<CarDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех машин");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public CarDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID машины");
|
||||
|
||||
var item = _storage.GetById(id);
|
||||
return item ?? throw new ElementNotFoundException($"Машина {id} не найдена");
|
||||
}
|
||||
|
||||
public void Add(CarDataModel machine)
|
||||
{
|
||||
machine.Validate();
|
||||
|
||||
var customer = _customerStorage.GetById(machine.CustomerId);
|
||||
if (customer == null)
|
||||
throw new ValidationException("Заказчик не найден");
|
||||
|
||||
if (_storage.GetList().Any(m => m.LicensePlate == machine.LicensePlate))
|
||||
throw new ElementExistsException(machine.LicensePlate, "Машина с таким номером уже существует");
|
||||
|
||||
_storage.Add(machine);
|
||||
_logger.LogInformation($"Добавлена машина: {machine.Id}");
|
||||
}
|
||||
|
||||
public void Update(CarDataModel machine)
|
||||
{
|
||||
var existing = GetById(machine.Id);
|
||||
machine.Validate();
|
||||
|
||||
if (existing.LicensePlate != machine.LicensePlate &&
|
||||
_storage.GetList().Any(m => m.LicensePlate == machine.LicensePlate))
|
||||
throw new ElementExistsException(machine.LicensePlate, "Машина с таким номером уже существует");
|
||||
|
||||
_storage.Update(machine);
|
||||
_logger.LogInformation($"Обновлена машина: {machine.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var item = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удалена машина: {id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class CustomerBusinessLogic : ICustomerBusinessLogic
|
||||
{
|
||||
private readonly ICustomerStorageContract _storage;
|
||||
private readonly ILogger<CustomerBusinessLogic> _logger;
|
||||
|
||||
public CustomerBusinessLogic(
|
||||
ICustomerStorageContract storage,
|
||||
ILogger<CustomerBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<CustomerDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех заказчиков");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public CustomerDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID заказчика");
|
||||
|
||||
var item = _storage.GetById(id);
|
||||
return item ?? throw new ElementNotFoundException($"Заказчик {id} не найден");
|
||||
}
|
||||
|
||||
public void Add(CustomerDataModel customer)
|
||||
{
|
||||
customer.Validate();
|
||||
|
||||
if (_storage.GetList().Any(c => c.Phone == customer.Phone))
|
||||
throw new ElementExistsException(customer.Phone, "Заказчик с таким телефоном уже существует");
|
||||
|
||||
_storage.Add(customer);
|
||||
_logger.LogInformation($"Добавлен заказчик: {customer.Id}");
|
||||
}
|
||||
|
||||
public void Update(CustomerDataModel customer)
|
||||
{
|
||||
var existing = GetById(customer.Id);
|
||||
customer.Validate();
|
||||
|
||||
if (existing.Phone != customer.Phone &&
|
||||
_storage.GetList().Any(c => c.Phone == customer.Phone))
|
||||
throw new ElementExistsException(customer.Phone, "Заказчик с таким телефоном уже существует");
|
||||
|
||||
_storage.Update(customer);
|
||||
_logger.LogInformation($"Обновлен заказчик: {customer.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var item = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удален заказчик: {id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class ExecutorBusinessLogic : IExecutorBusinessLogic
|
||||
{
|
||||
private readonly IExecutorStorageContract _storage;
|
||||
private readonly ILogger<ExecutorBusinessLogic> _logger;
|
||||
public ExecutorBusinessLogic(
|
||||
IExecutorStorageContract storage,
|
||||
ILogger<ExecutorBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<ExecutorDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех исполнителей");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public ExecutorDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID исполнителя");
|
||||
|
||||
var item = _storage.GetById(id);
|
||||
return item ?? throw new ElementNotFoundException($"Исполнитель {id} не найден");
|
||||
}
|
||||
|
||||
public void Add(ExecutorDataModel worker)
|
||||
{
|
||||
worker.Validate();
|
||||
|
||||
if (_storage.GetList().Any(w => w.Phone == worker.Phone))
|
||||
throw new ElementExistsException(worker.Phone, "Исполнитель с таким телефоном уже существует");
|
||||
|
||||
_storage.Add(worker);
|
||||
_logger.LogInformation($"Добавлен исполнитель: {worker.Id}");
|
||||
}
|
||||
|
||||
public void Update(ExecutorDataModel worker)
|
||||
{
|
||||
var existing = GetById(worker.Id);
|
||||
worker.Validate();
|
||||
|
||||
if (existing.Phone != worker.Phone &&
|
||||
_storage.GetList().Any(w => w.Phone == worker.Phone))
|
||||
throw new ElementExistsException(worker.Phone, "Исполнитель с таким телефоном уже существует");
|
||||
|
||||
_storage.Update(worker);
|
||||
_logger.LogInformation($"Обновлен исполнитель: {worker.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var item = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удален исполнитель: {id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class MaintenanceBusinessLogic : IMaintenanceBusinessLogic
|
||||
{
|
||||
private readonly IMaintenanceStorageContract _storage;
|
||||
private readonly ICarStorageContract _machineStorage;
|
||||
private readonly IWorkStorageContract _workStorage;
|
||||
private readonly ILogger<MaintenanceBusinessLogic> _logger;
|
||||
|
||||
public MaintenanceBusinessLogic(
|
||||
IMaintenanceStorageContract storage,
|
||||
ICarStorageContract machineStorage,
|
||||
IWorkStorageContract workStorage,
|
||||
ILogger<MaintenanceBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_machineStorage = machineStorage;
|
||||
_workStorage = workStorage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<MaintenanceDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех ТО");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public MaintenanceDataModel GetById(string id)
|
||||
{
|
||||
if (id.IsEmpty() || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID ТО");
|
||||
|
||||
var maintenance = _storage.GetById(id);
|
||||
return maintenance ?? throw new ElementNotFoundException($"ТО с ID {id} не найден");
|
||||
}
|
||||
|
||||
public void Add(MaintenanceDataModel maintenance)
|
||||
{
|
||||
// Валидация модели
|
||||
maintenance.Validate();
|
||||
|
||||
// Проверка существования машины
|
||||
var machine = _machineStorage.GetById(maintenance.MachineId);
|
||||
if (machine == null)
|
||||
throw new ElementNotFoundException($"Машина {maintenance.MachineId} не найдена");
|
||||
|
||||
// Проверка существования работ
|
||||
foreach (var work in maintenance.Works)
|
||||
{
|
||||
var existingWork = _workStorage.GetById(work.Id);
|
||||
if (existingWork == null)
|
||||
throw new ElementNotFoundException($"Работа {work.Id} не найдена");
|
||||
}
|
||||
|
||||
// Добавление в хранилище
|
||||
_storage.Add(maintenance);
|
||||
_logger.LogInformation($"Добавлено ТО: {maintenance.Id}");
|
||||
}
|
||||
|
||||
public void Update(MaintenanceDataModel maintenance)
|
||||
{
|
||||
// Проверка существования записи
|
||||
var existingMaintenance = GetById(maintenance.Id);
|
||||
|
||||
// Валидация модели
|
||||
maintenance.Validate();
|
||||
|
||||
// Обновление машины (если изменился ID)
|
||||
if (existingMaintenance.MachineId != maintenance.MachineId)
|
||||
{
|
||||
var newMachine = _machineStorage.GetById(maintenance.MachineId);
|
||||
if (newMachine == null)
|
||||
throw new ElementNotFoundException($"Машина {maintenance.MachineId} не найдена");
|
||||
}
|
||||
|
||||
// Обновление работ
|
||||
foreach (var work in maintenance.Works)
|
||||
{
|
||||
var existingWork = _workStorage.GetById(work.Id);
|
||||
if (existingWork == null)
|
||||
throw new ElementNotFoundException($"Работа {work.Id} не найдена");
|
||||
}
|
||||
|
||||
// Сохранение изменений
|
||||
_storage.Update(maintenance);
|
||||
_logger.LogInformation($"Обновлено ТО: {maintenance.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var maintenance = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удалено ТО: {id}");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HookArmsContract
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implementations;
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class MalfunctionBusinessLogic : IMalfunctionBusinessLogic
|
||||
{
|
||||
@@ -28,7 +27,7 @@ public class MalfunctionBusinessLogic : IMalfunctionBusinessLogic
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID");
|
||||
|
||||
return _storage.GetById(id) ?? throw new NotFoundException("Неисправность не найдена");
|
||||
return _storage.GetById(id) ?? throw new ElementNotFoundException("Неисправность не найдена");
|
||||
}
|
||||
|
||||
public void Add(MalfunctionDataModel malfunction)
|
||||
@@ -0,0 +1,67 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class RepairBusinessLogic : IRepairBusinessLogic
|
||||
{
|
||||
private readonly IRepairStorageContract _storage;
|
||||
private readonly ISparePartStorageContract _sparePartStorage;
|
||||
private readonly ILogger<RepairBusinessLogic> _logger;
|
||||
|
||||
public RepairBusinessLogic(
|
||||
IRepairStorageContract storage,
|
||||
ISparePartStorageContract sparePartStorage,
|
||||
ILogger<RepairBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_sparePartStorage = sparePartStorage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Add(RepairDataModel repair)
|
||||
{
|
||||
repair.Validate();
|
||||
|
||||
|
||||
foreach (var part in repair.SpareParts)
|
||||
{
|
||||
var existingPart = _sparePartStorage.GetById(part.Id);
|
||||
if (existingPart == null || existingPart.Stock < existingPart.Stock - 1)
|
||||
throw new ValidationException($"Недостаточно запчасти: {part.Name}");
|
||||
}
|
||||
|
||||
_storage.Add(repair);
|
||||
_logger.LogInformation($"Добавлен ремонт: {repair.Id}");
|
||||
}
|
||||
|
||||
public List<RepairDataModel> GetAll() => _storage.GetList();
|
||||
|
||||
public RepairDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID");
|
||||
|
||||
return _storage.GetById(id) ?? throw new ElementNotFoundException("Неисправность не найдена");
|
||||
}
|
||||
|
||||
public void Update(RepairDataModel malfunction)
|
||||
{
|
||||
malfunction.Validate();
|
||||
_storage.Update(malfunction);
|
||||
_logger.LogInformation($"Обновлена неисправность: {malfunction.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID");
|
||||
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удалена неисправность: {id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class SparePartBusinessLogic : ISparePartBusinessLogic
|
||||
{
|
||||
private readonly ISparePartStorageContract _storage;
|
||||
private readonly ILogger<SparePartBusinessLogic> _logger;
|
||||
|
||||
public SparePartBusinessLogic(
|
||||
ISparePartStorageContract storage,
|
||||
ILogger<SparePartBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<SparePartDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех запчастей");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public SparePartDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID запчасти");
|
||||
|
||||
var item = _storage.GetById(id);
|
||||
return item ?? throw new ElementNotFoundException($"Запчасть {id} не найдена");
|
||||
}
|
||||
|
||||
public void Add(SparePartDataModel sparePart)
|
||||
{
|
||||
sparePart.Validate();
|
||||
|
||||
if (_storage.GetList().Any(s => s.Article == sparePart.Article))
|
||||
throw new ElementExistsException(sparePart.Article, "Запчасть с таким артикулом уже существует");
|
||||
|
||||
_storage.Add(sparePart);
|
||||
_logger.LogInformation($"Добавлена запчасть: {sparePart.Id}");
|
||||
}
|
||||
|
||||
public void Update(SparePartDataModel sparePart)
|
||||
{
|
||||
var existing = GetById(sparePart.Id);
|
||||
sparePart.Validate();
|
||||
|
||||
if (existing.Article != sparePart.Article &&
|
||||
_storage.GetList().Any(s => s.Article == sparePart.Article))
|
||||
throw new ElementExistsException(sparePart.Article, "Запчасть с таким артикулом уже существует");
|
||||
|
||||
_storage.Update(sparePart);
|
||||
_logger.LogInformation($"Обновлена запчасть: {sparePart.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var item = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удалена запчасть: {id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using HookArmsContract.BusinessLogicsContracts;
|
||||
using HookArmsContract.DataModels;
|
||||
using HookArmsContract.Exceptions;
|
||||
using HookArmsContract.Extensions;
|
||||
using HookArmsContract.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HookArmsBusinessLogic.Implemetations;
|
||||
|
||||
public class WorkBusinessLogic : IWorkBusinessLogic
|
||||
{
|
||||
private readonly IWorkStorageContract _storage;
|
||||
private readonly ILogger<WorkBusinessLogic> _logger;
|
||||
|
||||
public WorkBusinessLogic(
|
||||
IWorkStorageContract storage,
|
||||
ILogger<WorkBusinessLogic> logger)
|
||||
{
|
||||
_storage = storage;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<WorkDataModel> GetAll()
|
||||
{
|
||||
_logger.LogInformation("Запрос всех работ");
|
||||
return _storage.GetList();
|
||||
}
|
||||
|
||||
public WorkDataModel GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || !id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID работы");
|
||||
|
||||
var item = _storage.GetById(id);
|
||||
return item ?? throw new ElementNotFoundException($"Работа {id} не найдена");
|
||||
}
|
||||
|
||||
public void Add(WorkDataModel work)
|
||||
{
|
||||
work.Validate();
|
||||
|
||||
if (work.WorkDate > DateTime.UtcNow)
|
||||
throw new ValidationException("Дата работы не может быть в будущем");
|
||||
|
||||
_storage.Add(work);
|
||||
_logger.LogInformation($"Добавлена работа: {work.Id}");
|
||||
}
|
||||
|
||||
public void Update(WorkDataModel work)
|
||||
{
|
||||
var existing = GetById(work.Id);
|
||||
work.Validate();
|
||||
|
||||
if (work.WorkDate > DateTime.UtcNow)
|
||||
throw new ValidationException("Дата работы не может быть в будущем");
|
||||
|
||||
_storage.Update(work);
|
||||
_logger.LogInformation($"Обновлена работа: {work.Id}");
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var item = GetById(id);
|
||||
_storage.Delete(id);
|
||||
_logger.LogInformation($"Удалена работа: {id}");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HookArmsContract", "HookArm
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HookArmsDatabase", "HookArmsDatabase\HookArmsDatabase.csproj", "{23DCE4A6-B06B-44E5-ACCF-C85EAC80178F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HookArmsBusinessLogic", "HookArmsBusinessLogic\HookArmsBusinessLogic.csproj", "{08047FFC-2F9B-4BA8-B1B4-F0AC40F0C111}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -21,6 +23,10 @@ Global
|
||||
{23DCE4A6-B06B-44E5-ACCF-C85EAC80178F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23DCE4A6-B06B-44E5-ACCF-C85EAC80178F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23DCE4A6-B06B-44E5-ACCF-C85EAC80178F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{08047FFC-2F9B-4BA8-B1B4-F0AC40F0C111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{08047FFC-2F9B-4BA8-B1B4-F0AC40F0C111}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{08047FFC-2F9B-4BA8-B1B4-F0AC40F0C111}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{08047FFC-2F9B-4BA8-B1B4-F0AC40F0C111}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -5,29 +5,22 @@ using HookArmsContract.Infrastructure;
|
||||
|
||||
namespace HookArmsContract.DataModels;
|
||||
|
||||
public class CarDataModel(
|
||||
string id,
|
||||
string licensePlate,
|
||||
string model,
|
||||
BodyType bodyType,
|
||||
CustomerDataModel customer,
|
||||
List<MalfunctionDataModel> malfunctions,
|
||||
List<MaintenanceDataModel> maintenances) : IValidation
|
||||
public class CarDataModel : IValidation
|
||||
{
|
||||
public string Id { get; } = id;
|
||||
public string LicensePlate { get; } = licensePlate;
|
||||
public string Model { get; } = model;
|
||||
public BodyType BodyType { get; } = bodyType;
|
||||
public CustomerDataModel Customer { get; } = customer;
|
||||
public List<MalfunctionDataModel> Malfunctions { get; } = malfunctions;
|
||||
public List<MaintenanceDataModel> Maintenances { get; } = maintenances;
|
||||
public string Id { get; set; }
|
||||
public string LicensePlate { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string CustomerId { get; set; } // Добавленное свойство
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (licensePlate.IsEmpty())
|
||||
if (Id.IsEmpty() || !Id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID автомобиля");
|
||||
|
||||
if (LicensePlate.IsEmpty())
|
||||
throw new ValidationException("Номерной знак обязателен");
|
||||
|
||||
if (customer == null)
|
||||
throw new ValidationException("Машина должна иметь владельца");
|
||||
if (CustomerId.IsEmpty() || !CustomerId.IsGuid())
|
||||
throw new ValidationException("Некорректный ID заказчика");
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,32 @@ public class MaintenanceDataModel(
|
||||
string id,
|
||||
DateTime date,
|
||||
string description,
|
||||
List<WorkDataModel> works,
|
||||
CustomerDataModel customer) : IValidation
|
||||
string machineId,
|
||||
string customerId,
|
||||
List<WorkDataModel> works) : IValidation
|
||||
{
|
||||
public string Id { get; } = id;
|
||||
public DateTime Date { get; } = date;
|
||||
public string Description { get; } = description;
|
||||
public string MachineId { get; } = machineId;
|
||||
public string CustomerId { get; } = customerId;
|
||||
public List<WorkDataModel> Works { get; } = works;
|
||||
public CustomerDataModel Customer { get; } = customer;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (works.Count == 0)
|
||||
throw new ValidationException("Необходимы работы для ТО");
|
||||
if (Id.IsEmpty() || !Id.IsGuid())
|
||||
throw new ValidationException("Некорректный ID обслуживания");
|
||||
|
||||
if (Date > DateTime.UtcNow)
|
||||
throw new ValidationException("Дата обслуживания не может быть в будущем");
|
||||
|
||||
if (Description.IsEmpty())
|
||||
throw new ValidationException("Описание обязательно");
|
||||
|
||||
if (MachineId.IsEmpty() || !MachineId.IsGuid())
|
||||
throw new ValidationException("Некорректный ID машины");
|
||||
|
||||
if (Works.Count == 0)
|
||||
throw new ValidationException("Обслуживание должно включать работы");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user