PIbd-22. Shabunov O.A. Lab work 05 (Hard) #15

Closed
olshab wants to merge 31 commits from Lab5_Hard into Lab5
8 changed files with 60 additions and 1 deletions
Showing only changes of commit 2fa2dfe6bc - Show all commits

View File

@ -13,11 +13,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage)
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage, IShopStorage ShopStorage)
{
_logger = Logger;
_orderStorage = OrderStorage;
_shopStorage = ShopStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
@ -107,6 +110,23 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
public bool DeliveryOrder(OrderBindingModel Model)
{
var Order = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Order is null)
throw new ArgumentNullException(nameof(Order));
if (!_shopStorage.RestockingShops(new SupplyBindingModel
{
RepairId = Order.RepairId,
Count = Order.Count
}))
{
throw new ArgumentException("Недостаточно места");
}
return ChangeOrderStatus(Model, OrderStatus.Delivered);
}

View File

@ -158,5 +158,22 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool Sale(SupplySearchModel Model)
{
if (!Model.PizzaId.HasValue || !Model.Count.HasValue)
return false;
_logger.LogInformation("Проверка ремонтов во всех магазинах");
if (_shopStorage.Sale(Model))
{
_logger.LogInformation("Продажа выполнена успешно");
return true;
}
_logger.LogInformation("Продажа не выполнена");
return false;
}
}
}

View File

@ -13,5 +13,7 @@ namespace AutoWorkshopContracts.BindingModels
public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
public int RepairsMaxCount { get; set; }
}
}

View File

@ -17,5 +17,7 @@ namespace AutoWorkshopContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel Model);
bool MakeSupply(SupplyBindingModel Model);
bool Sale(SupplySearchModel Model);
}
}

View File

@ -0,0 +1,8 @@
namespace PizzeriaContracts.SearchModels
{
public class SupplySearchModel
{
public int? RepairId { get; set; }
public int? Count { get; set; }
}
}

View File

@ -1,6 +1,7 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
using PizzeriaContracts.SearchModels;
namespace AutoWorkshopContracts.StoragesContracts
{
@ -17,5 +18,9 @@ namespace AutoWorkshopContracts.StoragesContracts
ShopViewModel? Update(ShopBindingModel Model);
ShopViewModel? Delete(ShopBindingModel Model);
bool Sale(SupplySearchModel Model);
bool RestockingShops(SupplyBindingModel Model);
}
}

View File

@ -17,5 +17,8 @@ namespace AutoWorkshopContracts.ViewModels
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
[DisplayName("Вместимость")]
public int RepairsMaxCount { get; set; }
}
}

View File

@ -9,5 +9,7 @@
DateTime OpeningDate { get; }
Dictionary<int, (IRepairModel, int)> ShopRepairs { get; }
int RepairsMaxCount { get; }
}
}