Исправление

This commit is contained in:
Данила Мочалов 2023-04-07 16:05:54 +04:00
parent 0b3b9b391a
commit 71f60ebf7a

View File

@ -81,77 +81,6 @@ namespace LawFirmFileImplement.Implements
return shop.GetViewModel;
}
/* public bool SellDocument(IDocumentModel model, int count)
{
// переделать под linq
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
var countStore = count;
if (document == null)
{
return false;
}
foreach (var shop in source.Shops)
{
foreach (var doc in shop.ShopDocuments)
{
if (doc.Value.Item1.Id == document.Id)
{
count -= doc.Value.Item2;
}
if (count <= 0)
{
break;
}
}
}
if (count > 0)
{
return false;
}
count = countStore;
for (int i = 0; i < source.Shops.Count; i++)
{
var shop = source.Shops[i];
var documents = shop.ShopDocuments;
foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id))
{
var min = Math.Min(doc.Value.Item2, count);
documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min);
count -= min;
if (count <= 0)
{
break;
}
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
Name = shop.Name,
Adress = shop.Adress,
OpeningDate = shop.OpeningDate,
MaxCountDocuments = shop.MaxCountDocuments,
ShopDocuments = documents
});
source.SaveShops();
}
if (count > 0)
{
return false;
}
return true;
}
*/
public bool SellDocument(IDocumentModel model, int count)
{
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);