2024-04-30 23:40:05 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ServiceStationContracts.BindingModels;
|
2024-08-19 17:49:44 +04:00
|
|
|
|
using ServiceStationContracts.BusinessLogic;
|
2024-04-30 23:40:05 +04:00
|
|
|
|
using ServiceStationContracts.SearchModels;
|
|
|
|
|
using ServiceStationContracts.ViewModels;
|
2024-08-19 17:49:44 +04:00
|
|
|
|
using ServiceStationContracts.StorageContracts;
|
2024-04-30 23:40:05 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-08-19 17:49:44 +04:00
|
|
|
|
namespace ServiceStationBusinessLogic.BusinessLogic {
|
2024-04-30 23:40:05 +04:00
|
|
|
|
public class ClientLogic : IClientLogic {
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IClientStorage _storage;
|
|
|
|
|
|
2024-08-12 17:52:19 +04:00
|
|
|
|
public ClientLogic(ILogger<IClientLogic> logger, IClientStorage storage) {
|
2024-04-30 23:40:05 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_storage = storage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Create(ClientBindingModel model) {
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_storage.Insert(model) == null) {
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Delete(ClientBindingModel model) {
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
_logger.LogInformation($"Delete.Id:{model.Id}");
|
|
|
|
|
if (_storage.Delete(model) == null) {
|
|
|
|
|
_logger.LogWarning("Delete operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(ClientBindingModel model) {
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_storage.Update(model) == null) {
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ClientViewModel? ReadElement(ClientSearchModel model) {
|
|
|
|
|
if (model == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
2024-08-22 20:40:32 +04:00
|
|
|
|
_logger.LogInformation($"ReadElement.Id:{model.Id}.login:{model.fio}");
|
2024-04-30 23:40:05 +04:00
|
|
|
|
var element = _storage.GetElement(model);
|
|
|
|
|
if (element == null) {
|
2024-08-12 17:52:19 +04:00
|
|
|
|
_logger.LogWarning("ReadElement.Element not fount");
|
2024-04-30 23:40:05 +04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation($"ReadElement.find.Id:{element.Id}");
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-12 17:52:19 +04:00
|
|
|
|
public List<ClientViewModel>? ReadList() {
|
|
|
|
|
var list = _storage.GetFullList();
|
2024-04-30 23:40:05 +04:00
|
|
|
|
if (list == null) {
|
2024-08-12 17:52:19 +04:00
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
2024-04-30 23:40:05 +04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation($"ReadList.Count:{list.Count}");
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(ClientBindingModel model, bool withParams = true) {
|
2024-08-12 17:52:19 +04:00
|
|
|
|
if (string.IsNullOrEmpty((model.Id).ToString())) {
|
|
|
|
|
throw new ArgumentNullException("Нет Id клиента", nameof(model.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!withParams) {
|
2024-04-30 23:40:05 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-12 17:52:19 +04:00
|
|
|
|
if (string.IsNullOrEmpty(model.FIO)) {
|
|
|
|
|
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.FIO));
|
2024-04-30 23:40:05 +04:00
|
|
|
|
}
|
2024-08-22 20:40:32 +04:00
|
|
|
|
|
2024-08-27 16:29:09 +04:00
|
|
|
|
_logger.LogInformation($"Client.Id:{model.Id}.FIO:{model.FIO}");
|
2024-04-30 23:40:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|