Исправления
This commit is contained in:
parent
9452d830d3
commit
19340bfe98
@ -1,5 +1,6 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -83,7 +84,7 @@ namespace FurnitureAssembly
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
var operationResult = _orderLogic.TakeOrderInWork(GetOrderBindingModel());
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -107,10 +108,8 @@ namespace FurnitureAssembly
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
|
||||
id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new
|
||||
OrderBindingModel
|
||||
{ Id = id });
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(GetOrderBindingModel());
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -134,10 +133,8 @@ namespace FurnitureAssembly
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
|
||||
id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(new
|
||||
OrderBindingModel
|
||||
{ Id = id });
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(GetOrderBindingModel());
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -157,5 +154,19 @@ namespace FurnitureAssembly
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private OrderBindingModel GetOrderBindingModel()
|
||||
{
|
||||
return new OrderBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value),
|
||||
FurnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value),
|
||||
FurnitureName = dataGridView.SelectedRows[0].Cells["FurnitureName"].Value.ToString(),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,39 +24,70 @@ namespace FurnitureAssemblyBusinessLogic
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus orderStatus)
|
||||
{
|
||||
if (model.Status + 1 != orderStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
model.Status = orderStatus;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (!ChangeStatus(model, OrderStatus.Принят))
|
||||
{
|
||||
_logger.LogWarning("Order's status is wrong");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Принят;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
if (model.Status.Equals(OrderStatus.Готов))
|
||||
if (!ChangeStatus(model, OrderStatus.Выполняется))
|
||||
{
|
||||
model.Status = OrderStatus.Выдан;
|
||||
model.DateImplement = DateTime.Now;
|
||||
return true;
|
||||
_logger.LogWarning("Order's status is wrong");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
if (model.Status.Equals(OrderStatus.Выполняется))
|
||||
if (!ChangeStatus(model, OrderStatus.Готов))
|
||||
{
|
||||
model.Status = OrderStatus.Готов;
|
||||
return true;
|
||||
_logger.LogWarning("Order's status is wrong");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
if (!ChangeStatus(model, OrderStatus.Выдан))
|
||||
{
|
||||
_logger.LogWarning("Order's status is wrong");
|
||||
return false;
|
||||
}
|
||||
model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
@ -70,16 +101,7 @@ namespace FurnitureAssemblyBusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
if (model.Status.Equals(OrderStatus.Принят))
|
||||
{
|
||||
model.Status = OrderStatus.Выполняется;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -92,7 +114,7 @@ namespace FurnitureAssemblyBusinessLogic
|
||||
}
|
||||
if (model.FurnitureId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Идентификатор изделия должен быть больше 0", nameof(model.FurnitureId));
|
||||
throw new ArgumentNullException("Неверный идентификатор изделия", nameof(model.FurnitureId));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
@ -102,7 +124,9 @@ namespace FurnitureAssemblyBusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. FurnitureId:{FurnitureId}. Count:{ Count}. Sum:{ Sum}. OrderStatus: {OrderStatus} DateCreate: {DateCreate}. Id: { Id}", model.FurnitureId, model.Count, model.Sum, model.Status, model.DateCreate, model.Id);
|
||||
_logger.LogInformation("Order. OrderId: { Id}. OrderStatus: {OrderStatus} DateCreate: {DateCreate} " +
|
||||
"FurnitureId:{FurnitureId}. FurnitureName:{FurnitureName}. Count:{ Count}. Sum:{ Sum}. ",
|
||||
model.Id, model.Status, model.DateCreate, model.FurnitureId, model.FurnitureName, model.Count, model.Sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user