CourseWork_CompShop/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs
2023-05-20 00:08:47 +04:00

102 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.StorageContracts;
using ComputerShopContracts.ViewModels;
using ComputerShopDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerShopBusinessLogic.BusinessLogics
{
public class EquipmentReceivingLogic : IEquipmentReceivingLogic
{
private readonly ILogger _logger;
private readonly IEquipmentReceivingStorage _receivingStorage;
public EquipmentReceivingLogic(ILogger<PurchaseLogic> logger, IEquipmentReceivingStorage receivingStorage)
{
_logger = logger;
_receivingStorage = receivingStorage;
}
public List<EquipmentReceivingViewModel>? ReadList(EquipmentReceivingSearchModel? model)
{
var list = model == null ? _receivingStorage.GetFullList() : _receivingStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
return list;
}
public bool Create(EquipmentReceivingBindingModel model)
{
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;
}
public bool TakeOrderInWork(EquipmentReceivingBindingModel model)
{
return StatusUpdate(model, EquipmentReceivingStatus.Ожидается);
}
public bool Finish(EquipmentReceivingBindingModel model)
{
return StatusUpdate(model, EquipmentReceivingStatus.Получено);
}
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;
}
public bool TakeInWork(EquipmentReceivingBindingModel model)
{
throw new NotImplementedException();
}
}
}