Esempio n. 1
0
        public override void Transaction()
        {
            try
            {
                if (Accounts == null || Sender == null || Accounts.Count == 0)
                {
                    throw new TransactionFailureException("Неверно переданы счета или отсутствует счет отправитель!");
                }

                TransactionViewModel transactionViewModel = new TransactionViewModel(Accounts, Sender.AmountAvailable);
                DialogTransaction    dialogTransaction    = new DialogTransaction(transactionViewModel);

                if (transactionViewModel == null || dialogTransaction == null)
                {
                    throw new TransactionFailureException("Ошибка при создании диалога транзакции!");
                }

                if (dialogTransaction.ShowDialog() == true)
                {
                    Reciever = transactionViewModel.SelectedAccount;

                    Sender.Withdraw(transactionViewModel.Amount, Reciever);
                    Reciever.Put(transactionViewModel.Amount);
                }
            }
            catch (TransactionFailureException ex)
            {
                MessageBox.Show(ex.Info);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public override void Transaction()
        {
            try
            {
                if (Sender.BadHistory)
                {
                    throw new TransactionFailureException($"Клиент {Sender.Name} заблокирован!");
                }

                if (Reciever.BadHistory)
                {
                    throw new TransactionFailureException($"Счет {Reciever.Name} заблокирован!");
                }

                string label = IsWithdraw ? "Снятие со счета" : "Пополнение счета";

                DialogViewModel dialogVM     = new DialogViewModel(label, Reciever.AmountAvailable, IsWithdraw);
                DialogWindow    dialogWindow = new DialogWindow(dialogVM, label);

                if (dialogWindow.ShowDialog() == true)
                {
                    if (IsWithdraw)
                    {
                        Sender.Put(dialogVM.Amount);
                        Reciever.Withdraw(dialogVM.Amount);
                    }
                    else
                    {
                        Sender.Withdraw(dialogVM.Amount);
                        Reciever.Put(dialogVM.Amount);
                    }
                }
            }
            catch (TransactionFailureException ex)
            {
                MessageBox.Show(ex.Info);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }