проверка

This commit is contained in:
antoc0der 2024-04-25 22:22:23 +04:00
parent 580e7adc0c
commit 531aa03753
2 changed files with 36 additions and 36 deletions

View File

@ -18,6 +18,6 @@ namespace VeterinaryContracts.StorageContracts
DrugViewModel? Insert(DrugBindingModel model);
DrugViewModel? Update(DrugBindingModel model);
DrugViewModel? Delete(DrugBindingModel model);
public bool SellDrugs(IDrugModel model, int count);
//public bool SellDrugs(IDrugModel model, int count);
}
}

View File

@ -107,40 +107,40 @@ namespace VeterinaryDatabaseImplement.Implements
}
return null;
}
public bool SellDrugs(IDrugModel model, int count)
{
if (model == null)
return false;
using var context = new VeterinaryDatabase();
using var transaction = context.Database.BeginTransaction();
//List<ShopDrug> lst = new List<ShopDrug>();
//foreach (var el in context.ShopDrugs.Where(x => x.DrugId == model.Id))
//{
int dif = count;
if (model.Count < dif)
dif = model.Count;
model.Count -= dif;
count -= dif;
if (el.Count == 0)
{
lst.Add(el);
}
if (count == 0)
break;
//}
if (count > 0)
{
transaction.Rollback();
return false;
}
// почистили лист
foreach (var el in lst)
{
context.ShopDrugs.Remove(el);
}
context.SaveChanges();
transaction.Commit();
return true;
}
//public bool SellDrugs(IDrugModel model, int count)
//{
// if (model == null)
// return false;
// using var context = new VeterinaryDatabase();
// using var transaction = context.Database.BeginTransaction();
// //List<ShopDrug> lst = new List<ShopDrug>();
// //foreach (var el in context.ShopDrugs.Where(x => x.DrugId == model.Id))
// //{
// int dif = count;
// if (model.Count < dif)
// dif = model.Count;
// model.Count -= dif;
// count -= dif;
// if (el.Count == 0)
// {
// lst.Add(el);
// }
// if (count == 0)
// break;
// //}
// if (count > 0)
// {
// transaction.Rollback();
// return false;
// }
// // почистили лист
// foreach (var el in lst)
// {
// context.ShopDrugs.Remove(el);
// }
// context.SaveChanges();
// transaction.Commit();
// return true;
//}
}
}