Подправил

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("Пополнение магазина"); _logger.LogInformation("Пополнение магазина");
try try
{ {
var operationResult = _logicS.AddTextile(new SupplyBindingModel var operationResult = _logicS.MakeSupply(new SupplyBindingModel
{ {
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue), TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue),

View File

@ -38,20 +38,21 @@ namespace GarmentFactory
services.AddTransient<IComponentStorage, ComponentStorage>(); services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ITextileStorage, TextileStorage>(); services.AddTransient<ITextileStorage, TextileStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ITextileLogic, TextileLogic>(); services.AddTransient<ITextileLogic, TextileLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormComponent>(); services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>(); services.AddTransient<FormCreateOrder>();
services.AddTransient<FormTextile>(); services.AddTransient<FormTextile>();
services.AddTransient<FormTextileComponent>(); services.AddTransient<FormTextileComponent>();
services.AddTransient<FormTextiles>(); services.AddTransient<FormTextiles>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormShop>(); services.AddTransient<FormShop>();
services.AddTransient<FormShops>(); services.AddTransient<FormShops>();
services.AddTransient<FormAddTextile>(); services.AddTransient<FormAddTextile>();

View File

@ -140,6 +140,8 @@ namespace GarmentFactoryBusinessLogic
{ {
throw new ArgumentNullException(nameof(order)); throw new ArgumentNullException(nameof(order));
} }
//Если нельзя пополнить магазины таким кол-вом товаров (не хавтает места), то статус не меняем
if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count })) if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count }))
{ {
throw new ArgumentException("Недостаточно места"); throw new ArgumentException("Недостаточно места");

View File

@ -109,7 +109,7 @@ namespace GarmentFactoryBusinessLogic
} }
// Пополнение магазина // Пополнение магазина
public bool AddTextile(SupplyBindingModel model) public bool MakeSupply(SupplyBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -121,34 +121,52 @@ namespace GarmentFactoryBusinessLogic
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0"); 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];
if (shop.ShopTextiles.ContainsKey(model.TextileId)) oldValue.Item2 += model.Count;
{ shop.ShopTextiles[model.TextileId] = oldValue;
var oldValue = shop.ShopTextiles[model.TextileId]; }
oldValue.Item2 += model.Count; // Если такого товара нет, то кол-во такого товара равно переданному кол-ву
shop.ShopTextiles[model.TextileId] = oldValue; else
} {
// Если такого товара нет, то кол-во такого товара равно переданному кол-ву shop.ShopTextiles.Add(model.TextileId, (textile, model.Count));
else }
{
var textile = _textileStorage.GetElement(new TextileSearchModel{ Id = model.TextileId }); _shopStorage.Update(new()
if (textile == null)
{ {
throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден"); Id = shop.Id,
} ShopName = shop.ShopName,
shop.ShopTextiles.Add(model.TextileId, (textile, model.Count)); Address = shop.Address,
} DateOpen = shop.DateOpen,
return true; ShopTextiles = shop.ShopTextiles,
TextileMaxCount = shop.TextileMaxCount,
});
return true;
}
//Если не поместилось столько товара
_logger.LogWarning("Required shop is overflowed");
return false;
} }
// Проверка данных магазина при добавлении/удалении/обновлении // Проверка данных магазина при добавлении/удалении/обновлении
private void CheckModel(ShopBindingModel model, bool withParams = true) private void CheckModel(ShopBindingModel model, bool withParams = true)
{ {

View File

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

View File

@ -17,6 +17,7 @@ namespace GarmentFactoryContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model);
//Продажа изделий в нужном кол-ве
bool Sell(SupplySearchModel model); bool Sell(SupplySearchModel model);
//Пополнение магаз-ов //Пополнение магаз-ов
bool RestockShops(SupplyBindingModel model); bool RestockShops(SupplyBindingModel model);

View File

@ -2,6 +2,7 @@
using GarmentFactoryContracts.SearchModels; using GarmentFactoryContracts.SearchModels;
using GarmentFactoryContracts.StoragesContracts; using GarmentFactoryContracts.StoragesContracts;
using GarmentFactoryContracts.ViewModels; using GarmentFactoryContracts.ViewModels;
using GarmentFactoryDataModels.Models;
using GarmentFactoryListImplement.Models; using GarmentFactoryListImplement.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -110,7 +111,7 @@ namespace GarmentFactoryListImplement.Implements
return null; return null;
} }
public bool Sell (SupplySearchModel model) public bool Sell(SupplySearchModel model)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }