public void AddSaleRecall(SaleRecall saleRecall) { using (SalesDB db = new SalesDB()) { db.SalesRecalls.Add(saleRecall); db.SaveChanges(); } }
private async void ExecuteAddRecallAsync() { if (NewRecall.PriceTotalAfterDiscount == null) { return; } var saleCategoryQty = _saleCategoryServ.GetCategoryQty(ID, _newRecall.CategoryID); if (_newRecall.Qty > saleCategoryQty) { MessageDialogResult result = await _currentWindow.ShowMessageAsync("خطأ", "هذه الكمية اكبر من الكمية الخاصة بالفاتورة", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }); return; } var recallQty = _saleRecallServ.GetRecallCategoryQty(ID, _newRecall.CategoryID); if (_newRecall.Qty + recallQty > saleCategoryQty) { MessageDialogResult result = await _currentWindow.ShowMessageAsync("خطأ", " هذه الكمية والمرتجعات اكبر من الكمية الخاصة بالفاتورة", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }); return; } DateTime dt = DateTime.Now; SaleRecall saleRecall = new SaleRecall { CategoryID = _newRecall.CategoryID, Cost = _newRecall.Cost, CostTotal = _newRecall.CostTotal, Date = _newRecall.Date, PriceAfterDiscount = _newRecall.PriceAfterDiscount, PriceTotalAfterDiscount = _newRecall.PriceTotalAfterDiscount, RegistrationDate = dt, Qty = _newRecall.Qty, SaleID = _newRecall.SaleID }; _saleRecallServ.AddSaleRecall(saleRecall); Category cat = _categoryServ.GetCategory(_newRecall.CategoryID); if (cat.Qty + _newRecall.Qty != 0) { cat.Cost = (_newRecall.CostTotal + (cat.Cost * cat.Qty)) / (cat.Qty + _newRecall.Qty); } cat.Qty = cat.Qty + _newRecall.Qty; _categoryServ.UpdateCategory(cat); ClientAccount _account = new ClientAccount { ClientID = _selectedSale.ClientID, Date = _newRecall.Date, RegistrationDate = dt, Statement = "مرتجعات فاتورة مبيعات رقم " + ID, Credit = _newRecall.PriceTotalAfterDiscount, Debit = 0 }; _clientAccountServ.AddAccount(_account); Categories = new ObservableCollection <SaleRecallVM>(_saleRecallServ.GetSaleCategoriesVM(ID)); SaleRecalls = new ObservableCollection <SaleRecallVM>(_saleRecallServ.GetSaleRecallsVM(ID)); await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }); }