Compare commits

..

No commits in common. "80550c60fd7a85c8b637c32379ccf4ab0d19e9bc" and "21a3fe7c630d9344b68badb9269b8d5a38ef531f" have entirely different histories.

2 changed files with 30 additions and 51 deletions

View File

@ -108,7 +108,9 @@ namespace RenovationWorkView
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{ Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -125,27 +127,28 @@ namespace RenovationWorkView
private void buttonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel {Id = id});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ No{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonRef_Click(object sender, EventArgs e)
{

View File

@ -49,13 +49,13 @@ 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");
@ -63,13 +63,13 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}
if (element.Status == OrderStatus.Готов)
{
var repair = _repairStorage.GetElement(new RepairSearchModel() { Id = model.RepairId });
if (repair == null)
var manufacture = _repairStorage.GetElement(new RepairSearchModel() { Id = model.RepairId });
if (manufacture == null)
{
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found.");
return false;
}
if (CheckSupply(repair, model.Count) == false)
if (CheckSupply(manufacture, model.Count) == false)
{
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error.");
return false;
@ -130,31 +130,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}
_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)
{
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 bool CheckSupply(IRepairModel repair, int count)
private bool CheckSupply(IRepairModel repair, int count)
{
if (count <= 0)
{