ISEbd-21 Melnikov I. O. Lab Work 02 Advanced #16
@ -6,6 +6,7 @@ using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -109,6 +110,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Store with id {Id} not found", model.Id);
|
||||
return false;
|
||||
}
|
||||
var placeLeft = _storeStorage.GetPlaceLeft(selectedStore);
|
||||
if (placeLeft < count)
|
||||
{
|
||||
_logger.LogWarning("Store with id {Id} can't accomodate {Count} items", model.Id, count);
|
||||
return false;
|
||||
}
|
||||
//ищем изделие в магазине
|
||||
if (selectedStore.Manufactures.TryGetValue(manufacture.Id, out var manufactureInStore))
|
||||
{
|
||||
|
@ -27,5 +27,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
|
||||
/// <param name="count">Количество</param>
|
||||
/// <returns></returns>
|
||||
bool SellManufacture(IManufactureModel manufacture, int count);
|
||||
int GetPlaceLeft(IStoreModel store);
|
||||
}
|
||||
}
|
@ -113,5 +113,14 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetPlaceLeft(IStoreModel model)
|
||||
{
|
||||
var store = source.Stores.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (store == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return store.MaxManufactures - store.Manufactures.Select(x => x.Value.Item2).Sum();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,6 @@ namespace BlacksmithWorkshopFileImplement.Models
|
||||
OpeningDate= model.OpeningDate;
|
||||
SavedManufactures = model.Manufactures.ToDictionary(x => x.Value.Item1.Id, x => x.Value.Item2);
|
||||
_manufactures = null;
|
||||
MaxManufactures = model.MaxManufactures;
|
||||
}
|
||||
public StoreViewModel GetViewModel => new()
|
||||
{
|
||||
|
@ -108,5 +108,10 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
throw new NotImplementedException("Не применяется в данной реализации");
|
||||
}
|
||||
|
||||
public int GetPlaceLeft(IStoreModel store)
|
||||
{
|
||||
throw new NotImplementedException("Не применяется в данной реализации");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user