Compare commits
No commits in common. "fa374edd58b1fd02342af15a3c166777387995e6" and "8e0cbf292bef71f3bd22739e72d7c7dd44201bfc" have entirely different histories.
fa374edd58
...
8e0cbf292b
@ -89,43 +89,34 @@ namespace GarmentFactoryFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int remainingSpace = source.Shops.Select(x => x.Textiles.ContainsKey(model.TextileId.Value) ? x.Textiles[model.TextileId.Value] : 0).Sum();
|
||||||
|
|
||||||
//магазины по степени наполненности (от самого наполненного) с этим текстилем
|
if (remainingSpace < model.Count)
|
||||||
var shopsWithThisTextile = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList();
|
|
||||||
|
|
||||||
int thisTextileInShops = shopsWithThisTextile.Select(x => x.Textiles[model.TextileId.Value]).Sum();
|
|
||||||
|
|
||||||
if (thisTextileInShops < model.Count)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var shop in shopsWithThisTextile)
|
var shops = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList();
|
||||||
{
|
|
||||||
//кол-во необходимых текстилей после возможной продажи всех текстилей
|
|
||||||
int thisTextileNeed = model.Count.Value - shop.Textiles[model.TextileId.Value];
|
|
||||||
|
|
||||||
//Если текстиль ещё нужен будет
|
foreach (var shop in shops)
|
||||||
if (thisTextileNeed > 0)
|
{
|
||||||
|
int residue = model.Count.Value - shop.Textiles[model.TextileId.Value];
|
||||||
|
if (residue > 0)
|
||||||
{
|
{
|
||||||
//удаление всех текстилей в этом магазине
|
|
||||||
shop.Textiles.Remove(model.TextileId.Value);
|
shop.Textiles.Remove(model.TextileId.Value);
|
||||||
shop.TextilesUpdate();
|
shop.TextilesUpdate();
|
||||||
model.Count = thisTextileNeed;
|
model.Count = residue;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Если ровно хватает
|
if (residue == 0)
|
||||||
if (thisTextileNeed == 0)
|
|
||||||
{
|
{
|
||||||
shop.Textiles.Remove(model.TextileId.Value);
|
shop.Textiles.Remove(model.TextileId.Value);
|
||||||
}
|
}
|
||||||
//Если нужно меньше, чем есть в магазине
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//уменьшение кол-ва
|
shop.Textiles[model.TextileId.Value] = -residue;
|
||||||
shop.Textiles[model.TextileId.Value] = -thisTextileNeed;
|
|
||||||
}
|
}
|
||||||
shop.TextilesUpdate();
|
shop.TextilesUpdate();
|
||||||
source.SaveShops();
|
source.SaveShops();
|
||||||
|
Loading…
Reference in New Issue
Block a user