Подправил

This commit is contained in:
ujijrujijr 2024-05-09 17:22:02 +04:00
parent d7a6317852
commit 28b5ed2cfe
7 changed files with 54 additions and 31 deletions

View File

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

View File

@ -38,10 +38,12 @@ namespace GarmentFactory
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ITextileStorage, TextileStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ITextileLogic, TextileLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
@ -50,8 +52,7 @@ namespace GarmentFactory
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>();

View File

@ -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("Недостаточно места");

View File

@ -109,7 +109,7 @@ namespace GarmentFactoryBusinessLogic
}
// Пополнение магазина
public bool AddTextile(SupplyBindingModel model)
public bool MakeSupply(SupplyBindingModel model)
{
if (model == null)
{
@ -121,13 +121,23 @@ 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} не найден");
}
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)
{
// Если такой товар есть, то прибавление переданного кол-ва
if (shop.ShopTextiles.ContainsKey(model.TextileId))
{
@ -138,16 +148,24 @@ namespace GarmentFactoryBusinessLogic
// Если такого товара нет, то кол-во такого товара равно переданному кол-ву
else
{
var textile = _textileStorage.GetElement(new TextileSearchModel{ Id = model.TextileId });
if (textile == null)
{
throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден");
}
shop.ShopTextiles.Add(model.TextileId, (textile, model.Count));
}
_shopStorage.Update(new()
{
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)

View File

@ -22,7 +22,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool AddTextile(SupplyBindingModel model);
bool MakeSupply(SupplyBindingModel model);
bool Sell(SupplySearchModel model);
}

View File

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

View File

@ -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;