diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs index e73eb3b..9b70c60 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs @@ -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); + } } } diff --git a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IDrugLogic.cs b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IDrugLogic.cs index 6b15655..60b6fc4 100644 --- a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IDrugLogic.cs +++ b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IDrugLogic.cs @@ -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); } } diff --git a/VeterinaryView/VeterinaryContracts/StorageContracts/IDrugStorage.cs b/VeterinaryView/VeterinaryContracts/StorageContracts/IDrugStorage.cs index e63b93f..58fe47e 100644 --- a/VeterinaryView/VeterinaryContracts/StorageContracts/IDrugStorage.cs +++ b/VeterinaryView/VeterinaryContracts/StorageContracts/IDrugStorage.cs @@ -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); } } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs index e782452..9300cdf 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs @@ -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 lst = new List(); - // //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; + } } }