Gismatullin.ISEbd-21.STO.Co.../ServiceStation/ServiceSourceBusinessLogic/BusinessLogic/ClientWorkLogic.cs

80 lines
2.4 KiB
C#
Raw Normal View History

2024-04-30 23:40:05 +04:00
using Microsoft.Extensions.Logging;
using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicContracts;
using ServiceStationContracts.SearchModels;
using ServiceStationContracts.ViewModels;
using ServiceStationDataModels;
using ServiceStationsContracts.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceSourceBusinessLogic.BusinessLogic {
public class ClientWorkLogic : IClintWorkLogic {
private readonly ILogger _logger;
private readonly IClientWorkStorage _storage;
public ClientWorkLogic(ILogger<IClintWorkLogic> logger, IClientWorkStorage storage) {
_logger = logger;
_storage = storage;
}
public bool Create(ClientWorkBindingModel model) {
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ClientWorkBindingModel model) {
CheckModel(model, false);
_logger.LogInformation($"Delete. ClientID:{model.ClientId}");
if (_storage.Delete(model) == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(ClientWorkBindingModel model) {
CheckModel(model);
if (_storage.Update(model) == null) {
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<ClientWorkViewModel>? ReadList(ClientWorkSearchModel? model) {
_logger.LogInformation($"ReadList. ClientId:{model?.ClientId}.WorkId:{model?.WorkId}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null) {
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(ClientWorkBindingModel model, bool withParams = true) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty((model.ClientId).ToString())) {
throw new ArgumentNullException("Нет Id клиента", nameof(model.ClientId));
}
if (string.IsNullOrEmpty((model.WorkId).ToString())) {
throw new ArgumentNullException("Нет Id работы", nameof(model.WorkId));
}
_logger.LogInformation($"ClientWork. ClientId:{model.ClientId}.WorkId:{model.WorkId}");
}
}
}