ISEbd-21 Melnikov I. O. Lab Work 02 Advanced #16

Closed
Igor-Melnikov wants to merge 5 commits from lab2adv into lab1adv
5 changed files with 22 additions and 1 deletions
Showing only changes of commit 3ac21871a6 - Show all commits

View File

@ -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))
{

View File

@ -27,5 +27,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
/// <param name="count">Количество</param>
/// <returns></returns>
bool SellManufacture(IManufactureModel manufacture, int count);
int GetPlaceLeft(IStoreModel store);
}
}

View File

@ -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();
}
}
}

View File

@ -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()
{

View File

@ -108,5 +108,10 @@ namespace BlacksmithWorkshopListImplement.Implements
{
throw new NotImplementedException("Не применяется в данной реализации");
}
public int GetPlaceLeft(IStoreModel store)
{
throw new NotImplementedException("Не применяется в данной реализации");
}
}
}