public void AddSupplyRecall(SupplyRecall saleRecall) { using (SalesDB db = new SalesDB()) { db.SuppliesRecalls.Add(saleRecall); db.SaveChanges(); } }
private async void ExecuteAddRecallAsync() { if (NewRecall.Qty == null || NewRecall.Cost == null) { return; } var mySettings = new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }; var supplyCategoryQty = _supplyCategoryServ.GetCategoryQty(ID, _newRecall.CategoryID); if (_newRecall.Qty > supplyCategoryQty) { MessageDialogResult result = await _currentWindow.ShowMessageAsync("خطأ", "هذه الكمية اكبر من الكمية الخاصة بالفاتورة", MessageDialogStyle.Affirmative, mySettings); return; } var recallQty = _supplyRecallServ.GetRecallCategoryQty(ID, _newRecall.CategoryID); if (_newRecall.Qty + recallQty > supplyCategoryQty) { MessageDialogResult result = await _currentWindow.ShowMessageAsync("خطأ", " هذه الكمية والمرتجعات اكبر من الكمية الخاصة بالفاتورة", MessageDialogStyle.Affirmative, mySettings); return; } DateTime dt = DateTime.Now; SupplyRecall supplyRecall = new SupplyRecall { CategoryID = _newRecall.CategoryID, Cost = _newRecall.Cost, CostTotal = _newRecall.CostTotal, Date = _newRecall.Date, RegistrationDate = dt, Qty = _newRecall.Qty, SupplyID = _newRecall.SupplyID }; _supplyRecallServ.AddSupplyRecall(supplyRecall); Category cat = _categoryServ.GetCategory(_newRecall.CategoryID); if (cat.Qty - _newRecall.Qty != 0) { cat.Cost = ((cat.Cost * cat.Qty) - _newRecall.CostTotal) / (cat.Qty - _newRecall.Qty); } cat.Qty = cat.Qty - _newRecall.Qty; _categoryServ.UpdateCategory(cat); ClientAccount _account = new ClientAccount { ClientID = _selectedSupply.ClientID, Date = _newRecall.Date, RegistrationDate = dt, Statement = "مرتجعات فاتورة مشتريات رقم " + ID, Credit = 0, Debit = _newRecall.CostTotal }; _clientAccountServ.AddAccount(_account); Categories = new ObservableCollection <SupplyRecallVM>(_supplyRecallServ.GetSupplyCategoriesVM(ID)); SupplyRecalls = new ObservableCollection <SupplyRecallVM>(_supplyRecallServ.GetSupplyRecallsVM(ID)); await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }); }