2024-05-19 18:43:00 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
|
|
|
|
using ElectronicsShopContracts.StorageContracts;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-05-26 18:12:25 +04:00
|
|
|
|
using ElectronicsShopDataModels.Enums;
|
2024-05-19 18:43:00 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public class PaymeantLogic : IPaymeantLogic
|
2024-05-19 18:43:00 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2024-05-26 18:12:25 +04:00
|
|
|
|
private readonly IPaymeantStorage _storage;
|
2024-05-19 18:43:00 +04:00
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public PaymeantLogic(ILogger<PaymeantLogic> logger, IPaymeantStorage storage) {
|
2024-05-26 17:47:24 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_storage = storage;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public bool CreatePay(PaymeantBindingModel model)
|
2024-05-19 18:43:00 +04:00
|
|
|
|
{
|
2024-05-25 15:04:18 +04:00
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_storage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-05-19 18:43:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public PaymeantViewModel? ReadElement(PaymeantSearchModel model)
|
2024-05-19 18:43:00 +04:00
|
|
|
|
{
|
2024-05-25 15:04:18 +04:00
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation($"ReadElement.ProductID:{model.ProductID}.ID:{model.ID}");
|
|
|
|
|
var element = _storage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadElement. element not fount");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
|
|
|
|
|
return element;
|
2024-05-19 18:43:00 +04:00
|
|
|
|
}
|
2024-05-25 15:04:18 +04:00
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public List<PaymeantViewModel>? ReadList(PaymeantSearchModel? model)
|
2024-05-19 18:43:00 +04:00
|
|
|
|
{
|
2024-05-25 15:04:18 +04:00
|
|
|
|
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
|
2024-05-26 17:47:24 +04:00
|
|
|
|
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
|
2024-05-25 15:04:18 +04:00
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList. return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-05-26 17:47:24 +04:00
|
|
|
|
_logger.LogInformation($"ReadList.Count:{list.Count}");
|
2024-05-25 15:04:18 +04:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-26 18:12:25 +04:00
|
|
|
|
|
|
|
|
|
private void CheckModel(PaymeantBindingModel model, bool withParams = true)
|
2024-05-25 15:04:18 +04:00
|
|
|
|
{
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (model.SumPayment <= 0)
|
|
|
|
|
{
|
2024-05-26 17:47:24 +04:00
|
|
|
|
throw new ArgumentNullException("Сумма оплаты должна быть больше 0", nameof(model.SumPayment));
|
2024-05-25 15:04:18 +04:00
|
|
|
|
}
|
2024-05-26 17:47:24 +04:00
|
|
|
|
_logger.LogInformation($"Payment. ID:{model.ID}.ProductID:{model.ProductID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}" +
|
|
|
|
|
$".PayOption{model.PayOption}");
|
2024-05-19 18:43:00 +04:00
|
|
|
|
}
|
2024-05-26 18:12:25 +04:00
|
|
|
|
|
|
|
|
|
public bool SetFullPayment(PaymeantBindingModel model) {
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetPartialPayemnt(PaymeantBindingModel model) {
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) {
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
model.PayOption = paymeantOption;
|
|
|
|
|
if (_storage.UpdatePay == null) {
|
|
|
|
|
_logger.LogWarning("update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-19 18:43:00 +04:00
|
|
|
|
}
|