private void ShowAllLegalPersonAccountsMenuItem_OnClick(object sender, RoutedEventArgs e) { if (SelectedLegalPersonClient == null) { MessageBox.Show("Выберите клиента корректным образом!"); return; } var accountsWindow = new AccountsWindow(); accountsWindow.Title = $"Все счета клиента: {SelectedLegalPersonClient.DisplayName}"; using (var repo = new LegalPersonClientRepository()) { accountsWindow.AccountsDataGrid.DataContext = repo.GetAllClientAccounts(SelectedLegalPersonClient.Id); accountsWindow.ShowDialog(); } }
private void TransferLegalPersonMoneyButton_OnClick(object sender, RoutedEventArgs e) { MoneyTransferWindow moneyTransferWindow = new MoneyTransferWindow(); using (var physicalPersonClientRepo = new PhysicalPersonClientRepository()) using (var legalPersonClientRepo = new LegalPersonClientRepository()) { LegalPersonClient client = (LegalPersonClient)LegalPersonsDataGrid.SelectedItem; moneyTransferWindow.SenderAccountIdComboBox.ItemsSource = legalPersonClientRepo.GetAllClientAccounts(client.Id); moneyTransferWindow.SenderAccountIdComboBox.DisplayMemberPath = "Id"; var allClients = new List <IClient>(); allClients.AddRange(physicalPersonClientRepo.GetClients()); allClients.AddRange(legalPersonClientRepo.GetClients()); moneyTransferWindow.RecipientClientNamesComboBox.ItemsSource = allClients; moneyTransferWindow.RecipientClientNamesComboBox.DisplayMemberPath = "DisplayName"; if (moneyTransferWindow.ShowDialog() == true) { IAccount accountFrom = (IAccount)moneyTransferWindow.SenderAccountIdComboBox.SelectedValue; IAccount accountTo = (IAccount)moneyTransferWindow.RecipientAccountsIdComboBox.SelectedValue; try { AccountManager accountManager = new AccountManager(); accountManager.TransferMoney(accountFrom, accountTo, moneyTransferWindow.Amount); physicalPersonClientRepo.Save(); legalPersonClientRepo.Save(); } catch (InsufficientAmountsException exception) { MessageBox.Show($"Произошла ошибка: {exception.Message}\nСуммма денег на счету: {exception.Amount}"); } catch (CurrencyMismatchException exception) { MessageBox.Show($"Произошла ошибка: {exception.Message}\n" + $"Валюта счета отправителя: {exception.Sender}, валюта счета получателя: {exception.Recipient}"); } catch (Exception exception) { MessageBox.Show($"Произошла ошибка: {exception.Message} Выполняем завершение программы."); throw; } } } }