поручитель готова бд

This commit is contained in:
antoc0der 2024-04-25 22:59:36 +04:00
parent cf6b3dd18a
commit fc40e380ee
4 changed files with 18 additions and 41 deletions

View File

@ -113,9 +113,9 @@ namespace VeterinaryBusinessLogic.BusinessLogic
throw new InvalidOperationException("Лекарство с таким названием уже есть");
}
}
//public bool MakeSell(IDrugModel drug, int count)
//{
// return _drugStorage.SellDrugs(drug, count);
//}
public bool MakeSell(DrugBindingModel drug, int count)
{
return _drugStorage.SellDrugs(drug, count);
}
}
}

View File

@ -17,6 +17,6 @@ namespace VeterinaryContracts.BusinessLogicContracts
bool Create(DrugBindingModel model);
bool Update(DrugBindingModel model);
bool Delete(DrugBindingModel model);
//bool MakeSell(IDrugModel drug, int count);
bool MakeSell(DrugBindingModel model, int count);
}
}

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(DrugBindingModel model, int count);
}
}

View File

@ -107,40 +107,17 @@ 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(DrugBindingModel model, int count)
{
if (model == null)
return false;
using var context = new VeterinaryDatabase();
if (model.Count < count)
return false;
else
model.Count -= count;
context.SaveChanges();
return true;
}
}
}