private void saveNpa_E(object obj) { if (NewPaymentAdvice != null) { NewPaymentAdvice.Date = DateTime.Now; NewPaymentAdvice.IssuedBy = CurrentUser.FirstName; NewPaymentAdvice.CompanyId = SelectedCompany.CompanyId; db.PaymentAdvices.Add(NewPaymentAdvice); db.SaveChanges(); ClearBoxes.Execute("CPA"); PaymentAdvices = new ObservableCollection <PaymentAdvice>(db.PaymentAdvices); // show messagebox to alert success; MessageBox.Show("Payment Advice Added successfully", "Success !! ", MessageBoxButton.OK, MessageBoxImage.Information); return; } MessageBox.Show("Failed to Add Payment Advice", "Failure !! ", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Execute Method for saving a new expense /// </summary> /// <param name="obj"></param> /// <returns>whether the binder should be enabled</returns> private void saveNe_E(object obj) { //Check if the Expense has already been added var Expense = db.Expenses.Where(i => i.Amount == NewExpense.Amount && i.PaymentVoucherNumber == NewExpense.PaymentVoucherNumber && i.Description == NewExpense.Description).FirstOrDefault(); if (Expense != null) { if (MessageBox.Show("An Expense with the same details exist do you want to add it anyway", "Duplicate", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No) { return; } } bool IsExpenseValid = ValidateNewExpense(NewExpense); if (IsExpenseValid) { //Associate the Expense to the current Company NewExpense.CompanyId = SelectedCompany.CompanyId; NewExpense.Date = DateTime.Now; // add the new Expense db.Expenses.Add(NewExpense); db.SaveChanges(); RefreshExpenses(); ClearBoxes.Execute("E"); // show messagebox to alert success; MessageBox.Show("Expense Added Successfully", "Success !! ", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (!IsExpenseValid) { return; } // show Message Box to alert failure }