проверка
This commit is contained in:
parent
580e7adc0c
commit
531aa03753
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user