done
This commit is contained in:
parent
091ab47519
commit
c0e55f8227
@ -13,6 +13,7 @@ namespace BlacksmithWorkshopContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ManufactureId { get; set; }
|
||||
public string ManufactureName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -8,10 +8,9 @@ using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.SearchModels;
|
||||
using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopListImplement;
|
||||
using BlacksmithWorkshopListImplement.Models;
|
||||
|
||||
namespace OrdersShopListImplement.Implements
|
||||
namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
@ -25,7 +24,7 @@ namespace OrdersShopListImplement.Implements
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
result.Add(AttachManufactureName(Order.GetViewModel));
|
||||
result.Add(Order.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -40,7 +39,7 @@ namespace OrdersShopListImplement.Implements
|
||||
{
|
||||
if (Order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachManufactureName(Order.GetViewModel));
|
||||
result.Add(Order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -55,7 +54,7 @@ namespace OrdersShopListImplement.Implements
|
||||
{
|
||||
if (model.Id.HasValue && Order.Id == model.Id)
|
||||
{
|
||||
return AttachManufactureName(Order.GetViewModel);
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -76,7 +75,7 @@ namespace OrdersShopListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newOrder);
|
||||
return AttachManufactureName(newOrder.GetViewModel);
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
@ -85,7 +84,7 @@ namespace OrdersShopListImplement.Implements
|
||||
if (Order.Id == model.Id)
|
||||
{
|
||||
Order.Update(model);
|
||||
return AttachManufactureName(Order.GetViewModel);
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -98,22 +97,22 @@ namespace OrdersShopListImplement.Implements
|
||||
{
|
||||
var element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return AttachManufactureName(element.GetViewModel);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OrderViewModel AttachManufactureName(OrderViewModel model)
|
||||
{
|
||||
foreach (var manufacture in _source.Manufactures)
|
||||
{
|
||||
if (manufacture.Id == model.ManufactureId)
|
||||
{
|
||||
model.ManufactureName = manufacture.ManufactureName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
//private OrderViewModel AttachManufactureName(OrderViewModel model)
|
||||
//{
|
||||
// foreach (var manufacture in _source.Manufactures)
|
||||
// {
|
||||
// if (manufacture.Id == model.ManufactureId)
|
||||
// {
|
||||
// model.ManufactureName = manufacture.ManufactureName;
|
||||
// return model;
|
||||
// }
|
||||
// }
|
||||
// return model;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -16,19 +16,13 @@ namespace BlacksmithWorkshopListImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ManufactureId { get; private set; }
|
||||
|
||||
public string ManufactureName { get; private set; } = string.Empty;
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -39,6 +33,7 @@ namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ManufactureId = model.ManufactureId,
|
||||
ManufactureName = model.ManufactureName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -54,6 +49,7 @@ namespace BlacksmithWorkshopListImplement.Models
|
||||
return;
|
||||
}
|
||||
ManufactureId = model.ManufactureId;
|
||||
ManufactureName = model.ManufactureName;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
@ -64,6 +60,7 @@ namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
ManufactureId = ManufactureId,
|
||||
ManufactureName = ManufactureName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -11,7 +11,7 @@ using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic
|
||||
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ManufactureLogic : IManufactureLogic
|
||||
{
|
@ -12,19 +12,17 @@ using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic
|
||||
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||
@ -37,7 +35,6 @@ namespace BlacksmithWorkshopBusinessLogic
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -49,28 +46,24 @@ namespace BlacksmithWorkshopBusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (!CheckStatus(model, OrderStatus.Выполняется)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (!CheckStatus(model, OrderStatus.Готов)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (!CheckStatus(model, OrderStatus.Выдан)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (!CheckStatus(model, OrderStatus.Готов)) return false;
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -93,7 +86,7 @@ namespace BlacksmithWorkshopBusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. ManufactureId: { ManufactureId}", model.Id, model.Sum, model.ManufactureId);
|
||||
_logger.LogInformation("Order. OrderId: {Id}.Sum: {Sum}. ManufactureId: {ManufactureId}", model.Id, model.Sum, model.ManufactureId);
|
||||
}
|
||||
|
||||
private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true)
|
@ -87,6 +87,7 @@ namespace BlacksmithWorkshopView
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue),
|
||||
ManufactureName = comboBoxManufacture.Text,
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
});
|
||||
|
@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using BlacksmithWorkshopDataModels.Models;
|
||||
using BlacksmithWorkshopDataModels.Enums;
|
||||
|
||||
namespace BlacksmithWorkshopView
|
||||
{
|
||||
@ -78,10 +79,19 @@ namespace BlacksmithWorkshopView
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id);
|
||||
_logger.LogInformation("Заказ No {id}. Меняется статус на 'В работе'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = id,
|
||||
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
|
||||
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -100,10 +110,20 @@ namespace BlacksmithWorkshopView
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id);
|
||||
_logger.LogInformation("Заказ No {id}. Меняется статус на 'Готов'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = id,
|
||||
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
|
||||
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()),
|
||||
DateImplement = DateTime.Now,
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -122,15 +142,25 @@ namespace BlacksmithWorkshopView
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
|
||||
_logger.LogInformation("Заказ No {id}. Меняется статус на 'Выдан'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = id,
|
||||
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
|
||||
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()),
|
||||
DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
_logger.LogInformation("Заказ No{id} выдан", id);
|
||||
_logger.LogInformation("Заказ No {id} выдан", id);
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,12 +1,10 @@
|
||||
using BlacksmithWorkshopBusinessLogic.BusinessLogics;
|
||||
using BlacksmithWorkshopBusinessLogic;
|
||||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopListImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using OrdersShopListImplement.Implements;
|
||||
|
||||
namespace BlacksmithWorkshopView
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user