private void SaveAccountCommand_E(object obj) { try { var account = db.CompanyAccountDetails.Where(i => i.AccountName == NewCompanyAccount.AccountName && i.AccountNumber == NewCompanyAccount.AccountNumber && i.BankBranch == NewCompanyAccount.BankBranch).FirstOrDefault(); bool IsAccountValid = ValidateAccount(NewCompanyAccount); if (account == null && IsAccountValid) { NewCompanyAccount.CompanyId = FocusedCompany.CompanyId; focusedCompany.AccountDetails.Add(NewCompanyAccount); db.CompanyAccountDetails.Add(NewCompanyAccount); db.SaveChanges(); NewCompanyAccount = new CompanyAccountDetail(); refreshCs_E(null); SetFocusedCompany(); FocusedCompany.AccountDetails = focusedCompany.AccountDetails; // show messagebox to alert success; MessageBox.Show("Account Detail Added Successfully", "Success !! ", MessageBoxButton.OK, MessageBoxImage.Information); return; } else if (account != null) { Error = this["Duplicate"]; } if (!IsAccountValid) { return; } } catch { // show Message Box to alert failure MessageBox.Show("Failed to add Account detail", "Failure !! ", MessageBoxButton.OK, MessageBoxImage.Error); } }
public CompanyPageViewModel() { try { NewCompany = new Company(); NewOperation = new Operation(); NewCompanyAccount = new CompanyAccountDetail(); BrowseCommand = new RelayCommand(Browse_E, Browse_C); SaveCompanyCommand = new RelayCommand(SaveCompany_E, SaveCompany_C); SaveOperationCommand = new RelayCommand(SaveOperation_E, SaveOperation_C); SaveAccountCommand = new RelayCommand(SaveAccountCommand_E, SaveAccountCommand_C); DeleteCompanyCommand = new RelayCommand(DeleteCompany_E, General_C); DeleteOperationCommand = new RelayCommand(DeleteOperation_E, DeleteOperation_C); GeneralCommand = new RelayCommand(null, General_C); DeleteAccDetailCommand = new RelayCommand(DeleteAccDetail_E, General_C); ClearBoxes = new RelayCommand(Clear_E); AllCompanies = new ObservableCollection <Company>(db.Companies); currentContext = SynchronizationContext.Current; SearchCompanyCommand = new RelayCommand(_ => { SearchCompany(); }); } catch { } }
private bool ValidateAccount(CompanyAccountDetail newCompanyAccount) { if (string.IsNullOrWhiteSpace(newCompanyAccount.AccountName) || string.IsNullOrEmpty(newCompanyAccount.AccountNumber) || string.IsNullOrEmpty(newCompanyAccount.BankName) || string.IsNullOrEmpty(newCompanyAccount.BankBranch) ) { Error = this["ProvideValues"]; return(false); } Error = null; return(true); }
private void Clear_E(object parameter) { NewOperation = new Operation(); NewCompanyAccount = new CompanyAccountDetail(); NewCompany = new Company(); }