Example #1
0
        private void RemoveLegalPersonClientButton_OnClick(object sender, RoutedEventArgs e)
        {
            using (var repo = new LegalPersonClientRepository())
            {
                repo.RemoveClient(SelectedLegalPersonClient);
                repo.Save();
                repo.Update(SelectedLegalPersonClient);
            }

            LegalPersonClients.Remove(SelectedLegalPersonClient);
        }
Example #2
0
 private void LegalPersonsDataGrid_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (SelectedLegalPersonClient != null)
     {
         using (var repo = new LegalPersonClientRepository())
         {
             repo.Update(SelectedLegalPersonClient);
             repo.Save();
         }
     }
 }
Example #3
0
        private void TransferPhysicalPersonMoneyButton_OnClick(object sender, RoutedEventArgs e)
        {
            MoneyTransferWindow moneyTransferWindow = new MoneyTransferWindow();

            using (var physicalPersonClientRepo = new PhysicalPersonClientRepository())
                using (var legalPersonClientRepo = new LegalPersonClientRepository())
                {
                    PhysicalPersonClient client = (PhysicalPersonClient)PhysicalPersonsDataGrid.SelectedItem;
                    moneyTransferWindow.SenderAccountIdComboBox.ItemsSource       = physicalPersonClientRepo.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 (HimselfTransferException exception)
                        {
                            MessageBox.Show($"Произошла ошибка: {exception.Message}\n" +
                                            $"Перевод с клиента {accountFrom.ClientId} со счета {accountFrom.Id} клиенту {accountTo.ClientId} на счет {accountTo.Id}");
                        }
                        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;
                        }
                    }
                }
        }
Example #4
0
        private void AddNewLegalPersonClientButton_OnClick(object sender, RoutedEventArgs e)
        {
            var addingClientWindow = new AddingLegalPersonClientWindow();

            if (addingClientWindow.ShowDialog() == true)
            {
                using (var repo = new LegalPersonClientRepository())
                {
                    ClientType clientType = Convert.ToBoolean(addingClientWindow.IsVipCheckBox.IsChecked)
                        ? ClientType.Vip
                        : ClientType.Usual;

                    var client = new LegalPersonClient(addingClientWindow.CompanyNameTextBox.Text, clientType);
                    LegalPersonClients.Add(client);
                    repo.AddClient(client);
                    repo.Save();
                }
            }
        }