BusinessLogic

This commit is contained in:
DeerElk 2024-05-16 04:53:14 +04:00
parent 06ad198c12
commit 9769db17f0
9 changed files with 793 additions and 79 deletions

View File

@ -10,11 +10,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceContracts", "DeviceCo
{E4D8A5BF-C4ED-4E90-A630-A8880C4B4436} = {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceBusinessLogic", "DeviceBusinessLogic\DeviceBusinessLogic.csproj", "{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceBusinessLogic", "DeviceBusinessLogic\DeviceBusinessLogic.csproj", "{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}"
ProjectSection(ProjectDependencies) = postProject
{FA3605A8-7525-47B5-BE3E-4A90001971B5} = {FA3605A8-7525-47B5-BE3E-4A90001971B5}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceDatabaseImplement", "DeviceDatabaseImplement\DeviceDatabaseImplement.csproj", "{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -33,6 +35,10 @@ Global
{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Release|Any CPU.Build.0 = Release|Any CPU
{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -7,55 +7,54 @@ using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
public class CabinetLogic : ICabinetLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger,
IClientStorage clientStorage)
private readonly ICabinetStorage _cabinetStorage;
public CabinetLogic(ILogger<CabinetLogic> logger,
ICabinetStorage cabinetStorage)
{
_logger = logger;
_clientStorage = clientStorage;
_cabinetStorage = cabinetStorage;
}
public bool Create(ClientBindingModel model)
public bool Create(CabinetBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
if (_cabinetStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model)
public bool Update(CabinetBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
if (_cabinetStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
public bool Delete(CabinetBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Snils: {Snils}", model.Snils);
if (_clientStorage.Delete(model) == null)
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_cabinetStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
public List<CabinetViewModel>? ReadList(CabinetSearchModel? model)
{
_logger.LogInformation(
"ReadList. ClientSurname: {ClientSurname} {ClientName} " +
"{ClientPatronomic}. Snils: {Snils}", model?.ClientSurname,
model?.ClientName, model?.ClientPatronymic, model?.Snils);
var list = model == null ? _clientStorage.GetFullList() :
_clientStorage.GetFilteredList(model);
"ReadList. Id: {Id}, Room: {Room}, Building: " +
"{Building}.", model?.Id, model?.Room, model?.Building);
var list = model == null ? _cabinetStorage.GetFullList() :
_cabinetStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
@ -64,27 +63,26 @@ namespace DeviceBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
public CabinetViewModel? ReadElement(CabinetSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation(
"ReadElement. ClientFullname: {ClientSurname} {ClientName} " +
"{ClientPatronomic}. Snils: {Snils}", model.ClientSurname,
model.ClientName, model.ClientPatronymic, model.Snils);
var element = _clientStorage.GetElement(model);
"ReadElemnt. Id: {Id}, Room: {Room}, Building: " +
"{Building}.", model?.Id, model?.Room, model?.Building);
var element = _cabinetStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Snils: {Snils}",
element.Snils);
_logger.LogInformation("ReadElement find. Id: {Id}",
element.Id);
return element;
}
private void CheckModel(ClientBindingModel model,
private void CheckModel(CabinetBindingModel model,
bool withParams = true)
{
if (model == null)
@ -95,71 +93,37 @@ namespace DeviceBusinessLogic.BusinessLogics
{
return;
}
if (string.IsNullOrEmpty(model.Snils))
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Отсутствует СНИЛС клиента",
nameof(model.Snils));
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.ClientSurname))
if (string.IsNullOrEmpty(model.Room))
{
throw new ArgumentNullException(
"Отсутствует фамилия клиента",
nameof(model.ClientSurname));
"Отсутствует номер/название кабинета",
nameof(model.Room));
}
if (string.IsNullOrEmpty(model.ClientName))
if (model.Building < 1)
{
throw new ArgumentNullException(
"Отсутствует имя клиента",
nameof(model.ClientName));
"Номер корпуса должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.ClientPatronymic))
{
throw new ArgumentNullException(
"Отсутствует отчество клиента",
nameof(model.ClientPatronymic));
}
if (string.IsNullOrEmpty(model.Phone))
{
throw new ArgumentNullException(
"Отсутствует номер телефона клиента",
nameof(model.Phone));
}
if (string.IsNullOrEmpty(model.PasswordHash))
{
throw new ArgumentNullException(
"Отсутствует пароль клиента",
nameof(model.PasswordHash));
}
if (model.WorkerId <= 0)
{
throw new ArgumentNullException(
"Идентификатор работника должен быть больше 0",
nameof(model.WorkerId));
}
_logger.LogInformation("Client. Snils: {Snils}. ClientFullname: " +
"{ClientSurname} {ClientName} {ClientPatronymic}. Phone: " +
"{Phone}. Email: {Email}. PasswordHash: {PasswordHash}.",
model.Snils, model.ClientSurname, model.ClientName,
model.ClientPatronymic, model.Phone, model.Email,
model.PasswordHash);
var elementByEmail = _clientStorage.GetElement(
new ClientSearchModel
_logger.LogInformation(
"Id: {Id}, Room: {Room}, Building: " +
"{Building}.", model?.Id, model?.Room, model?.Building);
var elementByRoom = _cabinetStorage.GetElement(
new CabinetSearchModel
{
Email = model.Email,
Room = model.Room,
});
var elementByPhone = _clientStorage.GetElement(
new ClientSearchModel
var elementByBuilding = _cabinetStorage.GetElement(
new CabinetSearchModel
{
Phone = model.Phone,
Building = model.Building,
});
if ((elementByEmail != null && elementByEmail.Snils != model.Snils)
|| (elementByPhone != null && elementByPhone.Snils
!= model.Snils))
{
throw new InvalidOperationException("Клиент с такой почтой " +
"или номером телефона уже существует");
}
}
}
}

View File

@ -0,0 +1,176 @@
using DeviceContracts.BindingModels;
using DeviceContracts.BusinessLogicsContracts;
using DeviceContracts.SearchModels;
using DeviceContracts.StoragesContracts;
using DeviceContracts.ViewModels;
using DeviceDataModels;
using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class DeviceLogic : IDeviceLogic
{
private readonly ILogger _logger;
private readonly IDeviceStorage _deviceStorage;
public DeviceLogic(ILogger<DeviceLogic> logger,
IDeviceStorage deviceStorage)
{
_logger = logger;
_deviceStorage = deviceStorage;
}
public bool Create(DeviceBindingModel model)
{
CheckModel(model);
if (_deviceStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DeviceBindingModel model)
{
CheckModel(model);
if (_deviceStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DeviceBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_deviceStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<DeviceViewModel>? ReadList(DeviceSearchModel? model)
{
_logger.LogInformation(
"ReadList. Id: {Id}, Model: {Model}, SerialNumber: " +
"{SerialNumber}, ProductionDate: {ProductionDate}, " +
"WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " +
"KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model,
model?.SerialNumber, model?.ProductionDate,
model?.WarrantyPeriod, model?.Condition,
model?.KindId, model?.KitId);
var list = model == null ? _deviceStorage.GetFullList() :
_deviceStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public DeviceViewModel? ReadElement(DeviceSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation(
"ReadElement. Id: {Id}, Model: {Model}, SerialNumber: " +
"{SerialNumber}, ProductionDate: {ProductionDate}, " +
"WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " +
"KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model,
model?.SerialNumber, model?.ProductionDate,
model?.WarrantyPeriod, model?.Condition,
model?.KindId, model?.KitId);
var element = _deviceStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}",
element.Id);
return element;
}
private void CheckModel(DeviceBindingModel model,
bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.Model))
{
throw new ArgumentNullException(
"Отсутствует название модели",
nameof(model.Model));
}
if ((model.Condition != true) && (model.Condition != false))
{
throw new ArgumentNullException(
"Отсутствует показатель работоспособности",
nameof(model.Model));
}
if (model.KindId <= 0)
{
throw new ArgumentNullException(
"Идентификатор вида должен быть больше 0",
nameof(model.Id));
}
_logger.LogInformation(
"ReadElement. Id: {Id}, Model: {Model}, SerialNumber: " +
"{SerialNumber}, ProductionDate: {ProductionDate}, " +
"WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " +
"KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model,
model?.SerialNumber, model?.ProductionDate,
model?.WarrantyPeriod, model?.Condition,
model?.KindId, model?.KitId);
var elementByModel = _deviceStorage.GetElement(
new DeviceSearchModel
{
Model = model.Model,
});
var elementBySerialNumber = _deviceStorage.GetElement(
new DeviceSearchModel
{
SerialNumber = model.SerialNumber,
});
var elementByProductionDate = _deviceStorage.GetElement(
new DeviceSearchModel
{
ProductionDate = model.ProductionDate,
});
var elementByWarrantyPeriod = _deviceStorage.GetElement(
new DeviceSearchModel
{
WarrantyPeriod = model.WarrantyPeriod,
});
var elementByCondition = _deviceStorage.GetElement(
new DeviceSearchModel
{
Condition = model.Condition,
});
var elementByKindId = _deviceStorage.GetElement(
new DeviceSearchModel
{
KindId = model.KindId,
});
var elementByKitId = _deviceStorage.GetElement(
new DeviceSearchModel
{
KitId = model.KitId,
});
}
}
}

View File

@ -0,0 +1,135 @@
using DeviceContracts.BindingModels;
using DeviceContracts.BusinessLogicsContracts;
using DeviceContracts.SearchModels;
using DeviceContracts.StoragesContracts;
using DeviceContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class KindLogic : IKindLogic
{
private readonly ILogger _logger;
private readonly IKindStorage _kindStorage;
public KindLogic(ILogger<KindLogic> logger,
IKindStorage kindStorage)
{
_logger = logger;
_kindStorage = kindStorage;
}
public bool Create(KindBindingModel model)
{
CheckModel(model);
if (_kindStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(KindBindingModel model)
{
CheckModel(model);
if (_kindStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(KindBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_kindStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<KindViewModel>? ReadList(KindSearchModel? model)
{
_logger.LogInformation(
"ReadList. Id: {Id}, Title: {Title}, Frequency: " +
"{Frequency}.", model?.Id, model?.Title, model?.Frequency);
var list = model == null ? _kindStorage.GetFullList() :
_kindStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public KindViewModel? ReadElement(KindSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation(
"ReadElement. Id: {Id}, Title: {Title}, Frequency: " +
"{Frequency}.", model?.Id, model?.Title, model?.Frequency);
var element = _kindStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}",
element.Id);
return element;
}
private void CheckModel(KindBindingModel model,
bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.Title))
{
throw new ArgumentNullException(
"Отсутствует название вида устройства",
nameof(model.Title));
}
if (string.IsNullOrEmpty(model.Title))
{
throw new ArgumentNullException(
"Отсутствует название вида устройства",
nameof(model.Title));
}
if (model.Frequency > 0)
{
throw new ArgumentNullException(
"Частота обслуживания должна быть больше 0 месяцев",
nameof(model.Frequency));
}
_logger.LogInformation(
"Id: {Id}, Title: {Title}, Frequency: " +
"{Frequency}.", model?.Id, model?.Title, model?.Frequency);
var elementByTitle = _kindStorage.GetElement(
new KindSearchModel
{
Title = model.Title,
});
var elementByFrequency = _kindStorage.GetElement(
new KindSearchModel
{
Frequency = model.Frequency,
});
}
}
}

View File

@ -0,0 +1,118 @@
using DeviceContracts.BindingModels;
using DeviceContracts.BusinessLogicsContracts;
using DeviceContracts.SearchModels;
using DeviceContracts.StoragesContracts;
using DeviceContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class KitLogic : IKitLogic
{
private readonly ILogger _logger;
private readonly IKitStorage _kitStorage;
public KitLogic(ILogger<KitLogic> logger,
IKitStorage kitStorage)
{
_logger = logger;
_kitStorage = kitStorage;
}
public bool Create(KitBindingModel model)
{
CheckModel(model);
if (_kitStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(KitBindingModel model)
{
CheckModel(model);
if (_kitStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(KitBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_kitStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<KitViewModel>? ReadList(KitSearchModel? model)
{
_logger.LogInformation(
"ReadList. Id: {Id}, Title: {Title}, CabinetId: " +
"{CabinetId}.", model?.Id, model?.Title, model?.CabinetId);
var list = model == null ? _kitStorage.GetFullList() :
_kitStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public KitViewModel? ReadElement(KitSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation(
"ReadElement. Id: {Id}, Title: {Title}, CabinetId: " +
"{CabinetId}.", model?.Id, model?.Title, model?.CabinetId);
var element = _kitStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}",
element.Id);
return element;
}
private void CheckModel(KitBindingModel model,
bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.Title))
{
throw new ArgumentNullException(
"Отсутствует номер/название кабинета",
nameof(model.Title));
}
_logger.LogInformation(
"Id: {Id}, Title: {Title}, CabinetId: " +
"{CabinetId}.", model?.Id, model?.Title, model?.CabinetId);
var elementByTitle = _kitStorage.GetElement(
new KitSearchModel
{
Title = model.Title,
});
}
}
}

View File

@ -0,0 +1,147 @@
using DeviceContracts.BindingModels;
using DeviceContracts.BusinessLogicsContracts;
using DeviceContracts.SearchModels;
using DeviceContracts.StoragesContracts;
using DeviceContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class ServiceLogic : IServiceLogic
{
private readonly ILogger _logger;
private readonly IServiceStorage _serviceStorage;
public ServiceLogic(ILogger<ServiceLogic> logger,
IServiceStorage serviceStorage)
{
_logger = logger;
_serviceStorage = serviceStorage;
}
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;
}
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
{
_logger.LogInformation(
"ReadList. Id: {Id}, Description: {Description}, StartDate: " +
"{StartDate}, EndDate: {EndDate}, DeviceId: {DeviceId}.",
model?.Id, model?.Description, model?.StartDate,
model?.EndDate, model?.DeviceId);
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}, Description: {Description}, " +
"StartDate: {StartDate}, EndDate: " +
"{EndDate}, DeviceId: {DeviceId}.",
model?.Id, model?.Description, model?.StartDate,
model?.EndDate, model?.DeviceId);
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;
}
private void CheckModel(ServiceBindingModel model,
bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.Description))
{
throw new ArgumentNullException(
"Отсутствует описание",
nameof(model.Description));
}
if (model.DeviceId <= 0)
{
throw new ArgumentNullException(
"Идентификатор устройства должен быть больше 0",
nameof(model.Id));
}
_logger.LogInformation(
"Id: {Id}, Description: {Description}, " +
"StartDate: {StartDate}, EndDate: " +
"{EndDate}, DeviceId: {DeviceId}.",
model?.Id, model?.Description, model?.StartDate,
model?.EndDate, model?.DeviceId);
var elementByDescription = _serviceStorage.GetElement(
new ServiceSearchModel
{
Description = model.Description,
});
var elementByDeviceId = _serviceStorage.GetElement(
new ServiceSearchModel
{
DeviceId = model.DeviceId,
});
var elementByStartDate = _serviceStorage.GetElement(
new ServiceSearchModel
{
StartDate = model.StartDate,
});
var elementByEndDate = _serviceStorage.GetElement(
new ServiceSearchModel
{
EndDate = model.EndDate,
});
}
}
}

View File

@ -0,0 +1,152 @@
using DeviceContracts.BindingModels;
using DeviceContracts.BusinessLogicsContracts;
using DeviceContracts.SearchModels;
using DeviceContracts.StoragesContracts;
using DeviceContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace DeviceBusinessLogic.BusinessLogics
{
public class StaffLogic : IStaffLogic
{
private readonly ILogger _logger;
private readonly IStaffStorage _staffStorage;
public StaffLogic(ILogger<StaffLogic> logger,
IStaffStorage staffStorage)
{
_logger = logger;
_staffStorage = staffStorage;
}
public bool Create(StaffBindingModel model)
{
CheckModel(model);
if (_staffStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(StaffBindingModel model)
{
CheckModel(model);
if (_staffStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(StaffBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_staffStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<StaffViewModel>? ReadList(StaffSearchModel? model)
{
_logger.LogInformation(
"ReadList. Id: {Id}, FullName: {FullName}, Department: " +
"{Department}, Email: {Email}, AccessLevel: {AccessLevel},",
model?.Id, model?.FullName,
model?.Department, model?.Email, model?.AccessLevel);
var list = model == null ? _staffStorage.GetFullList() :
_staffStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public StaffViewModel? ReadElement(StaffSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation(
"ReadList. Id: {Id}, FullName: {FullName}, Department: " +
"{Department}, Email: {Email}, AccessLevel: {AccessLevel},",
model?.Id, model?.FullName,
model?.Department, model?.Email, model?.AccessLevel);
var element = _staffStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}",
element.Id);
return element;
}
private void CheckModel(StaffBindingModel model,
bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id <= 0)
{
throw new ArgumentNullException(
"Идентификатор должен быть больше 0",
nameof(model.Id));
}
if (string.IsNullOrEmpty(model.FullName))
{
throw new ArgumentNullException(
"Отсутствует ФИО",
nameof(model.FullName));
}
if (string.IsNullOrEmpty(model.Department))
{
throw new ArgumentNullException(
"Отсутствует ФИО",
nameof(model.Department));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException(
"Отсутствует ФИО",
nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException(
"Отсутствует ФИО",
nameof(model.Password));
}
_logger.LogInformation(
"ReadList. Id: {Id}, FullName: {FullName}, Department: " +
"{Department}, Email: {Email}, AccessLevel: {AccessLevel},",
model?.Id, model?.FullName,
model?.Department, model?.Email, model?.AccessLevel);
var elementByFullName = _staffStorage.GetElement(
new StaffSearchModel
{
FullName = model.FullName,
});
var elementByDepartment = _staffStorage.GetElement(
new StaffSearchModel
{
Department = model.Department,
});
var elementByEmail = _staffStorage.GetElement(
new StaffSearchModel
{
Email = model.Email,
});
}
}
}

View File

@ -0,0 +1,7 @@
namespace DeviceDatabaseImplement
{
public class Client
{
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>