Красная зона
This commit is contained in:
parent
940765f80a
commit
2ad081dfb0
@ -19,99 +19,31 @@ internal class OrderBusinessLogicContract(IOrderStorageContract orderStorageCont
|
|||||||
private readonly IOrderStorageContract _orderStorageContract = orderStorageContract;
|
private readonly IOrderStorageContract _orderStorageContract = orderStorageContract;
|
||||||
public List<OrderDataModel> GetAllOrdersByPeriod(DateTime fromDate, DateTime toDate)
|
public List<OrderDataModel> GetAllOrdersByPeriod(DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}",fromDate, toDate);
|
return [];
|
||||||
if (fromDate.IsDateNotOlder(toDate))
|
|
||||||
{
|
|
||||||
throw new IncorrectDatesException(fromDate, toDate);
|
|
||||||
}
|
|
||||||
return _orderStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
public List<OrderDataModel> GetAllOrdersByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
public List<OrderDataModel> GetAllOrdersByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllSales params: {workerId}, {fromDate},{ toDate} ", workerId, fromDate, toDate);
|
return [];
|
||||||
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 _orderStorageContract.GetList(fromDate, toDate, workerId:workerId) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
public List<OrderDataModel> GetAllOrdersByRestaurantByPeriod(string restaurantId, DateTime fromDate, DateTime toDate)
|
public List<OrderDataModel> GetAllOrdersByRestaurantByPeriod(string restaurantId, DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
|
return [];
|
||||||
_logger.LogInformation("GetAllSales params: {restaurantId}, {fromDate},{ toDate} ", restaurantId, fromDate, toDate);
|
|
||||||
if (fromDate.IsDateNotOlder(toDate))
|
|
||||||
{
|
|
||||||
throw new IncorrectDatesException(fromDate, toDate);
|
|
||||||
}
|
|
||||||
if (restaurantId.IsEmpty())
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(restaurantId));
|
|
||||||
}
|
|
||||||
if (!restaurantId.IsGuid())
|
|
||||||
{
|
|
||||||
throw new ValidationException("The value in the field restaurantId is not a unique identifier.");
|
|
||||||
}
|
|
||||||
return _orderStorageContract.GetList(fromDate, toDate, restaurantId:restaurantId) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
public List<OrderDataModel> GetAllOrdersByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
|
public List<OrderDataModel> GetAllOrdersByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllSales params: {productId}, {fromDate},{ toDate}", productId, fromDate, toDate);
|
return [];
|
||||||
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 _orderStorageContract.GetList(fromDate, toDate, productId: productId) ?? throw new NullListException();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public OrderDataModel GetOrderByData(string data)
|
public OrderDataModel GetOrderByData(string data)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Get element by data: {data}", data);
|
return new("", "", "", 0, true, []);
|
||||||
if (data.IsEmpty())
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
if (!data.IsGuid())
|
|
||||||
{
|
|
||||||
throw new ValidationException("Id is not a unique identifier");
|
|
||||||
}
|
|
||||||
return _orderStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertOrder(OrderDataModel orderDataModel)
|
public void InsertOrder(OrderDataModel orderDataModel)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("New data: {json}",JsonSerializer.Serialize(orderDataModel));
|
|
||||||
ArgumentNullException.ThrowIfNull(orderDataModel);
|
|
||||||
orderDataModel.Validate();
|
|
||||||
_orderStorageContract.AddElement(orderDataModel);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void CancelOrder(string id)
|
public void CancelOrder(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");
|
|
||||||
}
|
|
||||||
_orderStorageContract.DelElement(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,86 +16,39 @@ namespace PipingHotBusinessLogic.Implementations;
|
|||||||
|
|
||||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
|
||||||
public List<PostDataModel> GetAllPosts(bool onlyActive)
|
public List<PostDataModel> GetAllPosts(bool onlyActive)
|
||||||
{
|
{
|
||||||
logger.LogInformation("GetAllPosts params: {onlyActive}",onlyActive);
|
return [];
|
||||||
return _postStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
|
return [];
|
||||||
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)
|
public PostDataModel GetPostByData(string data)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Get element by data: {data}", data);
|
|
||||||
if (data.IsEmpty())
|
return new("", "", PostType.None, 0, true, DateTime.UtcNow);
|
||||||
{
|
|
||||||
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)
|
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)
|
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)
|
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)
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,79 +20,32 @@ internal class ProductBusinessLogicContract(IProductStorageContract productStora
|
|||||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||||
public List<ProductDataModel> GetAllProducts(bool onlyActive = true)
|
public List<ProductDataModel> GetAllProducts(bool onlyActive = true)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllProducts params: {onlyActive}",onlyActive);
|
return [];
|
||||||
return _productStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProductDataModel> GetAllProductsByRestaurant(string restaurantId, bool onlyActive = true)
|
public List<ProductDataModel> GetAllProductsByRestaurant(string restaurantId, bool onlyActive = true)
|
||||||
{
|
{
|
||||||
if (restaurantId.IsEmpty())
|
return [];
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(restaurantId));
|
|
||||||
}
|
|
||||||
if (!restaurantId.IsGuid())
|
|
||||||
{
|
|
||||||
throw new ValidationException("The value in the field restaurantId is not a unique identifier.");
|
|
||||||
}
|
|
||||||
_logger.LogInformation("GetAllProducts params: {restaurantId},{ onlyActive}", restaurantId, onlyActive);
|
|
||||||
return _productStorageContract.GetList(onlyActive, restaurantId) ?? throw new NullListException();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
||||||
{
|
{
|
||||||
logger.LogInformation("GetProductHistoryByProduct for {productId}",productId);
|
return [];
|
||||||
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 ProductDataModel GetProductByData(string data)
|
public ProductDataModel GetProductByData(string data)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Get element by data: {data}", data);
|
return new("", "", ProductType.None, "", 0, true);
|
||||||
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)
|
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)
|
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)
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,54 +21,25 @@ internal class RestaurantBusinessLogicContract(IRestaurantStorageContract resta
|
|||||||
|
|
||||||
public List<RestaurantDataModel> GetAllRestaurants()
|
public List<RestaurantDataModel> GetAllRestaurants()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllRestaurants");
|
return [];
|
||||||
return _restaurantStorageContract.GetList() ?? throw new NullListException();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestaurantDataModel GetRestaurantByData(string data)
|
public RestaurantDataModel GetRestaurantByData(string data)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Get element by data: {data}", data);
|
return new("", "", null, null);
|
||||||
if (data.IsEmpty())
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
if (data.IsGuid())
|
|
||||||
{
|
|
||||||
return _restaurantStorageContract.GetElementById(data) ??
|
|
||||||
throw new ElementNotFoundException(data);
|
|
||||||
}
|
|
||||||
return _restaurantStorageContract.GetElementByName(data) ??
|
|
||||||
_restaurantStorageContract.GetElementByOldName(data) ??
|
|
||||||
throw new ElementNotFoundException(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertRestaurant(RestaurantDataModel restaurantDataModel)
|
public void InsertRestaurant(RestaurantDataModel restaurantDataModel)
|
||||||
{
|
{
|
||||||
logger.LogInformation("New data: {json}", JsonSerializer.Serialize(restaurantDataModel));
|
|
||||||
ArgumentNullException.ThrowIfNull(restaurantDataModel);
|
|
||||||
restaurantDataModel.Validate();
|
|
||||||
_restaurantStorageContract.AddElement(restaurantDataModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRestaurant(RestaurantDataModel restaurantDataModel)
|
public void UpdateRestaurant(RestaurantDataModel restaurantDataModel)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(restaurantDataModel));
|
|
||||||
ArgumentNullException.ThrowIfNull(restaurantDataModel);
|
|
||||||
restaurantDataModel.Validate();
|
|
||||||
_restaurantStorageContract.UpdElement(restaurantDataModel);
|
|
||||||
}
|
}
|
||||||
public void DeleteRestaurant(string id)
|
public void DeleteRestaurant(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");
|
|
||||||
}
|
|
||||||
_restaurantStorageContract.DelElement(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,46 +23,15 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
|||||||
|
|
||||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}",fromDate, toDate);
|
return [];
|
||||||
if (fromDate.IsDateNotOlder(toDate))
|
|
||||||
{
|
|
||||||
throw new IncorrectDatesException(fromDate, toDate);
|
|
||||||
}
|
|
||||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
||||||
{
|
{
|
||||||
if (fromDate.IsDateNotOlder(toDate))
|
return [];
|
||||||
{
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate},{ workerId}", fromDate, toDate, workerId);
|
|
||||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ?? throw new NullListException();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void CalculateSalaryByMounth(DateTime date)
|
public void CalculateSalaryByMounth(DateTime date)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("CalculateSalaryByMounth: {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 workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
|
||||||
foreach (var worker in workers)
|
|
||||||
{
|
|
||||||
var orders = _orderStorageContract.GetList(startDate, finishDate, workerId: worker.Id)?.Sum(x => x.Sum) ?? throw new NullListException();
|
|
||||||
var post = _postStorageContract.GetElementById(worker.PostId) ?? throw new NullListException();
|
|
||||||
var salary = post.Salary + orders * 0.1;
|
|
||||||
_logger.LogDebug("The employee {workerId} was paid a salary of { salary}", worker.Id, salary);
|
|
||||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,90 +21,37 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageC
|
|||||||
|
|
||||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}",onlyActive);
|
return [];
|
||||||
return _workerStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
|
||||||
}
|
}
|
||||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllWorkers params: {postId},{ onlyActive},", postId, onlyActive);
|
return [];
|
||||||
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)
|
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllWorkers params: {onlyActive},{ fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
return [];
|
||||||
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)
|
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllWorkers params: {onlyActive},{ fromDate}, { toDate}", onlyActive, fromDate, toDate);
|
return [];
|
||||||
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)
|
public WorkerDataModel GetWorkerByData(string data)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Get element by data: {data}", data);
|
return new("", "", "", "", DateTime.Now, DateTime.Now, true);
|
||||||
if (data.IsEmpty())
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
if (data.IsGuid())
|
|
||||||
{
|
|
||||||
return _workerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
|
||||||
}
|
|
||||||
if (Regex.IsMatch(data, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
|
||||||
{
|
|
||||||
return _workerStorageContract.GetElementByEmail(data) ??
|
|
||||||
throw new ElementNotFoundException(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
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)
|
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)
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user