Лаб_2сложн

This commit is contained in:
yuliya.mavrina@internet.ru 2024-04-23 15:48:49 +03:00
parent 21a3fe7c63
commit 14c5a5991c

View File

@ -49,13 +49,14 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}
private bool StatusUpdate(OrderBindingModel model, OrderStatus status)
{
CheckModel(model);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
CheckModel(element);
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
@ -107,6 +108,30 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
return list;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.RepairId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.RepairId));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество работ в заказе должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id);
}
private void CheckModel(OrderViewModel model, bool withParams = true)
{
if (model == null)
{