Mochalov D.V. LabWork05_Hard #13

Closed
b0n3l3sS wants to merge 63 commits from LabWork05_Hard into LabWork05_Base
Showing only changes of commit 71f60ebf7a - Show all commits

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