2023-05-19 19:34:21 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ComputerShopContracts.SearchModels;
|
2023-05-20 00:08:47 +04:00
|
|
|
|
using ComputerShopContracts.StorageContracts;
|
2023-05-19 19:34:21 +04:00
|
|
|
|
using ComputerShopContracts.ViewModels;
|
2023-05-20 00:08:47 +04:00
|
|
|
|
using ComputerShopDataModels.Enums;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-05-19 19:34:21 +04:00
|
|
|
|
using System;
|
2023-05-17 14:20:02 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
2023-05-19 19:34:21 +04:00
|
|
|
|
public class EquipmentReceivingLogic : IEquipmentReceivingLogic
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
2023-05-20 00:08:47 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IEquipmentReceivingStorage _receivingStorage;
|
|
|
|
|
|
|
|
|
|
public EquipmentReceivingLogic(ILogger<PurchaseLogic> logger, IEquipmentReceivingStorage receivingStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_receivingStorage = receivingStorage;
|
|
|
|
|
}
|
2023-05-19 19:34:21 +04:00
|
|
|
|
public List<EquipmentReceivingViewModel>? ReadList(EquipmentReceivingSearchModel? model)
|
|
|
|
|
{
|
2023-05-20 00:08:47 +04:00
|
|
|
|
var list = model == null ? _receivingStorage.GetFullList() : _receivingStorage.GetFilteredList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
2023-05-19 19:34:21 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 00:08:47 +04:00
|
|
|
|
public bool Create(EquipmentReceivingBindingModel model)
|
2023-05-19 19:34:21 +04:00
|
|
|
|
{
|
2023-05-20 00:08:47 +04:00
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (model.Status != EquipmentReceivingStatus.Неизвестен)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed. Receiving status incorrect.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
model.Status = EquipmentReceivingStatus.Ожидается;
|
|
|
|
|
if (_receivingStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
model.Status = EquipmentReceivingStatus.Неизвестен;
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2023-05-19 19:34:21 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-01 19:59:06 +04:00
|
|
|
|
public bool Delete(EquipmentReceivingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
|
|
|
|
if (_receivingStorage.Delete(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Delete operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-05-19 19:34:21 +04:00
|
|
|
|
|
2023-12-01 19:59:06 +04:00
|
|
|
|
public bool Finish(EquipmentReceivingBindingModel model)
|
2023-05-19 19:34:21 +04:00
|
|
|
|
{
|
2023-05-20 00:08:47 +04:00
|
|
|
|
return StatusUpdate(model, EquipmentReceivingStatus.Получено);
|
2023-05-19 19:34:21 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 00:08:47 +04:00
|
|
|
|
private void CheckModel(EquipmentReceivingBindingModel model, bool withParams = true)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool StatusUpdate(EquipmentReceivingBindingModel model, EquipmentReceivingStatus newStatus)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (model.Status + 1 != newStatus)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
model.Status = newStatus;
|
|
|
|
|
if (model.Status == EquipmentReceivingStatus.Получено) model.DateImplement = DateTime.Now;
|
|
|
|
|
if (_receivingStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
model.Status--;
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|