Подправил
This commit is contained in:
parent
d7a6317852
commit
28b5ed2cfe
@ -78,7 +78,7 @@ namespace GarmentFactoryView
|
||||
_logger.LogInformation("Пополнение магазина");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicS.AddTextile(new SupplyBindingModel
|
||||
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
||||
{
|
||||
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
||||
TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue),
|
||||
|
@ -38,20 +38,21 @@ namespace GarmentFactory
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ITextileStorage, TextileStorage>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ITextileLogic, TextileLogic>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormTextile>();
|
||||
services.AddTransient<FormTextileComponent>();
|
||||
services.AddTransient<FormTextiles>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormAddTextile>();
|
||||
|
@ -140,6 +140,8 @@ namespace GarmentFactoryBusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(order));
|
||||
}
|
||||
|
||||
//Если нельзя пополнить магазины таким кол-вом товаров (не хавтает места), то статус не меняем
|
||||
if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count }))
|
||||
{
|
||||
throw new ArgumentException("Недостаточно места");
|
||||
|
@ -109,7 +109,7 @@ namespace GarmentFactoryBusinessLogic
|
||||
}
|
||||
|
||||
// Пополнение магазина
|
||||
public bool AddTextile(SupplyBindingModel model)
|
||||
public bool MakeSupply(SupplyBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -121,34 +121,52 @@ namespace GarmentFactoryBusinessLogic
|
||||
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0");
|
||||
}
|
||||
|
||||
var shop = _shopStorage.GetElement(new ShopSearchModel{ Id = model.ShopId });
|
||||
var textile = _textileStorage.GetElement(new TextileSearchModel { Id = model.TextileId });
|
||||
if (textile == null)
|
||||
{
|
||||
throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден");
|
||||
}
|
||||
|
||||
if (shop == null)
|
||||
var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.ShopId });
|
||||
if (shop == null)
|
||||
{
|
||||
throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден");
|
||||
}
|
||||
|
||||
int countTextilesInShop = shop.ShopTextiles.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
//Если в текущий магазин помещается столько товаров
|
||||
if (countTextilesInShop + model.Count <= shop.TextileMaxCount)
|
||||
{
|
||||
throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден");
|
||||
}
|
||||
|
||||
// Если такой товар есть, то прибавление переданного кол-ва
|
||||
if (shop.ShopTextiles.ContainsKey(model.TextileId))
|
||||
{
|
||||
var oldValue = shop.ShopTextiles[model.TextileId];
|
||||
oldValue.Item2 += model.Count;
|
||||
shop.ShopTextiles[model.TextileId] = oldValue;
|
||||
}
|
||||
// Если такого товара нет, то кол-во такого товара равно переданному кол-ву
|
||||
else
|
||||
{
|
||||
var textile = _textileStorage.GetElement(new TextileSearchModel{ Id = model.TextileId });
|
||||
if (textile == null)
|
||||
// Если такой товар есть, то прибавление переданного кол-ва
|
||||
if (shop.ShopTextiles.ContainsKey(model.TextileId))
|
||||
{
|
||||
var oldValue = shop.ShopTextiles[model.TextileId];
|
||||
oldValue.Item2 += model.Count;
|
||||
shop.ShopTextiles[model.TextileId] = oldValue;
|
||||
}
|
||||
// Если такого товара нет, то кол-во такого товара равно переданному кол-ву
|
||||
else
|
||||
{
|
||||
shop.ShopTextiles.Add(model.TextileId, (textile, model.Count));
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден");
|
||||
}
|
||||
shop.ShopTextiles.Add(model.TextileId, (textile, model.Count));
|
||||
}
|
||||
return true;
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
ShopTextiles = shop.ShopTextiles,
|
||||
TextileMaxCount = shop.TextileMaxCount,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
//Если не поместилось столько товара
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Проверка данных магазина при добавлении/удалении/обновлении
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts
|
||||
|
||||
bool Delete(ShopBindingModel model);
|
||||
|
||||
bool AddTextile(SupplyBindingModel model);
|
||||
bool MakeSupply(SupplyBindingModel model);
|
||||
|
||||
bool Sell(SupplySearchModel model);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace GarmentFactoryContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
//Продажа изделий в нужном кол-ве
|
||||
bool Sell(SupplySearchModel model);
|
||||
//Пополнение магаз-ов
|
||||
bool RestockShops(SupplyBindingModel model);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using GarmentFactoryContracts.SearchModels;
|
||||
using GarmentFactoryContracts.StoragesContracts;
|
||||
using GarmentFactoryContracts.ViewModels;
|
||||
using GarmentFactoryDataModels.Models;
|
||||
using GarmentFactoryListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -110,7 +111,7 @@ namespace GarmentFactoryListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Sell (SupplySearchModel model)
|
||||
public bool Sell(SupplySearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user