Получается рефакторинг.
This commit is contained in:
parent
3c803705c3
commit
cc59bf5dd5
@ -86,13 +86,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shop.Manufactures.ContainsKey(manufacture.Id))
|
||||
if (!shop.ShopManufactures.ContainsKey(manufacture.Id))
|
||||
{
|
||||
shop.Manufactures[manufacture.Id] = (manufacture, count);
|
||||
shop.ShopManufactures[manufacture.Id] = (manufacture, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Manufactures[manufacture.Id] = (manufacture, shop.Manufactures[manufacture.Id].Item2 + count);
|
||||
shop.ShopManufactures[manufacture.Id] = (manufacture, shop.ShopManufactures[manufacture.Id].Item2 + count);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
@ -101,7 +101,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
MaxCountManufactures = shop.MaxCountManufactures,
|
||||
Manufactures = shop.Manufactures
|
||||
ShopManufactures = shop.ShopManufactures
|
||||
});
|
||||
|
||||
return true;
|
||||
@ -112,9 +112,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
|
||||
{
|
||||
int _countManufactures = 0;
|
||||
|
||||
foreach (var manufacture in model.Manufactures)
|
||||
foreach (var manufacture in model.ShopManufactures)
|
||||
{
|
||||
_countManufactures += model.Manufactures[manufacture.Key].Item2;
|
||||
_countManufactures += model.ShopManufactures[manufacture.Key].Item2;
|
||||
}
|
||||
|
||||
if(_countManufactures + count > model.MaxCountManufactures)
|
||||
@ -211,7 +211,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
|
||||
|
||||
_logger.LogInformation("AddManufactures. Manufacture: {Manufacture}. Count: {Count}", model?.ManufactureName, count);
|
||||
|
||||
var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountManufactures - x.Manufactures.Select(x => x.Value.Item2).Sum()).Sum() - count;
|
||||
var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountManufactures - x.ShopManufactures.Select(x => x.Value.Item2).Sum()).Sum() - count;
|
||||
|
||||
if (capacity < 0)
|
||||
{
|
||||
@ -221,16 +221,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count)
|
||||
if (shop.MaxCountManufactures - shop.ShopManufactures.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
if (!AddManufacture(new() { Id = shop.Id }, model, shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum()))
|
||||
if (!AddManufacture(new() { Id = shop.Id }, model, shop.MaxCountManufactures - shop.ShopManufactures.Select(x => x.Value.Item2).Sum()))
|
||||
{
|
||||
_logger.LogWarning("AddManufactures operation failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
count -= shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum();
|
||||
count -= shop.MaxCountManufactures - shop.ShopManufactures.Select(x => x.Value.Item2).Sum();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace BlacksmithWorkshopContracts.BindingModels
|
||||
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
|
||||
public Dictionary<int, (IManufactureModel, int)> ShopManufactures { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace BlacksmithWorkshopContracts.ViewModels
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
|
||||
public Dictionary<int, (IManufactureModel, int)> ShopManufactures { get; set; } = new();
|
||||
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int MaxCountManufactures { get; set; }
|
||||
|
@ -23,6 +23,6 @@ namespace BlacksmithWorkshopDataModels.Models
|
||||
int MaxCountManufactures { get; }
|
||||
|
||||
//изделия в магазине
|
||||
Dictionary<int, (IManufactureModel, int)> Manufactures { get; }
|
||||
Dictionary<int, (IManufactureModel, int)> ShopManufactures { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user