Compare commits
3 Commits
5f09122350
...
7b6d7fdfae
Author | SHA1 | Date | |
---|---|---|---|
7b6d7fdfae | |||
|
e6bea06856 | ||
|
51e32cc9f9 |
@ -13,129 +13,124 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CarpentryWorkshopBusinessLogic.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. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
_orderStorage.Insert(new OrderBindingModel
|
||||
{
|
||||
WoodId = model.WoodId,
|
||||
WoodName = model.WoodName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = OrderStatus.Принят,
|
||||
DateCreate = DateTime.Now
|
||||
}); ;
|
||||
return true;
|
||||
}
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Элемент не найден");
|
||||
}
|
||||
if (order.Status.ToString() != "Принят")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Принят\"");
|
||||
}
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
|
||||
Status = OrderStatus.Выполняется
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Не найден заказ");
|
||||
}
|
||||
if (order.Status.ToString() != "Выполняется")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Выполняется\"");
|
||||
}
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
DateImplement = DateTime.Now,
|
||||
Status = OrderStatus.Готов
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Не найден заказ");
|
||||
}
|
||||
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. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
_orderStorage.Insert(new OrderBindingModel
|
||||
{
|
||||
WoodId = model.WoodId,
|
||||
WoodName = model.WoodName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = OrderStatus.Принят,
|
||||
DateCreate = DateTime.Now
|
||||
}); ;
|
||||
return true;
|
||||
}
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Элемент не найден");
|
||||
}
|
||||
if (order.Status.ToString() != "Принят")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Принят\"");
|
||||
}
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
|
||||
if (order.Status.ToString() != "Готов")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Готов\"");
|
||||
}
|
||||
Status = OrderStatus.Выполняется
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Не найден заказ");
|
||||
}
|
||||
if (order.Status.ToString() != "Выполняется")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Выполняется\"");
|
||||
}
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
DateImplement = DateTime.Now,
|
||||
Status = OrderStatus.Готов
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new Exception("Не найден заказ");
|
||||
}
|
||||
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
DateImplement = order.DateImplement,
|
||||
Status = OrderStatus.Выдан
|
||||
});
|
||||
return true;
|
||||
if (order.Status.ToString() != "Готов")
|
||||
{
|
||||
throw new Exception("Заказ не в статусе \"Готов\"");
|
||||
}
|
||||
|
||||
}
|
||||
_orderStorage.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
WoodId = order.WoodId,
|
||||
WoodName = order.WoodName,
|
||||
Count = order.Count,
|
||||
Sum = order.Sum,
|
||||
DateCreate = order.DateCreate,
|
||||
DateImplement = order.DateImplement,
|
||||
Status = OrderStatus.Выдан
|
||||
});
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,11 +88,11 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.WoodName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.WoodName));
|
||||
throw new ArgumentNullException("Нет названия изделия", nameof(model.WoodName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
|
||||
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Wood. WoodName:{WoodName}. Cost:{ Cost}. Id: { Id}", model.WoodName, model.Price, model.Id);
|
||||
var element = _woodStorage.GetElement(new WoodSearchModel
|
||||
@ -101,7 +101,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
throw new InvalidOperationException("Изделие с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace CarpentryWorkshopBusinessLogic
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -16,6 +16,5 @@ namespace CarpentryWorkshopContracts.BusinessLogicsContracts
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace CarpentryWorkshopContracts
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
public string? WoodName { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,5 +16,4 @@ namespace CarpentryWorkshopContracts.ViewModels
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,4 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -10,11 +10,7 @@ namespace CarpentryWorkshopDataModels.Models
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int WoodId { get; }
|
||||
string WoodName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
string WoodName { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -14,14 +14,14 @@ namespace CarpentryWorkshopFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WoodId { get; set; }
|
||||
public string WoodName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int Id { get; private set; }
|
||||
public int WoodId { get; private set; }
|
||||
public string WoodName { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -65,14 +65,7 @@ namespace CarpentryWorkshopFileImplement.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id = model.Id;
|
||||
WoodId = model.WoodId;
|
||||
WoodName = model.WoodName;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
|
@ -13,14 +13,14 @@ namespace CarpentryWorkshopListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WoodId { get; set; }
|
||||
public string WoodName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int Id { get; private set; }
|
||||
public int WoodId { get; private set; }
|
||||
public string WoodName { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -27,5 +27,4 @@
|
||||
<ProjectReference Include="..\CarpentryWorkshopFileImplement\CarpentryWorkshopFileImplement.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
2
CarpentryWorkshopView/FormComponent.Designer.cs
generated
2
CarpentryWorkshopView/FormComponent.Designer.cs
generated
@ -100,7 +100,7 @@
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.ButtonSave);
|
||||
this.Name = "FormComponent";
|
||||
this.Text = "FormComponent";
|
||||
this.Text = "Форма Компонента";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
Loading…
Reference in New Issue
Block a user