Merge branch 'lab2_hard' into lab3_hard

This commit is contained in:
prodigygirl 2023-03-23 20:28:24 +04:00
commit 9db137ac76
2 changed files with 14 additions and 15 deletions

View File

@ -108,12 +108,7 @@ namespace FurnitureAssembly
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
int furnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value);
int furnitureCount = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value);
if (!_shopLogic.AddFurnituresAtShops(new FurnitureBindingModel { Id = furnitureId }, furnitureCount)) {
MessageBox.Show("Магазины переполнены. Пополнение невозможно", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try try
{ {
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
@ -121,11 +116,7 @@ namespace FurnitureAssembly
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
@ -142,8 +133,7 @@ namespace FurnitureAssembly
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
id);
try try
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });

View File

@ -17,11 +17,13 @@ namespace FurnitureAssemblyBusinessLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopLogic = shopLogic;
} }
private bool ChangeStatus(OrderBindingModel model, OrderStatus orderStatus) private bool ChangeStatus(OrderBindingModel model, OrderStatus orderStatus)
@ -91,6 +93,13 @@ namespace FurnitureAssemblyBusinessLogic
{ {
return false; return false;
} }
if (!_shopLogic.AddFurnituresAtShops(new FurnitureBindingModel() { Id = model.FurnitureId}, model.Count))
{
_logger.LogWarning("There are not empty places at shops. Replenishment is impossible");
return false;
}
if (!ChangeStatus(model, OrderStatus.Выдан)) if (!ChangeStatus(model, OrderStatus.Выдан))
{ {
_logger.LogWarning("Order's status is wrong"); _logger.LogWarning("Order's status is wrong");