74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using YAPContracts.BusinessLodicContracts;
|
|
using YAPContracts.DataModels;
|
|
using YAPContracts.Exceptions;
|
|
using YAPContracts.Extentions;
|
|
using YAPContracts.StorageContracts;
|
|
|
|
namespace YAPBusinessLogic.Implementations
|
|
{
|
|
internal class ProductSetBusinessLogicContract(IProductSetStorageContract productSetStorageContract, ILogger logger) : IProductSetBusinessLogicContract
|
|
{
|
|
private readonly ILogger _logger = logger;
|
|
private readonly IProductSetStorageContract _productSetStorageContract = productSetStorageContract;
|
|
public List<ProductSetDataModel> GetAllProductSets(bool onlyActual = true)
|
|
{
|
|
_logger.LogInformation($"GetAllProductSets method called with parameter onlyActual: {onlyActual}", onlyActual);
|
|
var productSets = _productSetStorageContract.GetList(onlyActual);
|
|
return productSets ?? throw new NullListException();
|
|
}
|
|
|
|
public ProductSetDataModel? GetProductSetByData(string data)
|
|
{
|
|
_logger.LogInformation($"GetProductSetByData method called with data: {data}", data);
|
|
if (data.IsEmpty())
|
|
{
|
|
throw new ArgumentNullException(nameof(data));
|
|
}
|
|
if (!data.IsGuid())
|
|
{
|
|
throw new ValidationException("Id is not a unique identifier");
|
|
}
|
|
var productSet = _productSetStorageContract.GetElementById(data);
|
|
return productSet ?? throw new ElementNotFoundException(data);
|
|
}
|
|
|
|
public void InsertProductSet(ProductSetDataModel productSet)
|
|
{
|
|
_logger.LogInformation("Insert data: {json}", JsonSerializer.Serialize(productSet));
|
|
ArgumentNullException.ThrowIfNull(productSet);
|
|
productSet.Validate();
|
|
_productSetStorageContract.AddElement(productSet);
|
|
}
|
|
|
|
public void UpdateProductSet(ProductSetDataModel productSet)
|
|
{
|
|
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(productSet));
|
|
ArgumentNullException.ThrowIfNull(productSet);
|
|
productSet.Validate();
|
|
_productSetStorageContract.UpdateElement(productSet);
|
|
}
|
|
|
|
public void DeleteProductSet(string id)
|
|
{
|
|
_logger.LogInformation($"Delete data by id: {id}", id);
|
|
if (id.IsEmpty())
|
|
{
|
|
throw new ArgumentNullException(nameof(id));
|
|
}
|
|
if (!id.IsGuid())
|
|
{
|
|
throw new ValidationException("Id is not a unique identifier");
|
|
}
|
|
_productSetStorageContract.DeleteElement(id);
|
|
}
|
|
}
|
|
}
|