forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using MagicCarpetContracts.BusinessLogicContracts;
|
|
using MagicCarpetContracts.DataModels;
|
|
using MagicCarpetContracts.Enums;
|
|
using MagicCarpetContracts.Exceptions;
|
|
using MagicCarpetContracts.Extensions;
|
|
using MagicCarpetContracts.StoragesContracts;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MagicCarpetBusinessLogic.Implementations;
|
|
|
|
public class AgencyBusinessLogicContract(IAgencyStorageContract agencyStorageContract, ILogger logger) : IAgencyBusinessLogicContract
|
|
{
|
|
private readonly IAgencyStorageContract _agencyStorageContract = agencyStorageContract;
|
|
private readonly ILogger _logger = logger;
|
|
public List<AgencyDataModel> GetAllAgencies()
|
|
{
|
|
_logger.LogInformation("GetAllTours");
|
|
return _agencyStorageContract.GetList() ?? throw new NullListException();
|
|
|
|
return [];
|
|
}
|
|
|
|
public AgencyDataModel GetAgencyByData(string data)
|
|
{
|
|
_logger.LogInformation("Get element by data: {data}", data);
|
|
if (data.IsEmpty())
|
|
{
|
|
throw new ArgumentNullException(nameof(data));
|
|
}
|
|
if (!data.IsGuid())
|
|
{
|
|
throw new ElementNotFoundException(data);
|
|
}
|
|
return _agencyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
|
|
|
return new("", TourType.None, 0, []);
|
|
}
|
|
|
|
public void InsertAgency(AgencyDataModel AgencyDataModel)
|
|
{
|
|
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(AgencyDataModel));
|
|
ArgumentNullException.ThrowIfNull(AgencyDataModel);
|
|
AgencyDataModel.Validate();
|
|
_agencyStorageContract.AddElement(AgencyDataModel);
|
|
}
|
|
|
|
public void UpdateAgency(AgencyDataModel AgencyDataModel)
|
|
{
|
|
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(AgencyDataModel));
|
|
ArgumentNullException.ThrowIfNull(AgencyDataModel);
|
|
AgencyDataModel.Validate();
|
|
_agencyStorageContract.UpdElement(AgencyDataModel);
|
|
}
|
|
|
|
public void DeleteAgency(string id)
|
|
{
|
|
logger.LogInformation("Delete by id: {id}", id);
|
|
if (id.IsEmpty())
|
|
{
|
|
throw new ArgumentNullException(nameof(id));
|
|
}
|
|
if (!id.IsGuid())
|
|
{
|
|
throw new ValidationException("Id is not a unique identifier");
|
|
}
|
|
_agencyStorageContract.DelElement(id);
|
|
}
|
|
}
|