BusinessLogic
This commit is contained in:
parent
6c7c5fa390
commit
14f80b4425
112
Sto/STOBusinessLogic/BusinessLogics/CarLogic.cs
Normal file
112
Sto/STOBusinessLogic/BusinessLogics/CarLogic.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CarLogic : ICarLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICarStorage _carStorage;
|
||||
public CarLogic(ILogger logger, ICarStorage carStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_carStorage = carStorage;
|
||||
}
|
||||
public List<CarViewModel>? ReadList(CarSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.CarId:{ CarId}", 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. CarId:{ CarId}", 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.Brand))
|
||||
{
|
||||
throw new ArgumentNullException("Нет бренда автомобиля", nameof(model.Brand));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Model))
|
||||
{
|
||||
throw new ArgumentNullException("Нет модели автомобиля", nameof(model.Model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.VIN))
|
||||
{
|
||||
throw new ArgumentNullException("Нет VIN автомобиля", nameof(model.Model));
|
||||
}
|
||||
var element = _carStorage.GetElement(new CarSearchModel
|
||||
{
|
||||
VIN = model.VIN
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Автомобиль с таким VIN уже есть");
|
||||
}
|
||||
_logger.LogInformation("Car. Id:{ Id}.CarBrand:{CarBrand}.CarModel:{CarModel}.CarVIN:{CarVIN}", model?.Id, model?.Brand, model?.Brand, model?.VIN);
|
||||
}
|
||||
}
|
||||
}
|
111
Sto/STOBusinessLogic/BusinessLogics/EmployerLogic.cs
Normal file
111
Sto/STOBusinessLogic/BusinessLogics/EmployerLogic.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class EmployerLogic : IEmployerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployerStorage _employerStorage;
|
||||
public EmployerLogic(ILogger logger, IEmployerStorage employerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_employerStorage = employerStorage;
|
||||
}
|
||||
public List<EmployerViewModel>? ReadList(EmployerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. EmployerId:{ EmployerId}", model?.Id);
|
||||
var list = model == null ? _employerStorage.GetFullList() : _employerStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public EmployerViewModel? ReadElement(EmployerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. EmployerId:{ EmployerId}", model?.Id);
|
||||
var element = _employerStorage.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(EmployerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(EmployerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(EmployerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_employerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(EmployerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина работника", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почты работника", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля работника", nameof(model.Password));
|
||||
}
|
||||
var element = _employerStorage.GetElement(new EmployerSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("работник с таким логином уже есть");
|
||||
}
|
||||
_logger.LogInformation("Employer. EmployerId:{ Id}.EmployerLogin:{EmployerLogin}.EmployerEmail:{EmployerEmail}", model?.Id, model?.Login, model?.Email);
|
||||
}
|
||||
}
|
||||
}
|
99
Sto/STOBusinessLogic/BusinessLogics/MaintenanceLogic.cs
Normal file
99
Sto/STOBusinessLogic/BusinessLogics/MaintenanceLogic.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MaintenanceLogic : IMaintenanceLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMaintenanceStorage _maintenanceStorage;
|
||||
public MaintenanceLogic(ILogger logger, IMaintenanceStorage maintenanceStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_maintenanceStorage = maintenanceStorage;
|
||||
}
|
||||
public List<MaintenanceViewModel>? ReadList(MaintenanceSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MaintenanceId:{ MaintenanceId}", model?.Id);
|
||||
var list = model == null ? _maintenanceStorage.GetFullList() : _maintenanceStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public MaintenanceViewModel? ReadElement(MaintenanceSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. MaintenanceId:{ MaintenanceId}", model?.Id);
|
||||
var element = _maintenanceStorage.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(MaintenanceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_maintenanceStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MaintenanceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_maintenanceStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MaintenanceBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_maintenanceStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MaintenanceBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.EmployerId<0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор работника", nameof(model.EmployerId));
|
||||
}
|
||||
if (model.Cost<=0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость должна быть больше нуля", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Maintenance. MaintenanceId:{MaintenanceId}.EmployerId: { EmployerId}.Cost:{Cost}", model.Id, model.EmployerId, model.Cost);
|
||||
}
|
||||
}
|
||||
}
|
44
Sto/STOBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
44
Sto/STOBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly IWorkStorage _workStorage;
|
||||
private readonly ISpareStorage _spareStorage;
|
||||
public ReportLogic(IWorkStorage work, ISpareStorage spareStorage)
|
||||
{
|
||||
_workStorage = work;
|
||||
_spareStorage = spareStorage;
|
||||
}
|
||||
public List<ReportViewModel> GetSpares(ReportBindingModel model)
|
||||
{
|
||||
return _workStorage.GetFilteredList(new WorkSearchModel { DateTo = model.DateTo, DateFrom = model.DateFrom })
|
||||
.Select(x => new ReportViewModel
|
||||
{
|
||||
Name = x.Title,
|
||||
Spares = x.WorkSpares.Select(x => x.Value.Item1.Name).ToList(),
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public void SaveToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveToWordFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
91
Sto/STOBusinessLogic/BusinessLogics/ServiceLogic.cs
Normal file
91
Sto/STOBusinessLogic/BusinessLogics/ServiceLogic.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ServiceLogic : IServiceLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceStorage _serviceStorage;
|
||||
public ServiceLogic(ILogger logger, IServiceStorage serviceStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceStorage = serviceStorage;
|
||||
}
|
||||
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ServiceId:{ ServiceId}", 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. ServiceId:{ ServiceId}", 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;
|
||||
}
|
||||
_logger.LogInformation("Service. ServiceId: { ServiceId}.", model.Id);
|
||||
}
|
||||
}
|
||||
}
|
109
Sto/STOBusinessLogic/BusinessLogics/SpareLogic.cs
Normal file
109
Sto/STOBusinessLogic/BusinessLogics/SpareLogic.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class SpareLogic : ISpareLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISpareStorage _spareStorage;
|
||||
public SpareLogic(ILogger logger, ISpareStorage spareStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_spareStorage = spareStorage;
|
||||
}
|
||||
public List<SpareViewModel>? ReadList(SpareSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.SpareId:{Id}", model?.Id);
|
||||
var list = model == null ? _spareStorage.GetFullList() : _spareStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public SpareViewModel? ReadElement(SpareSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. SpareId:{Id}", model?.Id);
|
||||
var element = _spareStorage.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(SpareBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_spareStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(SpareBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_spareStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(SpareBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_spareStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(SpareBindingModel 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.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неправильная цена детали", nameof(model.Price));
|
||||
}
|
||||
|
||||
var element = _spareStorage.GetElement(new SpareSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Деталь с таким названием уже есть");
|
||||
}
|
||||
_logger.LogInformation("Spare. Id:{ Id}.Name:{Name}.Price:{Price}", model?.Id, model?.Name, model?.Price);
|
||||
}
|
||||
}
|
||||
}
|
113
Sto/STOBusinessLogic/BusinessLogics/StorekeeperLogic.cs
Normal file
113
Sto/STOBusinessLogic/BusinessLogics/StorekeeperLogic.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class StorekeeperLogic : IStorekeeperLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStorekeeperStorage _storekeeperStorage;
|
||||
public StorekeeperLogic(ILogger logger, IStorekeeperStorage storekeeperStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storekeeperStorage = storekeeperStorage;
|
||||
}
|
||||
public List<StorekeeperViewModel>? ReadList(StorekeeperSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.StorekeeperId:{Id}", model?.Id);
|
||||
var list = model == null ? _storekeeperStorage.GetFullList() : _storekeeperStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public StorekeeperViewModel? ReadElement(StorekeeperSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. StorekeeperId:{Id}", model?.Id);
|
||||
var element = _storekeeperStorage.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(StorekeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storekeeperStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(StorekeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storekeeperStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(StorekeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_storekeeperStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(StorekeeperBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина кладовщика", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля кладовщика", nameof(model.Password));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почты кладовщика", nameof(model.Email));
|
||||
}
|
||||
var element = _storekeeperStorage.GetElement(new StorekeeperSearchModel
|
||||
{
|
||||
Login = model.Login,
|
||||
Email = model.Email
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Кладовщик с такими параметрами уже есть");
|
||||
}
|
||||
_logger.LogInformation("Storekeeper. Id:{ Id}.Login:{Login}.Email:{Email}.Password:{Password}", model?.Id, model?.Login, model?.Email, model?.Password);
|
||||
}
|
||||
}
|
||||
}
|
96
Sto/STOBusinessLogic/BusinessLogics/WorkDurationLogic.cs
Normal file
96
Sto/STOBusinessLogic/BusinessLogics/WorkDurationLogic.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkDurationLogic : IWorkDurationLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWorkDurationStorage _workDurationStorage;
|
||||
public WorkDurationLogic(ILogger logger, IWorkDurationStorage workDurationStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_workDurationStorage = workDurationStorage;
|
||||
}
|
||||
public List<WorkDurationViewModel>? ReadList(WorkDurationSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.WorkDurationId:{Id}", model?.Id);
|
||||
var list = model == null ? _workDurationStorage.GetFullList() : _workDurationStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public WorkDurationViewModel? ReadElement(WorkDurationSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. WorkDurationId:{Id}", model?.Id);
|
||||
var element = _workDurationStorage.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(WorkDurationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workDurationStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(WorkDurationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workDurationStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(WorkDurationBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_workDurationStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(WorkDurationBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Duration < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Нет длительности", nameof(model.Duration));
|
||||
}
|
||||
_logger.LogInformation("WorkDuration. Id:{ Id}.Duration:{Duration}", model?.Id, model?.Duration);
|
||||
}
|
||||
}
|
||||
}
|
108
Sto/STOBusinessLogic/BusinessLogics/WorkLogic.cs
Normal file
108
Sto/STOBusinessLogic/BusinessLogics/WorkLogic.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using STOContracts.BindingModels;
|
||||
using STOContracts.BusinessLogicsContracts;
|
||||
using STOContracts.SearchModels;
|
||||
using STOContracts.StoragesContracts;
|
||||
using STOContracts.ViewModels;
|
||||
|
||||
namespace STOBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkLogic : IWorkLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWorkStorage _workStorage;
|
||||
public WorkLogic(ILogger logger, IWorkStorage workStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_workStorage = workStorage;
|
||||
}
|
||||
public List<WorkViewModel>? ReadList(WorkSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.WorkId:{Id}", model?.Id);
|
||||
var list = model == null ? _workStorage.GetFullList() : _workStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public WorkViewModel? ReadElement(WorkSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. WorkId:{ Id}", model?.Id);
|
||||
var element = _workStorage.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(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_workStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(WorkBindingModel 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.Price < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Нет цены работы", nameof(model.Price));
|
||||
}
|
||||
var element = _workStorage.GetElement(new WorkSearchModel
|
||||
{
|
||||
Title = model.Title,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Работа с таким именем уже есть");
|
||||
}
|
||||
_logger.LogInformation("Work. Id:{ Id}.Title:{Title}.Price:{Price}", model?.Id, model?.Title, model?.Price);
|
||||
}
|
||||
}
|
||||
}
|
26
Sto/STOBusinessLogic/STOBusinessLogic.csproj
Normal file
26
Sto/STOBusinessLogic/STOBusinessLogic.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Implements\**" />
|
||||
<Compile Remove="OfficePackage\**" />
|
||||
<EmbeddedResource Remove="Implements\**" />
|
||||
<EmbeddedResource Remove="OfficePackage\**" />
|
||||
<None Remove="Implements\**" />
|
||||
<None Remove="OfficePackage\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\STOContracts\STOContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user