4 лабораторная

This commit is contained in:
2025-05-27 13:50:04 +04:00
parent bbccb79ebb
commit 83c3fdcb32
199 changed files with 12528 additions and 4879 deletions

View File

@@ -0,0 +1,189 @@
using AutoMapper;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class BuyerAdapter : IBuyerAdapter
{
private readonly IBuyerBuisnessLogicContract _buyerBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public BuyerAdapter(IBuyerBuisnessLogicContract buyerBusinessLogicContract, ILogger<BuyerAdapter> logger)
{
_buyerBusinessLogicContract = buyerBusinessLogicContract;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<BuyerBindingModel, BuyerDataModel>();
cfg.CreateMap<BuyerDataModel, BuyerViewModel>();
});
_mapper = new Mapper(config);
}
public BuyerOperationResponse GetList()
{
try
{
return BuyerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllBuyers().Select(x => _mapper.Map<BuyerViewModel>(x))]);
}
catch (NullListException)
{
_logger.LogError("NullListException");
return BuyerOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return BuyerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return BuyerOperationResponse.InternalServerError(ex.Message);
}
}
public BuyerOperationResponse GetElement(string data)
{
try
{
return BuyerOperationResponse.OK(_mapper.Map<BuyerViewModel>(_buyerBusinessLogicContract.GetBuyerByData(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return BuyerOperationResponse.BadRequest("Data is empty");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return BuyerOperationResponse.NotFound($"Not found element by data {data}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return BuyerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return BuyerOperationResponse.InternalServerError(ex.Message);
}
}
public BuyerOperationResponse RegisterBuyer(BuyerBindingModel buyerModel)
{
try
{
_buyerBusinessLogicContract.InsertBuyer(_mapper.Map<BuyerDataModel>(buyerModel));
return BuyerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return BuyerOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return BuyerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return BuyerOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return BuyerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return BuyerOperationResponse.InternalServerError(ex.Message);
}
}
public BuyerOperationResponse ChangeBuyerInfo(BuyerBindingModel buyerModel)
{
try
{
_buyerBusinessLogicContract.UpdateBuyer(_mapper.Map<BuyerDataModel>(buyerModel));
return BuyerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return BuyerOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return BuyerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return BuyerOperationResponse.BadRequest($"Not found element by Id {buyerModel.Id}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return BuyerOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return BuyerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return BuyerOperationResponse.InternalServerError(ex.Message);
}
}
public BuyerOperationResponse RemoveBuyer(string id)
{
try
{
_buyerBusinessLogicContract.DeleteBuyer(id);
return BuyerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return BuyerOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return BuyerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return BuyerOperationResponse.BadRequest($"Not found element by id: {id}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return BuyerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return BuyerOperationResponse.InternalServerError(ex.Message);
}
}
}

View File

@@ -0,0 +1,205 @@
using AutoMapper;
using DaisiesBuisnessLogic.Implementations;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class ClientDiscountAdapter : IClientDiscountAdapter
{
private readonly IClientDiscountBuisnessLogicContract _clientDiscountBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public ClientDiscountAdapter(IClientDiscountBuisnessLogicContract clientDiscountBusinessLogicContrac, ILogger<ClientDiscountAdapter> logger)
{
_clientDiscountBusinessLogicContract = clientDiscountBusinessLogicContrac;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ClientDiscountBindingModel, ClientDiscountDataModel>();
cfg.CreateMap<ClientDiscountDataModel, ClientDiscountViewModel>();
});
_mapper = new Mapper(config);
}
public ClientDiscountOperationResponse RegisterClientDiscount(ClientDiscountBindingModel
clientDiscountModel)
{
try
{
_clientDiscountBusinessLogicContract.InsertClientDiscount(_mapper.Map<ClientDiscountDataModel>(clientDiscountModel));
return ClientDiscountOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ClientDiscountOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ClientDiscountOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return ClientDiscountOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ClientDiscountOperationResponse.BadRequest($"Error whileworking with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ClientDiscountOperationResponse.InternalServerError(ex.Message);
}
}
public ClientDiscountOperationResponse GetElementByBuyerId(string data)
{
try
{
return
ClientDiscountOperationResponse.OK(_mapper.Map<ClientDiscountViewModel>(_clientDiscountBusinessLogicContract.GetClientDiscountByBuyerId(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ClientDiscountOperationResponse.BadRequest("Data is empty");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ClientDiscountOperationResponse.NotFound($"Not found element by data {data} ");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ClientDiscountOperationResponse.BadRequest($"Element by data: {data} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ClientDiscountOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ClientDiscountOperationResponse.InternalServerError(ex.Message);
}
}
public ClientDiscountOperationResponse GetList(bool onlyActive = true)
{
try
{
return ClientDiscountOperationResponse.OK([..
_clientDiscountBusinessLogicContract.GetAllClientDiscounts().Select(x =>
_mapper.Map<ClientDiscountViewModel>(x))]);
}
catch (NullListException)
{
_logger.LogError("NullListException");
return ClientDiscountOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ClientDiscountOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return ClientDiscountOperationResponse.InternalServerError(ex.Message);
}
}
public ClientDiscountOperationResponse ChangeClientDiscountInfo(ClientDiscountBindingModel clientDiscountModel)
{
try
{
_clientDiscountBusinessLogicContract.UpdateClientDiscount(_mapper.Map<ClientDiscountDataModel>(clientDiscountModel));
return ClientDiscountOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ClientDiscountOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ClientDiscountOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ClientDiscountOperationResponse.BadRequest($"Not found element by BuyerId {clientDiscountModel.BuyerId} ");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return ClientDiscountOperationResponse.BadRequest(ex.Message);
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ClientDiscountOperationResponse.BadRequest($"Element by id: {clientDiscountModel.BuyerId} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ClientDiscountOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ClientDiscountOperationResponse.InternalServerError(ex.Message);
}
}
public ClientDiscountOperationResponse GetElement(string data)
{
try
{
return ClientDiscountOperationResponse.OK(_mapper.Map<ClientDiscountViewModel>(_clientDiscountBusinessLogicContract.GetClientDiscountByBuyerId(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ClientDiscountOperationResponse.BadRequest("Data is empty");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ClientDiscountOperationResponse.NotFound($"Not found element by data {data} ");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ClientDiscountOperationResponse.BadRequest($"Element by data: {data} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ClientDiscountOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return ClientDiscountOperationResponse.InternalServerError(ex.Message);
}
}
}

View File

@@ -0,0 +1,266 @@
using AutoMapper;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class PostAdapter : IPostAdapter
{
private readonly IPostBuisnessLogicContract _postBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public PostAdapter(IPostBuisnessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger)
{
_postBusinessLogicContract = postBusinessLogicContract;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<PostBindingModel, PostDataModel>();
cfg.CreateMap<PostDataModel, PostViewModel>();
});
_mapper = new Mapper(config);
}
public PostOperationResponse GetList()
{
try
{
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllPosts().Select(x => _mapper.Map<PostViewModel>(x))]);
}
catch (NullListException)
{
_logger.LogError("NullListException");
return PostOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse GetHistory(string id)
{
try
{
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllDataOfPost(id).Select(x => _mapper.Map<PostViewModel>(x))]);
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse GetElement(string data)
{
try
{
return PostOperationResponse.OK(_mapper.Map<PostViewModel>(_postBusinessLogicContract.GetPostByData(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Data is empty");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return PostOperationResponse.NotFound($"Not found element by data {data}");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return PostOperationResponse.BadRequest($"Element by data: {data} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse RegisterPost(PostBindingModel postModel)
{
try
{
_postBusinessLogicContract.InsertPost(_mapper.Map<PostDataModel>(postModel));
return PostOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return PostOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse ChangePostInfo(PostBindingModel postModel)
{
try
{
_postBusinessLogicContract.UpdatePost(_mapper.Map<PostDataModel>(postModel));
return PostOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return PostOperationResponse.BadRequest($"Not found element by Id {postModel.Id}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return PostOperationResponse.BadRequest(ex.Message);
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return PostOperationResponse.BadRequest($"Element by id: {postModel.Id} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse RemovePost(string id)
{
try
{
_postBusinessLogicContract.DeletePost(id);
return PostOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return PostOperationResponse.BadRequest($"Not found element by id: {id}");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return PostOperationResponse.BadRequest($"Element by id: {id} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
public PostOperationResponse RestorePost(string id)
{
try
{
_postBusinessLogicContract.RestorePost(id);
return PostOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return PostOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return PostOperationResponse.BadRequest($"Not found element by id: {id}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return PostOperationResponse.InternalServerError(ex.Message);
}
}
}

View File

@@ -0,0 +1,263 @@
using AutoMapper;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class ProductAdapter : IProductAdapter
{
private readonly IProductBuisnessLogicContract
_productBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public ProductAdapter(IProductBuisnessLogicContract
productBusinessLogicContract, ILogger<ProductAdapter> logger)
{
_productBusinessLogicContract = productBusinessLogicContract;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ProductBindingModel, ProductDataModel>();
cfg.CreateMap<ProductDataModel, ProductViewModel>();
cfg.CreateMap<ProductHistoryDataModel, ProductHistoryViewModel>();
});
_mapper = new Mapper(config);
}
public ProductOperationResponse GetList(bool includeDeleted)
{
try
{
return ProductOperationResponse.OK([.. _productBusinessLogicContract.GetAllProducts(!includeDeleted).Select(x =>_mapper.Map<ProductViewModel>(x))]);
}
catch (NullListException)
{
_logger.LogError("NullListException");
return ProductOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse GetSupplierList(string id, bool includeDeleted)
{
try
{
return ProductOperationResponse.OK([.. _productBusinessLogicContract.GetAllProductsBySupplier(id,!includeDeleted).Select(x => _mapper.Map<ProductViewModel>(x))]);
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ProductOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return ProductOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse GetHistory(string id)
{
try
{
return ProductOperationResponse.OK([.. _productBusinessLogicContract.GetProductHistoryByProduct(id).Select(x => _mapper.Map<ProductHistoryViewModel>(x))]);
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ProductOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return ProductOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse GetElement(string data)
{
try
{
return
ProductOperationResponse.OK(_mapper.Map<ProductViewModel>(_productBusinessLogicContract.GetProductByData(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ProductOperationResponse.BadRequest("Data is empty");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ProductOperationResponse.NotFound($"Not found element by data {data} ");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ProductOperationResponse.BadRequest($"Element by data: {data} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse RegisterProduct(ProductBindingModel
productModel)
{
try
{
_productBusinessLogicContract.InsertProduct(_mapper.Map<ProductDataModel>(productModel));
return ProductOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ProductOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ProductOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return ProductOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.BadRequest($"Error whileworking with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse ChangeProductInfo(ProductBindingModel
productModel)
{
try
{
_productBusinessLogicContract.UpdateProduct(_mapper.Map<ProductDataModel>(productModel));
return ProductOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ProductOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ProductOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ProductOperationResponse.BadRequest($"Not found element by Id {productModel.Id} ");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return ProductOperationResponse.BadRequest(ex.Message);
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ProductOperationResponse.BadRequest($"Element by id: {productModel.Id} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
public ProductOperationResponse RemoveProduct(string id)
{
try
{
_productBusinessLogicContract.DeleteProduct(id);
return ProductOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return ProductOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return ProductOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return ProductOperationResponse.BadRequest($"Not found element by id: {id} ");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return ProductOperationResponse.BadRequest($"Element by id: {id} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return ProductOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
ProductOperationResponse.InternalServerError(ex.Message);
}
}
}

View File

@@ -0,0 +1,263 @@
using AutoMapper;
using DaisiesBuisnessLogic.Implementations;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class SaleAdapter : ISaleAdapter
{
private readonly ISaleBuisnessLogicContract _saleBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public SaleAdapter(ISaleBuisnessLogicContract saleBusinessLogicContract, ILogger<SaleAdapter> logger)
{
_saleBusinessLogicContract = saleBusinessLogicContract;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SaleBindingModel, SaleDataModel>();
cfg.CreateMap<SaleDataModel, SaleViewModel>();
cfg.CreateMap<SaleProductBindingModel, SaleProductDataModel>();
cfg.CreateMap<SaleProductDataModel, SaleProductViewModel>();
});
_mapper = new Mapper(config);
}
public SaleOperationResponse GetList(DateTime fromDate, DateTime toDate)
{
try
{
return SaleOperationResponse.OK([.. _saleBusinessLogicContract.GetAllSalesByPeriod(fromDate, toDate).Select(x => _mapper.Map<SaleViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return SaleOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse GetWorkerList(string id, DateTime fromDate, DateTime toDate)
{
try
{
return SaleOperationResponse.OK([.. _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(id, fromDate, toDate).Select(x => _mapper.Map<SaleViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return SaleOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse GetBuyerList(string id, DateTime fromDate, DateTime toDate)
{
try
{
return SaleOperationResponse.OK([.. _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(id, fromDate, toDate).Select(x => _mapper.Map<SaleViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return SaleOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse GetProductList(string id, DateTime fromDate, DateTime toDate)
{
try
{
return SaleOperationResponse.OK([.. _saleBusinessLogicContract.GetAllSalesByProductByPeriod(id, fromDate, toDate).Select(x => _mapper.Map<SaleViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return SaleOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse GetElement(string id)
{
try
{
return SaleOperationResponse.OK(_mapper.Map<SaleViewModel>(_saleBusinessLogicContract.GetSaleByData(id)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return SaleOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return SaleOperationResponse.NotFound($"Not found element by data {id}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse MakeSale(SaleBindingModel saleModel)
{
try
{
var data = _mapper.Map<SaleDataModel>(saleModel);
_saleBusinessLogicContract.InsertSale(_mapper.Map<SaleDataModel>(saleModel));
return SaleOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return SaleOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
public SaleOperationResponse CancelSale(string id)
{
try
{
_saleBusinessLogicContract.CancelSale(id);
return SaleOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return SaleOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return SaleOperationResponse.BadRequest($"Not found element by id: {id}");
}
catch (ElementDeletedException ex)
{
_logger.LogError(ex, "ElementDeletedException");
return SaleOperationResponse.BadRequest($"Element by id: {id} was deleted");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return SaleOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return SaleOperationResponse.InternalServerError(ex.Message);
}
}
}

View File

@@ -0,0 +1,280 @@
using AutoMapper;
using DaisiesBuisnessLogic.Implementations;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.ViewModels;
namespace DaisiesWebApi.Adapters;
public class WorkerAdapter : IWorkerAdapter
{
private readonly IWorkerBuisnessLogicContract _buyerBusinessLogicContract;
private readonly ILogger _logger;
private readonly Mapper _mapper;
public WorkerAdapter(IWorkerBuisnessLogicContract
workerBusinessLogicContract, ILogger<WorkerAdapter> logger)
{
_buyerBusinessLogicContract = workerBusinessLogicContract;
_logger = logger;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<WorkerBindingModel, WorkerDataModel>();
cfg.CreateMap<WorkerDataModel, WorkerViewModel>();
});
_mapper = new Mapper(config);
}
public WorkerOperationResponse GetList(bool includeDeleted)
{
try
{
return WorkerOperationResponse.OK([.._buyerBusinessLogicContract.GetAllWorkers(!includeDeleted).Select(x =>_mapper.Map<WorkerViewModel>(x))]);
}
catch (NullListException)
{
_logger.LogError("NullListException");
return WorkerOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse GetPostList(string id, bool includeDeleted)
{
try
{
return WorkerOperationResponse.OK([.._buyerBusinessLogicContract.GetAllWorkersByPost(id, !includeDeleted).Select(x =>_mapper.Map<WorkerViewModel>(x))]);
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return WorkerOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse GetListByBirthDate(DateTime fromDate,
DateTime toDate, bool includeDeleted)
{
try
{
return WorkerOperationResponse.OK([.._buyerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate, toDate,!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return WorkerOperationResponse.BadRequest($"Incorrect dates: {ex.Message} ");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return WorkerOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate,
DateTime toDate, bool includeDeleted)
{
try
{
return WorkerOperationResponse.OK([.._buyerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate, toDate,!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
}
catch (IncorrectDatesException ex)
{
_logger.LogError(ex, "IncorrectDatesException");
return WorkerOperationResponse.BadRequest($"Incorrect dates: {ex.Message} ");
}
catch (NullListException)
{
_logger.LogError("NullListException");
return WorkerOperationResponse.NotFound("The list is not initialized");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse GetElement(string data)
{
try
{
return
WorkerOperationResponse.OK(_mapper.Map<WorkerViewModel>(_buyerBusinessLogicContract.GetWorkerByData(data)));
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return WorkerOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return WorkerOperationResponse.NotFound($"Not found element by data {data} ");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse RegisterWorker(WorkerBindingModel workerModel)
{
try
{
_buyerBusinessLogicContract.InsertWorker(_mapper.Map<WorkerDataModel>(workerModel));
return WorkerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return WorkerOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return WorkerOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel workerModel)
{
try
{
_buyerBusinessLogicContract.UpdateWorker(_mapper.Map<WorkerDataModel>(workerModel));
return WorkerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return WorkerOperationResponse.BadRequest("Data is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return WorkerOperationResponse.BadRequest($"Not found element by Id {workerModel.Id} ");
}
catch (ElementExistsException ex)
{
_logger.LogError(ex, "ElementExistsException");
return WorkerOperationResponse.BadRequest(ex.Message);
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
public WorkerOperationResponse RemoveWorker(string id)
{
try
{
_buyerBusinessLogicContract.DeleteWorker(id);
return WorkerOperationResponse.NoContent();
}
catch (ArgumentNullException ex)
{
_logger.LogError(ex, "ArgumentNullException");
return WorkerOperationResponse.BadRequest("Id is empty");
}
catch (ValidationException ex)
{
_logger.LogError(ex, "ValidationException");
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message} ");
}
catch (ElementNotFoundException ex)
{
_logger.LogError(ex, "ElementNotFoundException");
return WorkerOperationResponse.BadRequest($"Not found element by id: {id} ");
}
catch (StorageException ex)
{
_logger.LogError(ex, "StorageException");
return WorkerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message} ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception");
return
WorkerOperationResponse.InternalServerError(ex.Message);
}
}
}

20
DaisiesApi/AuthOptions.cs Normal file
View File

@@ -0,0 +1,20 @@
using System.Text;
using Microsoft.IdentityModel.Tokens;
namespace DaisiesWebApi;
public class AuthOptions
{
public const string ISSUER = "Daisies_AuthServer";
public const string AUDIENCE = "Daisies_AuthClient";
const string KEY = "supersecret_32_chars_long_key_1234567890!!";
public static SymmetricSecurityKey GetSymmetricSecurityKey()
{
var key = Encoding.UTF8.GetBytes(KEY);
if (key.Length * 8 < 256)
throw new Exception("JWT key must be at least 32 characters long!");
return new SymmetricSecurityKey(key);
}
}

View File

@@ -0,0 +1,45 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class BuyersController(IBuyerAdapter adapter) : ControllerBase
{
private readonly IBuyerAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetAllRecords()
{
return _adapter.GetList().GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Register([FromBody] BuyerBindingModel model)
{
return _adapter.RegisterBuyer(model).GetResponse(Request, Response);
}
[HttpPut]
public IActionResult ChangeInfo([FromBody] BuyerBindingModel model)
{
return _adapter.ChangeBuyerInfo(model).GetResponse(Request, Response);
}
[HttpDelete("{id}")]
public IActionResult Delete(string id)
{
return _adapter.RemoveBuyer(id).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,36 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class ClientDiscountsController(IClientDiscountAdapter adapter) : ControllerBase
{
private readonly IClientDiscountAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetAllRecords()
{
return _adapter.GetList().GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Register([FromBody] ClientDiscountBindingModel model)
{
return _adapter.RegisterClientDiscount(model).GetResponse(Request, Response);
}
[HttpPut]
public IActionResult ChangeInfo([FromBody] ClientDiscountBindingModel model)
{
return _adapter.ChangeClientDiscountInfo(model).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,58 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class PostsController(IPostAdapter adapter) : ControllerBase
{
private readonly IPostAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetRecords()
{
return _adapter.GetList().GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Register([FromBody] PostBindingModel model)
{
return _adapter.RegisterPost(model).GetResponse(Request, Response);
}
[HttpPut]
public IActionResult ChangeInfo([FromBody] PostBindingModel model)
{
return _adapter.ChangePostInfo(model).GetResponse(Request, Response);
}
[HttpDelete("{id}")]
public IActionResult Delete(string id)
{
return _adapter.RemovePost(id).GetResponse(Request, Response);
}
[HttpPatch("{id}")]
public IActionResult Restore(string id)
{
return _adapter.RestorePost(id).GetResponse(Request, Response);
}
[HttpGet("history/{postId}")]
public IActionResult GetHistory(string postId)
{
return _adapter.GetHistory(postId).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,55 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
[Produces("application/json")]
public class ProductsController(IProductAdapter adapter) : ControllerBase
{
private readonly IProductAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetRecords(bool includeDeleted)
{
return _adapter.GetList(includeDeleted).GetResponse(Request,
Response);
}
[HttpGet]
public IActionResult GetSupplierRecords(string id, bool includeDeleted)
{
return _adapter.GetSupplierList(id,
includeDeleted).GetResponse(Request, Response);
}
[HttpGet]
public IActionResult GetHistory(string id)
{
return _adapter.GetHistory(id).GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Register([FromBody] ProductBindingModel model)
{
return _adapter.RegisterProduct(model).GetResponse(Request,
Response);
}
[HttpPut]
public IActionResult ChangeInfo([FromBody] ProductBindingModel model)
{
return _adapter.ChangeProductInfo(model).GetResponse(Request,
Response);
}
[HttpDelete("{id}")]
public IActionResult Delete(string id)
{
return _adapter.RemoveProduct(id).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,57 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
[Produces("application/json")]
public class SalesController(ISaleAdapter adapter) : ControllerBase
{
private readonly ISaleAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetRecords(DateTime fromDate, DateTime toDate)
{
return _adapter.GetList(fromDate, toDate).GetResponse(Request, Response);
}
[HttpGet]
public IActionResult GetWorkerRecords(string id, DateTime fromDate, DateTime toDate)
{
return _adapter.GetWorkerList(id, fromDate, toDate).GetResponse(Request, Response);
}
[HttpGet]
public IActionResult GetBuyerRecords(string id, DateTime fromDate, DateTime toDate)
{
return _adapter.GetBuyerList(id, fromDate, toDate).GetResponse(Request, Response);
}
[HttpGet]
public IActionResult GetProductRecords(string id, DateTime fromDate, DateTime toDate)
{
return _adapter.GetProductList(id, fromDate, toDate).GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Sale([FromBody] SaleBindingModel model)
{
return _adapter.MakeSale(model).GetResponse(Request, Response);
}
[HttpDelete("{id}")]
public IActionResult Cancel(string id)
{
return _adapter.CancelSale(id).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesApi.Controllers;
[Authorize]
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}

View File

@@ -0,0 +1,62 @@
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BindingModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DaisiesWebApi.Controllers;
[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
[Produces("application/json")]
public class WorkersController(IWorkerAdapter adapter) : ControllerBase
{
private readonly IWorkerAdapter _adapter = adapter;
[HttpGet]
public IActionResult GetRecords(bool includeDeleted = false)
{
return _adapter.GetList(includeDeleted).GetResponse(Request,
Response);
}
[HttpGet]
public IActionResult GetPostRecords(string id, bool includeDeleted = false)
{
return _adapter.GetPostList(id, includeDeleted).GetResponse(Request,
Response);
}
[HttpGet]
public IActionResult GetBirthDateRecords(DateTime fromDate, DateTime
toDate, bool includeDeleted = false)
{
return _adapter.GetListByBirthDate(fromDate, toDate,
includeDeleted).GetResponse(Request, Response);
}
[HttpGet]
public IActionResult GetEmploymentRecords(DateTime fromDate, DateTime
toDate, bool includeDeleted = false)
{
return _adapter.GetListByEmploymentDate(fromDate, toDate,
includeDeleted).GetResponse(Request, Response);
}
[HttpGet("{data}")]
public IActionResult GetRecord(string data)
{
return _adapter.GetElement(data).GetResponse(Request, Response);
}
[HttpPost]
public IActionResult Register([FromBody] WorkerBindingModel model)
{
return _adapter.RegisterWorker(model).GetResponse(Request, Response);
}
[HttpPut]
public IActionResult ChangeInfo([FromBody] WorkerBindingModel model)
{
return _adapter.ChangeWorkerInfo(model).GetResponse(Request,
Response);
}
[HttpDelete("{id}")]
public IActionResult Delete(string id)
{
return _adapter.RemoveWorker(id).GetResponse(Request, Response);
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DaisiesBusinessLogic\DaisiesBusinessLogic.csproj" />
<ProjectReference Include="..\DaisiesContracts\DaisiesContracts.csproj" />
<ProjectReference Include="..\DaisiesDatabase\DaisiesDatabase.csproj" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="DaisiesTests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@DaisiesApi_HostAddress = http://localhost:5107
GET {{DaisiesApi_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,13 @@
using DaisiesContracts.Infrastructure;
namespace DaisiesWebApi.Infrastructure;
public class ConfigurationDatabase(IConfiguration configuration) : IConfigurationDatabase
{
private readonly Lazy<DataBaseSettings> _dataBaseSettings = new(() =>
{
return configuration.GetValue<DataBaseSettings>("DataBaseSettings") ?? throw new InvalidDataException(nameof(DataBaseSettings));
});
public string ConnectionString => _dataBaseSettings.Value.ConnectionString;
}

View File

@@ -0,0 +1,6 @@
namespace DaisiesWebApi.Infrastructure;
public class DataBaseSettings
{
public required string ConnectionString { get; set; }
}

118
DaisiesApi/Program.cs Normal file
View File

@@ -0,0 +1,118 @@
using DaisiesBuisnessLogic.Implementations;
using DaisiesContracts.AdapterContracts;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.Infrastructure;
using DaisiesContracts.StoragesContracts;
using DaisiesDatabase;
using DaisiesDatabase.Implementations;
using DaisiesWebApi;
using DaisiesWebApi.Adapters;
using DaisiesWebApi.Infrastructure;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Serilog;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddAutoMapper(typeof(Program).Assembly);
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder.Services.AddTransient<IBuyerBuisnessLogicContract, BuyerBuisnessLogicContract>();
builder.Services.AddTransient<IClientDiscountBuisnessLogicContract, ClientDiscountBuisnessLogicContract>();
builder.Services.AddTransient<IPostBuisnessLogicContract, PostBuisnessLogicContract>();
builder.Services.AddTransient<IProductBuisnessLogicContract, ProductBuisnessLogicContract>();
builder.Services.AddTransient<ISaleBuisnessLogicContract, SaleBusinessLogicContract>();
builder.Services.AddTransient<IWorkerBuisnessLogicContract, WorkerBuisnessLogicContract>();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder.Services.AddTransient<DaisiesDbContext>();
builder.Services.AddTransient<IBuyerStorageContract, BuyerStorageContract>();
builder.Services.AddTransient<IPostStorageContract, PostStorageContract>();
builder.Services.AddTransient<IProductStorageContract, ProductStorageContract>();
builder.Services.AddTransient<IClientDiscountStorageContract, ClientDiscountStorageContract>();
builder.Services.AddTransient<ISaleStorageContract, SaleStorageContract>();
builder.Services.AddTransient<IWorkerStorageContract, WorkerStorageContract>();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder.Services.AddTransient<IBuyerAdapter, BuyerAdapter>();
builder.Services.AddTransient<IClientDiscountAdapter, ClientDiscountAdapter>();
builder.Services.AddTransient<IPostAdapter, PostAdapter>();
builder.Services.AddTransient<IProductAdapter, ProductAdapter>();
builder.Services.AddTransient<ISaleAdapter, SaleAdapter>();
builder.Services.AddTransient<IWorkerAdapter, WorkerAdapter>();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
using var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).CreateLogger());
builder.Services.AddSingleton(loggerFactory.CreateLogger("Any"));
builder.Services.AddAuthorization();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidateIssuer = true,
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidIssuer = AuthOptions.ISSUER,
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidateAudience = true,
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidAudience = AuthOptions.AUDIENCE,
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidateLifetime = true,
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ValidateIssuerSigningKey = true,
};
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
if (app.Environment.IsProduction())
{
var dbContext = app.Services.GetRequiredService<DaisiesDbContext>();
if (dbContext.Database.CanConnect())
{
dbContext.Database.EnsureCreated();
dbContext.Database.Migrate();
}
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.Map("/login/{username}", (string username) =>
{
return new JwtSecurityTokenHandler().WriteToken(new JwtSecurityToken(
issuer: AuthOptions.ISSUER,
audience: AuthOptions.AUDIENCE,
claims: [new(ClaimTypes.Name, username)],
expires: DateTime.UtcNow.Add(TimeSpan.FromMinutes(2)),
signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)));
});
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5107",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7197;http://localhost:5107",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace DaisiesApi
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,22 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/chamomiles-.log",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Username} {Message:lj}{Exception}{NewLine}"
}
}
]
},
"AllowedHosts": "*",
"DataBaseSettings": {
"ConnectionString": "Host=127.0.0.1;Port=5432;Database=Daisies;Username=postgres;Password=postgres;"
}
}

View File

@@ -1,17 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="DaisiesTests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DaisiesContracts\DaisiesContracts.csproj" />
<ProjectReference Include="..\DaisiesDatabase\DaisiesDatabase.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,115 +0,0 @@
using DaisiesContracts.BusinessLogicsContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace DaisiesBusinessLogic.Implementations;
public class BouquetBusinessLogicContract(IBouquetStorageContract bouquetStorageContract, ILogger logger) : IBouquetBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IBouquetStorageContract _bouquetStorageContract = bouquetStorageContract;
public void CancelBouquet(string id)
{
_logger.LogInformation("Cancel by id: {id}", id);
if (id.IsEmpty())
{
throw new ArgumentNullException(nameof(id));
}
if (!id.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
_bouquetStorageContract.DelElement(id);
}
public List<BouquetDataModel> GetAllBouquetsByCustomerByPeriod(string customerId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {customerId}, {fromDate}, {toDate}", customerId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (customerId.IsEmpty())
{
throw new ArgumentNullException(nameof(customerId));
}
if (!customerId.IsGuid())
{
throw new ValidationException("The value in the field customerId is not a unique identifier.");
}
return _bouquetStorageContract.GetList(fromDate, toDate, customerId: customerId) ?? throw new NullListException();
}
public List<BouquetDataModel> GetAllBouquetsByEmployeerByPeriod(string employeerId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {employeerId}, {fromDate}, {toDate}", employeerId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (employeerId.IsEmpty())
{
throw new ArgumentNullException(nameof(employeerId));
}
if (!employeerId.IsGuid())
{
throw new ValidationException("The value in the field employeerId is not a unique identifier.");
}
return _bouquetStorageContract.GetList(fromDate, toDate, employeeId: employeerId) ?? throw new NullListException();
}
public List<BouquetDataModel> GetAllBouquetsByFlowerByPeriod(string flowerId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {flowerId}, {fromDate}, {toDate}", flowerId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (flowerId.IsEmpty())
{
throw new ArgumentNullException(nameof(flowerId));
}
if (!flowerId.IsGuid())
{
throw new ValidationException("The value in the field flowerId is not a unique identifier.");
}
return _bouquetStorageContract.GetList(fromDate, toDate, flowerId: flowerId) ?? throw new NullListException();
}
public List<BouquetDataModel> GetAllBouquetsByPeriod(DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _bouquetStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
}
public BouquetDataModel GetBouquetByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (!data.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
return _bouquetStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
public void InsertBouquet(BouquetDataModel bouquetDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(bouquetDataModel));
ArgumentNullException.ThrowIfNull(bouquetDataModel);
bouquetDataModel.Validate();
_bouquetStorageContract.AddElement(bouquetDataModel);
}
}

View File

@@ -0,0 +1,77 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace DaisiesBuisnessLogic.Implementations;
public class BuyerBuisnessLogicContract : IBuyerBuisnessLogicContract
{
private readonly ILogger _logger;
private readonly IBuyerStorageContract _buyerStorageContract;
public BuyerBuisnessLogicContract(IBuyerStorageContract buyerStorageContract, ILogger logger)
{
_buyerStorageContract = buyerStorageContract;
_logger = logger;
}
public List<BuyerDataModel> GetAllBuyers()
{
_logger.LogInformation("GetAllBuyers");
return _buyerStorageContract.GetList() ?? throw new NullListException();
}
public BuyerDataModel GetBuyerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _buyerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
{
return _buyerStorageContract.GetElementByPhoneNumber(data) ?? throw new ElementNotFoundException(data);
}
return _buyerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
}
public void InsertBuyer(BuyerDataModel buyerDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(buyerDataModel));
ArgumentNullException.ThrowIfNull(buyerDataModel);
buyerDataModel.Validate();
_buyerStorageContract.AddElement(buyerDataModel);
}
public void UpdateBuyer(BuyerDataModel buyerDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(buyerDataModel));
ArgumentNullException.ThrowIfNull(buyerDataModel);
buyerDataModel.Validate();
_buyerStorageContract.UpdElement(buyerDataModel);
}
public void DeleteBuyer(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");
}
_buyerStorageContract.DelElement(id);
}
}

View File

@@ -0,0 +1,68 @@
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace DaisiesBuisnessLogic.Implementations;
public class ClientDiscountBuisnessLogicContract(IClientDiscountStorageContract clientDiscountStorageContract, ILogger logger) : IClientDiscountBuisnessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IClientDiscountStorageContract _clientDiscountStorageContract = clientDiscountStorageContract;
public List<ClientDiscountDataModel> GetAllClientDiscounts()
{
_logger.LogInformation("GetAllBuyers");
return _clientDiscountStorageContract.GetList() ?? throw new NullListException();
}
public ClientDiscountDataModel GetClientDiscountByBuyerId(string data)
{
_logger.LogInformation("get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _clientDiscountStorageContract.GetElementByBuyerId(data) ?? throw new
ElementNotFoundException(data);
}
return _clientDiscountStorageContract.GetElementByBuyerFIO(data) ?? throw new
ElementNotFoundException(data);
}
public void InsertClientDiscount(ClientDiscountDataModel clientDiscountDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(clientDiscountDataModel));
ArgumentNullException.ThrowIfNull(clientDiscountDataModel);
clientDiscountDataModel.Validate();
_clientDiscountStorageContract.AddElement(clientDiscountDataModel);
}
public void UpdateClientDiscount(ClientDiscountDataModel clientDiscountDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(clientDiscountDataModel));
ArgumentNullException.ThrowIfNull(clientDiscountDataModel);
clientDiscountDataModel.Validate();
_clientDiscountStorageContract.UpdElement(clientDiscountDataModel);
}
public void DeleteClientDiscount(string buyerId)
{
_logger.LogInformation("Delete by id: {id}", buyerId);
if (buyerId.IsEmpty())
{
throw new ArgumentNullException(nameof(buyerId));
}
if (!buyerId.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
_clientDiscountStorageContract.DelElement(buyerId);
}
}

View File

@@ -1,70 +0,0 @@
using DaisiesContracts.BusinessLogicsContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace DaisiesBusinessLogic.Implementations;
public class CustomerBusinessLogicContract(ICustomerStorageContract customerStorageContract, ILogger logger) : ICustomerBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly ICustomerStorageContract _customerStorageContract = customerStorageContract;
public void DeleteCustomer(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");
}
_customerStorageContract.DelElement(id);
}
public List<CustomerDataModel> GetAllCustomers()
{
_logger.LogInformation("GetAllCustomers");
return _customerStorageContract.GetList() ?? throw new NullListException();
}
public CustomerDataModel GetCustomerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _customerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
{
return _customerStorageContract.GetElementByPhoneNumber(data) ?? throw new ElementNotFoundException(data);
}
return _customerStorageContract.GetElementByFullName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertCustomer(CustomerDataModel customerDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(customerDataModel));
ArgumentNullException.ThrowIfNull(customerDataModel);
customerDataModel.Validate();
_customerStorageContract.AddElement(customerDataModel);
}
public void UpdateCustomer(CustomerDataModel customerDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(customerDataModel));
ArgumentNullException.ThrowIfNull(customerDataModel);
customerDataModel.Validate();
_customerStorageContract.UpdElement(customerDataModel);
}
}

View File

@@ -1,61 +0,0 @@
using DaisiesContracts.BusinessLogicsContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace DaisiesBusinessLogic.Implementations;
public class CustomerDiscountBusinessLogicContract(ICustomerDiscountStorageContract customerDiscountStorageContract, IBouquetStorageContract bouquetStorageContract, ICustomerStorageContract customerStorageContract, ILogger logger) : ICustomerDiscountBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly ICustomerDiscountStorageContract _customerDiscountStorageContract = customerDiscountStorageContract;
private readonly ICustomerStorageContract _customerStorageContract = customerStorageContract;
private readonly IBouquetStorageContract _bouquetStorageContract = bouquetStorageContract;
public void CalculateDiscountByMounth(DateTime date)
{
_logger.LogInformation("CalculateDiscountByMounth: {date}", date);
var startDate = new DateTime(date.Year, date.Month, 1);
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
var customers = _customerStorageContract.GetList() ?? throw new NullListException();
foreach (var customer in customers)
{
var sales = _bouquetStorageContract.GetList(startDate, finishDate, customerId: customer.Id)?.Sum(x => x.Items.Count) ??
throw new NullListException();
var salary = sales * 0.1 > 100 ? 100 : sales * 0.1;
_logger.LogDebug("The customer {customerId} was paid a salary of {salary}", customer.Id, salary);
_customerDiscountStorageContract.AddElement(new CustomerDiscountDataModel(customer.Id, DateTime.UtcNow, (decimal)salary));
}
}
public List<CustomerDiscountDataModel> GetAllDiscountsByPeriod(DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllDiscounts params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _customerDiscountStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
}
public List<CustomerDiscountDataModel> GetAllDiscountsByPeriodByCustomer(DateTime fromDate, DateTime toDate, string customerId)
{
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (customerId.IsEmpty())
{
throw new ArgumentNullException(nameof(customerId));
}
if (!customerId.IsGuid())
{
throw new ValidationException("The value in the field customerId is not a unique identifier.");
}
_logger.LogInformation("GetAllDiscounts params: {fromDate}, {toDate}, {workerId}", fromDate, toDate, customerId);
return _customerDiscountStorageContract.GetList(fromDate, toDate, customerId) ?? throw new NullListException();
}
}

View File

@@ -1,75 +0,0 @@
using DaisiesContracts.BusinessLogicsContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace DaisiesBusinessLogic.Implementations;
public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
public void DeleteEmployeer(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");
}
_employeeStorageContract.DelElement(id);
}
public List<EmployeeDataModel> GetAllEmployeers(bool onlyActive = true)
{
_logger.LogInformation("GetAllEmployeers params: {onlyActive}", onlyActive);
return _employeeStorageContract.GetList(onlyActive) ?? throw new NullListException();
}
public List<EmployeeDataModel> GetAllEmployeersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
{
_logger.LogInformation("GetAllEmployeers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _employeeStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
}
public EmployeeDataModel GetEmployeerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _employeeStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _employeeStorageContract.GetElementByFullName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertEmployeer(EmployeeDataModel employeeDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(employeeDataModel));
ArgumentNullException.ThrowIfNull(employeeDataModel);
employeeDataModel.Validate();
_employeeStorageContract.AddElement(employeeDataModel);
}
public void UpdateEmployeer(EmployeeDataModel employeeDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(employeeDataModel));
ArgumentNullException.ThrowIfNull(employeeDataModel);
employeeDataModel.Validate();
_employeeStorageContract.UpdElement(employeeDataModel);
}
}

View File

@@ -1,65 +0,0 @@
using DaisiesContracts.BusinessLogicsContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace DaisiesBusinessLogic.Implementations;
public class FlowerBusinessLogicContract(IFlowerStorageContract flowerStorageContract, ILogger logger) : IFlowerBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IFlowerStorageContract _flowerStorageContract = flowerStorageContract;
public void DeleteFlower(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");
}
_flowerStorageContract.DelElement(id);
}
public List<FlowerDataModel> GetAllFlowers(bool onlyActive = true)
{
_logger.LogInformation("GetAllFlowers params: {onlyActive}", onlyActive);
return _flowerStorageContract.GetList() ?? throw new NullListException();
}
public FlowerDataModel GetFlowerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _flowerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _flowerStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertFlower(FlowerDataModel flowerDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(flowerDataModel));
ArgumentNullException.ThrowIfNull(flowerDataModel);
flowerDataModel.Validate();
_flowerStorageContract.AddElement(flowerDataModel);
}
public void UpdateFlower(FlowerDataModel flowerDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(flowerDataModel));
ArgumentNullException.ThrowIfNull(flowerDataModel);
flowerDataModel.Validate();
_flowerStorageContract.UpdElement(flowerDataModel);
}
}

View File

@@ -0,0 +1,95 @@
using System.Text.Json;
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace DaisiesBuisnessLogic.Implementations;
public class PostBuisnessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBuisnessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IPostStorageContract _postStorageContract = postStorageContract;
public List<PostDataModel> GetAllPosts()
{
_logger.LogInformation("GetAllPosts params: {onlyActive}");
return _postStorageContract.GetList() ?? throw new NullListException();
}
public List<PostDataModel> GetAllDataOfPost(string postId)
{
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
if (postId.IsEmpty())
{
throw new ArgumentNullException(nameof(postId));
}
if (!postId.IsGuid())
{
throw new ValidationException("The value in the field postId is not a unique identifier.");
}
return _postStorageContract.GetPostWithHistory(postId) ?? throw new NullListException();
}
public PostDataModel GetPostByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _postStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _postStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertPost(PostDataModel postDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(postDataModel));
ArgumentNullException.ThrowIfNull(postDataModel);
postDataModel.Validate();
_postStorageContract.AddElement(postDataModel);
}
public void UpdatePost(PostDataModel postDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(postDataModel));
ArgumentNullException.ThrowIfNull(postDataModel);
postDataModel.Validate();
_postStorageContract.UpdElement(postDataModel);
}
public void DeletePost(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");
}
_postStorageContract.DelElement(id);
}
public void RestorePost(string id)
{
_logger.LogInformation("Restore by id: {id}", id);
if (id.IsEmpty())
{
throw new ArgumentNullException(nameof(id));
}
if (!id.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
_postStorageContract.ResElement(id);
}
}

View File

@@ -0,0 +1,97 @@
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Enum;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using System.Text.Json;
using Microsoft.Extensions.Logging;
namespace DaisiesBuisnessLogic.Implementations;
public class ProductBuisnessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBuisnessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IProductStorageContract _productStorageContract = productStorageContract;
public List<ProductDataModel> GetAllProducts(bool onlyActive)
{
_logger.LogInformation("GetAllProducts params: {onlyActive}", onlyActive);
return _productStorageContract.GetList(onlyActive) ?? throw new NullListException();
}
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
{
_logger.LogInformation("GetProductHistoryByProduct for {productId}", productId);
if (productId.IsEmpty())
{
throw new ArgumentNullException(nameof(productId));
}
if (!productId.IsGuid())
{
throw new ValidationException("The value in the field productId is not a unique identifier.");
}
return _productStorageContract.GetHistoryByProductId(productId) ?? throw new NullListException();
}
public List<ProductDataModel> GetAllProductsBySupplier(string
supplierId, bool onlyActive = true)
{
if (supplierId.IsEmpty())
{
throw new ArgumentNullException(nameof(supplierId));
}
if (!supplierId.IsGuid())
{
throw new ValidationException("The value in the field supplierId is not a unique identifier.");
}
_logger.LogInformation("GetAllProducts params: {supplierId}, { onlyActive} ", supplierId, onlyActive);
return _productStorageContract.GetList(onlyActive, supplierId) ??
throw new NullListException();
return [];
}
public ProductDataModel GetProductByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _productStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _productStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertProduct(ProductDataModel productDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(productDataModel));
ArgumentNullException.ThrowIfNull(productDataModel);
productDataModel.Validate();
_productStorageContract.AddElement(productDataModel);
}
public void UpdateProduct(ProductDataModel productDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(productDataModel));
ArgumentNullException.ThrowIfNull(productDataModel);
productDataModel.Validate();
_productStorageContract.UpdElement(productDataModel);
}
public void DeleteProduct(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");
}
_productStorageContract.DelElement(id);
}
}

View File

@@ -0,0 +1,116 @@
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace DaisiesBuisnessLogic.Implementations;
public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, ILogger logger) : ISaleBuisnessLogicContract
{
private readonly ILogger _logger = logger;
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _saleStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
}
public List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {workerId}, {fromDate}, {toDate}", workerId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (workerId.IsEmpty())
{
throw new ArgumentNullException(nameof(workerId));
}
if (!workerId.IsGuid())
{
throw new ValidationException("The value in the field workerId is not a unique identifier.");
}
return _saleStorageContract.GetList(fromDate, toDate, workerId: workerId) ?? throw new NullListException();
}
public List<SaleDataModel> GetAllSalesByBuyerByPeriod(string buyerId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {buyerId}, {fromDate}, {toDate}", buyerId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (buyerId.IsEmpty())
{
throw new ArgumentNullException(nameof(buyerId));
}
if (!buyerId.IsGuid())
{
throw new ValidationException("The value in the field buyerId is not a unique identifier.");
}
return _saleStorageContract.GetList(fromDate, toDate, buyerId: buyerId) ?? throw new NullListException();
}
public List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllSales params: {productId}, {fromDate}, {toDate}", productId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (productId.IsEmpty())
{
throw new ArgumentNullException(nameof(productId));
}
if (!productId.IsGuid())
{
throw new ValidationException("The value in the field productId is not a unique identifier.");
}
return _saleStorageContract.GetList(fromDate, toDate, productId: productId) ?? throw new NullListException();
}
public SaleDataModel GetSaleByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (!data.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
return _saleStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
public void InsertSale(SaleDataModel saleDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
ArgumentNullException.ThrowIfNull(saleDataModel);
saleDataModel.Validate();
_saleStorageContract.AddElement(saleDataModel);
}
public void CancelSale(string id)
{
_logger.LogInformation("Cancel by id: {id}", id);
if (id.IsEmpty())
{
throw new ArgumentNullException(nameof(id));
}
if (!id.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
_saleStorageContract.DelElement(id);
}
}

View File

@@ -0,0 +1,100 @@
using DaisiesContracts.BuisnessLogicContracts;
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using DaisiesContracts.Extensions;
using System.Text.Json;
namespace DaisiesBuisnessLogic.Implementations;
public class WorkerBuisnessLogicContract(IWorkerStorageContract workerStorageContract, ILogger logger) : IWorkerBuisnessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
{
_logger.LogInformation("GetAllWorkers params: {onlyActive}", onlyActive);
return _workerStorageContract.GetList(onlyActive) ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
{
_logger.LogInformation("GetAllWorkers params: {postId}, {onlyActive},", postId, onlyActive);
if (postId.IsEmpty())
{
throw new ArgumentNullException(nameof(postId));
}
if (!postId.IsGuid())
{
throw new ValidationException("The value in the field postId is not a unique identifier.");
}
return _workerStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
{
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _workerStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
{
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
}
public WorkerDataModel GetWorkerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _workerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _workerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
}
public void InsertWorker(WorkerDataModel workerDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(workerDataModel));
ArgumentNullException.ThrowIfNull(workerDataModel);
workerDataModel.Validate();
_workerStorageContract.AddElement(workerDataModel);
}
public void UpdateWorker(WorkerDataModel workerDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(workerDataModel));
ArgumentNullException.ThrowIfNull(workerDataModel);
workerDataModel.Validate();
_workerStorageContract.UpdElement(workerDataModel);
}
public void DeleteWorker(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");
}
_workerStorageContract.DelElement(id);
}
}

View File

@@ -0,0 +1,17 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface IBuyerAdapter
{
BuyerOperationResponse GetList();
BuyerOperationResponse GetElement(string data);
BuyerOperationResponse RegisterBuyer(BuyerBindingModel buyerModel);
BuyerOperationResponse ChangeBuyerInfo(BuyerBindingModel buyerModel);
BuyerOperationResponse RemoveBuyer(string id);
}

View File

@@ -0,0 +1,13 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface IClientDiscountAdapter
{
ClientDiscountOperationResponse GetList(bool onlyActive = true);
ClientDiscountOperationResponse GetElement(string data);
ClientDiscountOperationResponse RegisterClientDiscount(ClientDiscountBindingModel clientDiscountModel);
ClientDiscountOperationResponse ChangeClientDiscountInfo(ClientDiscountBindingModel clientDiscountModel);
}

View File

@@ -0,0 +1,21 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface IPostAdapter
{
PostOperationResponse GetList();
PostOperationResponse GetHistory(string id);
PostOperationResponse GetElement(string data);
PostOperationResponse RegisterPost(PostBindingModel postModel);
PostOperationResponse ChangePostInfo(PostBindingModel postModel);
PostOperationResponse RemovePost(string id);
PostOperationResponse RestorePost(string id);
}

View File

@@ -0,0 +1,15 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface IProductAdapter
{
ProductOperationResponse GetList(bool includeDeleted);
ProductOperationResponse GetSupplierList(string id, bool includeDeleted);
ProductOperationResponse GetHistory(string id);
ProductOperationResponse GetElement(string data);
ProductOperationResponse RegisterProduct(ProductBindingModel productModel);
ProductOperationResponse ChangeProductInfo(ProductBindingModel productModel);
ProductOperationResponse RemoveProduct(string id);
}

View File

@@ -0,0 +1,21 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface ISaleAdapter
{
SaleOperationResponse GetList(DateTime fromDate, DateTime toDate);
SaleOperationResponse GetWorkerList(string id, DateTime fromDate, DateTime toDate);
SaleOperationResponse GetBuyerList(string id, DateTime fromDate, DateTime toDate);
SaleOperationResponse GetProductList(string id, DateTime fromDate, DateTime toDate);
SaleOperationResponse GetElement(string id);
SaleOperationResponse MakeSale(SaleBindingModel saleModel);
SaleOperationResponse CancelSale(string id);
}

View File

@@ -0,0 +1,23 @@
using DaisiesContracts.AdapterContracts.OperationResponses;
using DaisiesContracts.BindingModels;
namespace DaisiesContracts.AdapterContracts;
public interface IWorkerAdapter
{
WorkerOperationResponse GetList(bool includeDeleted);
WorkerOperationResponse GetPostList(string id, bool includeDeleted);
WorkerOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
WorkerOperationResponse GetElement(string data);
WorkerOperationResponse RegisterWorker(WorkerBindingModel workerModel);
WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel workerModel);
WorkerOperationResponse RemoveWorker(string id);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class BuyerOperationResponse : OperationResponse
{
public static BuyerOperationResponse OK(List<BuyerViewModel> data) => OK<BuyerOperationResponse, List<BuyerViewModel>>(data);
public static BuyerOperationResponse OK(BuyerViewModel data) => OK<BuyerOperationResponse, BuyerViewModel>(data);
public static BuyerOperationResponse NoContent() => NoContent<BuyerOperationResponse>();
public static BuyerOperationResponse BadRequest(string message) => BadRequest<BuyerOperationResponse>(message);
public static BuyerOperationResponse NotFound(string message) => NotFound<BuyerOperationResponse>(message);
public static BuyerOperationResponse InternalServerError(string message) => InternalServerError<BuyerOperationResponse>(message);
}

View File

@@ -0,0 +1,15 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class ClientDiscountOperationResponse : OperationResponse
{
public static ClientDiscountOperationResponse OK(List<ClientDiscountViewModel> data) => OK<ClientDiscountOperationResponse, List<ClientDiscountViewModel>>(data);
public static ClientDiscountOperationResponse OK(ClientDiscountViewModel data) => OK<ClientDiscountOperationResponse, ClientDiscountViewModel>(data);
public static ClientDiscountOperationResponse NoContent() => NoContent<ClientDiscountOperationResponse>();
public static ClientDiscountOperationResponse NotFound(string message) => NotFound<ClientDiscountOperationResponse>(message);
public static ClientDiscountOperationResponse BadRequest(string message) => BadRequest<ClientDiscountOperationResponse>(message);
public static ClientDiscountOperationResponse InternalServerError(string message) => InternalServerError<ClientDiscountOperationResponse>(message);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class PostOperationResponse : OperationResponse
{
public static PostOperationResponse OK(List<PostViewModel> data) => OK<PostOperationResponse, List<PostViewModel>>(data);
public static PostOperationResponse OK(PostViewModel data) => OK<PostOperationResponse, PostViewModel>(data);
public static PostOperationResponse NoContent() => NoContent<PostOperationResponse>();
public static PostOperationResponse NotFound(string message) => NotFound<PostOperationResponse>(message);
public static PostOperationResponse BadRequest(string message) => BadRequest<PostOperationResponse>(message);
public static PostOperationResponse InternalServerError(string message) => InternalServerError<PostOperationResponse>(message);
}

View File

@@ -0,0 +1,22 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class ProductOperationResponse : OperationResponse
{
public static ProductOperationResponse OK(List<ProductViewModel> data) =>
OK<ProductOperationResponse, List<ProductViewModel>>(data);
public static ProductOperationResponse OK(List<ProductHistoryViewModel>
data) => OK<ProductOperationResponse, List<ProductHistoryViewModel>>(data);
public static ProductOperationResponse OK(ProductViewModel data) =>
OK<ProductOperationResponse, ProductViewModel>(data);
public static ProductOperationResponse NoContent() =>
NoContent<ProductOperationResponse>();
public static ProductOperationResponse NotFound(string message) =>
NotFound<ProductOperationResponse>(message);
public static ProductOperationResponse BadRequest(string message) =>
BadRequest<ProductOperationResponse>(message);
public static ProductOperationResponse InternalServerError(string message)
=> InternalServerError<ProductOperationResponse>(message);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class SaleOperationResponse : OperationResponse
{
public static SaleOperationResponse OK(List<SaleViewModel> data) => OK<SaleOperationResponse, List<SaleViewModel>>(data);
public static SaleOperationResponse OK(SaleViewModel data) => OK<SaleOperationResponse, SaleViewModel>(data);
public static SaleOperationResponse NoContent() => NoContent<SaleOperationResponse>();
public static SaleOperationResponse NotFound(string message) => NotFound<SaleOperationResponse>(message);
public static SaleOperationResponse BadRequest(string message) => BadRequest<SaleOperationResponse>(message);
public static SaleOperationResponse InternalServerError(string message) => InternalServerError<SaleOperationResponse>(message);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.Infrastructure;
using DaisiesContracts.ViewModels;
namespace DaisiesContracts.AdapterContracts.OperationResponses;
public class WorkerOperationResponse : OperationResponse
{
public static WorkerOperationResponse OK(List<WorkerViewModel> data) => OK<WorkerOperationResponse, List<WorkerViewModel>>(data);
public static WorkerOperationResponse OK(WorkerViewModel data) => OK<WorkerOperationResponse, WorkerViewModel>(data);
public static WorkerOperationResponse NoContent() => NoContent<WorkerOperationResponse>();
public static WorkerOperationResponse NotFound(string message) => NotFound<WorkerOperationResponse>(message);
public static WorkerOperationResponse BadRequest(string message) => BadRequest<WorkerOperationResponse>(message);
public static WorkerOperationResponse InternalServerError(string message) => InternalServerError<WorkerOperationResponse>(message);
}

View File

@@ -0,0 +1,12 @@
namespace DaisiesContracts.BindingModels;
public class BuyerBindingModel
{
public string? Id { get; set; }
public string? FIO { get; set; }
public string? PhoneNumber { get; set; }
public double DiscountSize { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace DaisiesContracts.BindingModels;
public class ClientDiscountBindingModel
{
public string BuyerId { get; set; }
public string BuyerFIO { get; set; }
public double TotalSum { get; set; }
public double PersonalDiscount { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace DaisiesContracts.BindingModels;
public class PostBindingModel
{
public string? Id { get; set; }
public string? PostId => Id;
public string? PostName { get; set; }
public string? PostType { get; set; }
public double Salary { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace DaisiesContracts.BindingModels;
public class ProductBindingModel
{
public required string Id { get; set; }
public string? ProductName { get; set; }
public string? SupplierId { get; set; }
public string? ProductType { get; set; }
public double Price { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace DaisiesContracts.BindingModels;
public class SaleBindingModel
{
public string? Id { get; set; }
public string? WorkerId { get; set; }
public string? BuyerId { get; set; }
public int DiscountType { get; set; }
public List<SaleProductBindingModel>? Products { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace DaisiesContracts.BindingModels;
public class SaleProductBindingModel
{
public string? SaleId { get; set; }
public string? ProductId { get; set; }
public int Count { get; set; }
public double Price { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace DaisiesContracts.BindingModels;
public class WorkerBindingModel
{
public string? Id { get; set; }
public string? FIO { get; set; }
public string? PostId { get; set; }
public DateTime BirthDate { get; set; }
public DateTime EmploymentDate { get; set; }
}

View File

@@ -0,0 +1,16 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface IBuyerBuisnessLogicContract
{
List<BuyerDataModel> GetAllBuyers();
BuyerDataModel GetBuyerByData(string data);
void InsertBuyer(BuyerDataModel buyerDataModel);
void UpdateBuyer(BuyerDataModel buyerDataModel);
void DeleteBuyer(string id);
}

View File

@@ -0,0 +1,16 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface IClientDiscountBuisnessLogicContract
{
List<ClientDiscountDataModel> GetAllClientDiscounts();
ClientDiscountDataModel GetClientDiscountByBuyerId(string buyerId);
void InsertClientDiscount(ClientDiscountDataModel clientDiscountDataModel);
void UpdateClientDiscount(ClientDiscountDataModel clientDiscountDataModel);
void DeleteClientDiscount(string buyerId);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface IPostBuisnessLogicContract
{
List<PostDataModel> GetAllPosts();
List<PostDataModel> GetAllDataOfPost(string postId);
PostDataModel GetPostByData(string data);
void InsertPost(PostDataModel postDataModel);
void UpdatePost(PostDataModel postDataModel);
void DeletePost(string id);
void RestorePost(string id);
}

View File

@@ -0,0 +1,19 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface IProductBuisnessLogicContract
{
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
List<ProductDataModel> GetAllProductsBySupplier(string supplierId, bool onlyActive = true);
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
ProductDataModel GetProductByData(string data);
void InsertProduct(ProductDataModel productDataModel);
void UpdateProduct(ProductDataModel productDataModel);
void DeleteProduct(string id);
}

View File

@@ -0,0 +1,20 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface ISaleBuisnessLogicContract
{
List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByBuyerByPeriod(string buyerId, DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate);
SaleDataModel GetSaleByData(string data);
void InsertSale(SaleDataModel saleDataModel);
void CancelSale(string id);
}

View File

@@ -0,0 +1,15 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BuisnessLogicContracts;
public interface IWorkerBuisnessLogicContract
{
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
WorkerDataModel GetWorkerByData(string data);
void InsertWorker(WorkerDataModel workerDataModel);
void UpdateWorker(WorkerDataModel workerDataModel);
void DeleteWorker(string id);
}

View File

@@ -1,20 +0,0 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BusinessLogicsContracts;
public interface IBouquetBusinessLogicContract
{
List<BouquetDataModel> GetAllBouquetsByPeriod(DateTime fromDate, DateTime toDate);
List<BouquetDataModel> GetAllBouquetsByEmployeerByPeriod(string employeerId, DateTime fromDate, DateTime toDate);
List<BouquetDataModel> GetAllBouquetsByCustomerByPeriod(string customerId, DateTime fromDate, DateTime toDate);
List<BouquetDataModel> GetAllBouquetsByFlowerByPeriod(string flowerId, DateTime fromDate, DateTime toDate);
BouquetDataModel GetBouquetByData(string data);
void InsertBouquet(BouquetDataModel bouquetDataModel);
void CancelBouquet(string id);
}

View File

@@ -1,16 +0,0 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BusinessLogicsContracts;
public interface ICustomerBusinessLogicContract
{
List<CustomerDataModel> GetAllCustomers();
CustomerDataModel GetCustomerByData(string data);
void InsertCustomer(CustomerDataModel customerDataModel);
void UpdateCustomer(CustomerDataModel customerDataModel);
void DeleteCustomer(string id);
}

View File

@@ -1,12 +0,0 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BusinessLogicsContracts;
public interface ICustomerDiscountBusinessLogicContract
{
List<CustomerDiscountDataModel> GetAllDiscountsByPeriod(DateTime fromDate, DateTime toDate);
List<CustomerDiscountDataModel> GetAllDiscountsByPeriodByCustomer(DateTime fromDate, DateTime toDate, string customerId);
void CalculateDiscountByMounth(DateTime date);
}

View File

@@ -1,18 +0,0 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BusinessLogicsContracts;
public interface IEmployeeBusinessLogicContract
{
List<EmployeeDataModel> GetAllEmployeers(bool onlyActive = true);
List<EmployeeDataModel> GetAllEmployeersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
EmployeeDataModel GetEmployeerByData(string data);
void InsertEmployeer(EmployeeDataModel employeeDataModel);
void UpdateEmployeer(EmployeeDataModel employeeDataModel);
void DeleteEmployeer(string id);
}

View File

@@ -1,16 +0,0 @@
using DaisiesContracts.DataModels;
namespace DaisiesContracts.BusinessLogicsContracts;
public interface IFlowerBusinessLogicContract
{
List<FlowerDataModel> GetAllFlowers(bool onlyActive = true);
FlowerDataModel GetFlowerByData(string data);
void InsertFlower(FlowerDataModel flowerDataModel);
void UpdateFlower(FlowerDataModel flowerDataModel);
void DeleteFlower(string id);
}

View File

@@ -1,9 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.5" />
</ItemGroup>
</Project>

View File

@@ -1,41 +0,0 @@
using DaisiesContracts.Enums;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class BouquetDataModel(string id, string employeeId, string? customerId, string name, DateTime compositionDate, BouquetType type, List<BouquetItemDataModel> items) : IValidation
{
public string Id { get; private set; } = id;
/// <summary>
/// Идентификатор сотрудника (обычно флориста), составившего букет.
/// </summary>
public string EmployeeId { get; private set; } = employeeId;
/// <summary>
/// Идентификатор покупателя (необязательное поле для клиентов без регистрации).
/// </summary>
public string? CustomerId { get; private set; } = customerId;
public string Name { get; private set; } = name;
public DateTime CompositionDate { get; private set; } = compositionDate;
public BouquetType Type { get; private set; } = type;
public List<BouquetItemDataModel> Items { get; private set; } = items;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Bouquet Id пустой");
if (!Id.IsGuid())
throw new ValidationException("Bouquet Id не является валидным GUID");
if (EmployeeId.IsEmpty())
throw new ValidationException("Employee Id пустой");
if (!EmployeeId.IsGuid())
throw new ValidationException("Employee Id не является валидным GUID");
if (!string.IsNullOrEmpty(CustomerId) && !CustomerId.IsGuid())
throw new ValidationException("Customer Id не является валидным GUID");
if (Type == BouquetType.None)
throw new ValidationException("Тип букета должен быть указан");
if ((Items?.Count ?? 0) == 0)
throw new ValidationException("Букет должен содержать хотя бы один элемент");
}
}

View File

@@ -1,20 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class BouquetHistoryDataModel(string bouquetId, string oldName, DateTime changeDate) : IValidation
{
public string BouquetId { get; private set; } = bouquetId;
public string OldName { get; private set; } = oldName;
public DateTime ChangeDate { get; private set; } = changeDate;
public void Validate()
{
if (BouquetId.IsEmpty())
throw new ValidationException("Bouquet Id пустой");
if (!BouquetId.IsGuid())
throw new ValidationException("Bouquet Id не является валидным GUID");
}
}

View File

@@ -1,26 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class BouquetItemDataModel(string bouquetId, string flowerId, int quantity) : IValidation
{
public string BouquetId { get; private set; } = bouquetId;
public string FlowerId { get; private set; } = flowerId;
public int Quantity { get; private set; } = quantity;
public void Validate()
{
if (BouquetId.IsEmpty())
throw new ValidationException("Bouquet Id пустой");
if (!BouquetId.IsGuid())
throw new ValidationException("Bouquet Id не является валидным GUID");
if (FlowerId.IsEmpty())
throw new ValidationException("Flower Id пустой");
if (!FlowerId.IsGuid())
throw new ValidationException("Flower Id не является валидным GUID");
if (Quantity <= 0)
throw new ValidationException("Количество должно быть больше 0");
}
}

View File

@@ -0,0 +1,30 @@
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
using System.Text.RegularExpressions;
using DaisiesContracts.Exceptions;
namespace DaisiesContracts.DataModels;
public class BuyerDataModel(string id, string fio, string phoneNumber, double discountSize) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string PhoneNumber { get; private set; } = phoneNumber;
public double DiscountSize { get; private set; } = discountSize;
public void Validate()
{
if (Id.IsEmpty()) { throw new ValidationException("Field Id is empty"); }
if (!Id.IsGuid()) { throw new ValidationException("The value in the field Id is not a unique identifier"); }
if (FIO.IsEmpty()) { throw new ValidationException("Field FIO is empty"); }
if (PhoneNumber.IsEmpty()) { throw new ValidationException("Field PhoneNumber is empty"); }
if (!Regex.IsMatch(PhoneNumber, @"^\+7[\s-]?\d{3}[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$")) { throw new ValidationException("Field PhoneNumber is not a phone number"); }
}
}

View File

@@ -0,0 +1,47 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class ClientDiscountDataModel(string buyerId, double totalSum, double personalDiscount) : IValidation
{
private readonly BuyerDataModel? _buyer;
public string BuyerId { get; private set; } = buyerId;
public double TotalSum { get; private set; } = totalSum;
public double PersonalDiscount { get; private set; } = personalDiscount;
public string BuyerFIO => _buyer?.FIO ?? string.Empty;
public ClientDiscountDataModel(string? buyerId, double totalSum, double personalDiscount, BuyerDataModel buyer) : this(buyerId, totalSum, personalDiscount)
{
_buyer = buyer;
}
public void Validate()
{
if (BuyerId.IsEmpty())
{
throw new ValidationException("Field Id is empty");
}
if (!BuyerId.IsGuid())
{
throw new ValidationException("The value in the field Id is not a unique identifier");
}
if (TotalSum < 0)
{
throw new ValidationException("TotalSum cannot be less than zero");
}
if (PersonalDiscount < 0)
{
throw new ValidationException("PersonalDiscount cannot be less than zero");
}
}
}

View File

@@ -1,28 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
using System.Text.RegularExpressions;
namespace DaisiesContracts.DataModels;
public class CustomerDataModel(string id, string fullName, string phoneNumber, DateTime registrationDate) : IValidation
{
public string Id { get; private set; } = id;
public string FullName { get; private set; } = fullName;
public string PhoneNumber { get; private set; } = phoneNumber;
public DateTime RegistrationDate { get; private set; } = registrationDate;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Customer Id пустой");
if (!Id.IsGuid())
throw new ValidationException("Customer Id не является валидным GUID");
if (FullName.IsEmpty())
throw new ValidationException("Customer Full Name пустой");
if (PhoneNumber.IsEmpty())
throw new ValidationException("Customer Phone Number пустой");
if (!Regex.IsMatch(PhoneNumber, @"^(?:\+?7|8)?(?:[\s\-(_]+)?(\d{3})(?:[\s\-_)]+)?(\d{3})(?:[\s\-_]+)?(\d{2})(?:[\s\-_]+)?(\d{2})$"))
throw new ValidationException("PhoneNumber не является номером телефона");
}
}

View File

@@ -1,29 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class CustomerDiscount(string id, string customerId, decimal discount) : IValidation
{
public string Id { get; private set; } = id;
public string CustomerId { get; private set; } = customerId;
/// <summary>
/// Скидка в процентах (от 0 до 100)
/// </summary>
public decimal Discount { get; private set; } = discount;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("History Id пустой");
if (!Id.IsGuid())
throw new ValidationException("History Id не является валидным GUID");
if (CustomerId.IsEmpty())
throw new ValidationException("Customer Id пустой");
if (!CustomerId.IsGuid())
throw new ValidationException("Customer Id не является валидным GUID");
if (Discount < 0 || Discount > 100)
throw new ValidationException("Скидка должна быть в диапазоне от 0 до 100");
}
}

View File

@@ -1,26 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class CustomerDiscountDataModel(string customerId, DateTime discountDateTime, decimal discount) : IValidation
{
public string Id { get; private set; } = Guid.NewGuid().ToString();
public string CustomerId { get; private set; } = customerId;
public DateTime DiscountDateTime { get; private set; } = discountDateTime;
/// <summary>
/// Скидка в процентах (от 0 до 100)
/// </summary>
public decimal Discount { get; private set; } = discount;
public void Validate()
{
if (CustomerId.IsEmpty())
throw new ValidationException("Customer Id пустой");
if (!CustomerId.IsGuid())
throw new ValidationException("Customer Id не является валидным GUID");
if (Discount < 0 || Discount > 100)
throw new ValidationException("Скидка должна быть в диапазоне от 0 до 100");
}
}

View File

@@ -1,30 +0,0 @@
using DaisiesContracts.Enums;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
using System.Text.RegularExpressions;
namespace DaisiesContracts.DataModels;
public class EmployeeDataModel(string id, string fullName, EmployeeRole role, DateTime employmentDate, bool isActive) : IValidation
{
public string Id { get; private set; } = id;
public string FullName { get; private set; } = fullName;
public EmployeeRole Role { get; private set; } = role;
public DateTime EmploymentDate { get; private set; } = employmentDate;
public bool IsActive { get; private set; } = isActive;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Employee Id пустой");
if (!Id.IsGuid())
throw new ValidationException("Employee Id не является валидным GUID");
if (FullName.IsEmpty())
throw new ValidationException("Employee Full Name пустой");
if (!Regex.IsMatch(FullName, @"^[A-ZА-ЯЁ][a-zа-яё]*(\s[A-ZА-ЯЁ][a-zа-яё]*)+$"))
throw new ValidationException("Поле FullName не является корректным полным именем");
if (EmploymentDate.Date > DateTime.Now.Date)
throw new ValidationException("Дата приема на работу не может быть в будущем");
}
}

View File

@@ -1,24 +0,0 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class FlowerDataModel(string id, string name, decimal price) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public decimal Price { get; private set; } = price;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Flower Id пустой");
if (!Id.IsGuid())
throw new ValidationException("Flower Id не является валидным GUID");
if (Name.IsEmpty())
throw new ValidationException("Flower Name пустой");
if (Price <= 0)
throw new ValidationException("Цена цветка должна быть положительной");
}
}

View File

@@ -0,0 +1,35 @@
using DaisiesContracts.Enum;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class PostDataModel(string postId, string postName, PostType postType, double salary) : IValidation
{
public string Id { get; private set; } = postId;
public string PostName { get; private set; } = postName;
public PostType PostType { get; private set; } = postType;
public double Salary { get; private set; } = salary;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (PostName.IsEmpty())
throw new ValidationException("Field PostName is empty");
if (PostType == PostType.None)
throw new ValidationException("Field PostType is empty");
if (Salary <= 0)
throw new ValidationException("Field Salary is empty");
}
}

View File

@@ -0,0 +1,47 @@
using DaisiesContracts.Enum;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class ProductDataModel : IValidation
{
public string Id { get; private set; }
public string ProductName { get; private set; }
public ProductType ProductType { get; private set; }
public string SupplierId { get; private set; }
public double Price { get; private set; }
public bool IsDeleted { get; private set; }
public ProductDataModel()
{
}
public ProductDataModel(string id, string productName, ProductType productType, string SupplierId, double price, bool isDeleted)
{
Id = id;
ProductName = productName;
ProductType = productType;
this.SupplierId = SupplierId;
Price = price;
IsDeleted = isDeleted;
}
public void Validate()
{
if (Id.IsEmpty()) { throw new ValidationException("Field Id is empty"); }
if (!Id.IsGuid()) { throw new ValidationException("The value in the field Id is a unique identifier"); }
if (ProductName.IsEmpty()) { throw new ValidationException("Field Id is empty"); }
if (ProductType == ProductType.None) { throw new ValidationException("Field ProductType is empty"); }
if (SupplierId.IsEmpty()) { throw new ValidationException("Field SupplierId is empty"); }
if (!SupplierId.IsGuid()) { throw new ValidationException("The value in the field SupplierId is not a unique identifier"); }
if (Price <= 0) { throw new ValidationException("Field Prise is less than or equal to 0"); }
}
}

View File

@@ -0,0 +1,27 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
{
private readonly ProductDataModel? _product;
public string ProductId { get; private set; } = productId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public string ProductName => _product?.ProductName ?? string.Empty;
public ProductHistoryDataModel(string productId, double oldPrice, DateTime changeDate, ProductDataModel product) : this(productId, oldPrice)
{
ChangeDate = changeDate;
_product = product;
}
public void Validate()
{
if (ProductId.IsEmpty()) { throw new ValidationException("Field ProductId is empty"); }
if (!ProductId.IsGuid()) { throw new ValidationException("The value in the field ProductId is a unique identifier"); }
if (OldPrice <= 0) { throw new ValidationException("Field OldPrice is less than or equal to 0"); }
}
}

View File

@@ -0,0 +1,64 @@
using DaisiesContracts.DataModels;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
public class SaleDataModel(string id, string workerId, string? buyerId, double sum, bool isCancel, List<SaleProductDataModel> saleProducts) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public string? BuyerId { get; private set; } = buyerId;
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProductDataModel> Products { get; private set; } = saleProducts;
private readonly BuyerDataModel? _buyer;
private readonly WorkerDataModel? _worker;
public string BuyerFIO => _buyer?.FIO ?? string.Empty;
public string WorkerFIO => _worker?.FIO ?? string.Empty;
public SaleDataModel(string id, string workerId, string? buyerId, double sum, bool isCancel, List<SaleProductDataModel> saleProducts, WorkerDataModel worker, BuyerDataModel? buyer) : this(id, workerId, buyerId, sum, isCancel, saleProducts)
{
//Sum = sum;
_worker = worker;
_buyer = buyer;
}
public SaleDataModel(string id, string workerId, string? buyerId, List<SaleProductDataModel> products) : this(id, workerId, buyerId, 1, false, products) { }
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (WorkerId.IsEmpty())
throw new ValidationException("Field WorkerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
if (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false)
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}

View File

@@ -0,0 +1,25 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
{
public string SaleId { get; private set; } = saleId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (SaleId.IsEmpty()) { throw new ValidationException("Field SaleId is empty"); }
if (!SaleId.IsGuid()) { throw new ValidationException("The value in the field SaleId is a unique identifier"); }
if (ProductId.IsEmpty()) { throw new ValidationException("Field ProductId is empty"); }
if (!ProductId.IsGuid()) { throw new ValidationException("The value in the field ProductId is a unique identifier"); }
if (Count <= 0) { throw new ValidationException("Field Count is less than or equal to 0"); }
}
}

View File

@@ -0,0 +1,50 @@
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
using Microsoft.Extensions.Hosting;
namespace DaisiesContracts.DataModels;
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string PostId { get; private set; } = postId;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime EmploymentDate { get; private set; } = employmentDate;
public bool IsDeleted { get; private set; } = isDeleted;
private readonly PostDataModel? _post;
public string PostName => _post?.PostName ?? string.Empty;
public WorkerDataModel(string id, string fio, string postId, DateTime
birthDate, DateTime employmentDate, bool isDeleted, PostDataModel post) :
this(id, fio, postId, birthDate, employmentDate, isDeleted)
{
_post = post;
}
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate) :
this(id, fio, postId, birthDate, employmentDate, false)
{
}
public void Validate()
{
if (Id.IsEmpty()) { throw new ValidationException("Field Id is empty"); }
if (!Id.IsGuid()) { throw new ValidationException("The value in the field Id is a unique identifier"); }
if (FIO.IsEmpty()) { throw new ValidationException("Field FIO is empty"); }
if (PostId.IsEmpty()) { throw new ValidationException("Field PostId is empty"); }
if (!PostId.IsGuid()) { throw new ValidationException("The value in the field PostId is a unique identifier"); }
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date) { throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})"); }
if (EmploymentDate.Date < BirthDate.Date) { throw new ValidationException("The date of employment cannot be less than the date of birth"); }
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) { throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); }
}
}

View File

@@ -0,0 +1,10 @@
namespace DaisiesContracts.Enum;
[Flags]
public enum DiscountType
{
None = 0,
OnSale = 1,
RegularCustomer = 2,
Certificate = 4
}

View File

@@ -0,0 +1,9 @@
namespace DaisiesContracts.Enum;
public enum PostType
{
None = 0,
Administrator = 1,
Florist = 2,
Assistant = 3,
}

View File

@@ -0,0 +1,9 @@
namespace DaisiesContracts.Enum;
public enum ProductType
{
None = 0,
Composition = 1,
Bouquet = 2,
Accessory = 3
}

View File

@@ -1,9 +0,0 @@
namespace DaisiesContracts.Enums;
public enum BouquetType
{
None = 0,
Standard = 1,
Special = 2,
Wedding = 3
}

View File

@@ -1,9 +0,0 @@
namespace DaisiesContracts.Enums;
public enum EmployeeRole
{
None = 0,
Florist = 1,
Helper = 2,
Administrator = 3
}

View File

@@ -0,0 +1,9 @@
namespace DaisiesContracts.Exceptions;
public static class DateTimeExtensions
{
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
{
return date >= olderDate;
}
}

View File

@@ -2,5 +2,5 @@
public class ElementDeletedException : Exception
{
public ElementDeletedException(string id) : base($"Cannot modify a deleted item(id: {id})") { }
}
public ElementDeletedException(string id) : base($"Cannot modify a deleted item (id: {id})") { }
}

View File

@@ -2,13 +2,13 @@
public class ElementExistsException : Exception
{
public string ParamName { get; private set; }
public string ParamName { get; private set; }
public string ParamValue { get; private set; }
public string ParamValue { get; private set; }
public ElementExistsException(string paramName, string paramValue) : base($"There is already an element with value{paramValue} of parameter {paramName}")
{
ParamName = paramName;
ParamValue = paramValue;
}
}
public ElementExistsException(string paramName, string paramValue) : base($"There is already an element with value{paramValue} of parameter { paramName}")
{
ParamName = paramName;
ParamValue = paramValue;
}
}

View File

@@ -2,10 +2,10 @@
public class ElementNotFoundException : Exception
{
public string Value { get; private set; }
public string Value { get; private set; }
public ElementNotFoundException(string value) : base($"Element not found at value = {value}")
{
Value = value;
}
}
public ElementNotFoundException(string value) : base($"Element not found at value = { value}")
{
Value = value;
}
}

View File

@@ -1,6 +1,8 @@
namespace DaisiesContracts.Exceptions;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace DaisiesContracts.Exceptions;
public class IncorrectDatesException : Exception
{
public IncorrectDatesException(DateTime start, DateTime end) : base($"The end date must be later than the start date.. StartDate: {start:dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}") { }
}
public IncorrectDatesException(DateTime start, DateTime end) : base($"The end date must be later than the start date..StartDate: { start: dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}") { }
}

View File

@@ -2,5 +2,5 @@
public class NullListException : Exception
{
public NullListException() : base("The returned list is null") { }
}
public NullListException() : base("The returned list is null") { }
}

View File

@@ -2,5 +2,5 @@
public class StorageException : Exception
{
public StorageException(Exception ex) : base($"Error while working in storage: {ex.Message}", ex) { }
}
public StorageException(Exception ex) : base($"Error while working in storage: { ex.Message}", ex) { }
}

View File

@@ -1,5 +1,3 @@
namespace DaisiesContracts.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}
public class ValidationException(string message) : Exception(message) { }

View File

@@ -1,9 +0,0 @@
namespace DaisiesContracts.Extensions;
public static class DateTimeExtensions
{
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
{
return date >= olderDate;
}
}

View File

@@ -2,6 +2,13 @@
public static class StringExtensions
{
public static bool IsEmpty(this string str) => string.IsNullOrWhiteSpace(str);
public static bool IsGuid(this string str) => Guid.TryParse(str, out _);
public static bool IsEmpty(this string str)
{
return string.IsNullOrWhiteSpace(str);
}
public static bool IsGuid(this string str)
{
return Guid.TryParse(str, out _);
}
}

View File

@@ -1,6 +0,0 @@
namespace DaisiesContracts.Infrastrcuture;
public interface IConfigurationDatabase
{
public string ConnectionString { get; }
}

View File

@@ -0,0 +1,6 @@
namespace DaisiesContracts.Infrastructure;
public interface IConfigurationDatabase
{
string ConnectionString { get; }
}

View File

@@ -3,4 +3,4 @@
public interface IValidation
{
void Validate();
}
}

Some files were not shown because too many files have changed in this diff Show More