Exemplo n.º 1
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            var bank = BanksListBox.SelectedItem as Bank;

            if (bank == null)
            {
                MessageBox.Show("You must select Bank from the List", "Can't Edit", MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
                return;
            }
            var oldBankName = bank.BankName;
            var newBankName = Interaction.InputBox("Edit Bank Name", "Edit Bank", oldBankName);

            if (IsBankExist(newBankName))
            {
                MessageBox.Show("Bank name already exist", "Can't Edit", MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
                return;
            }

            if (IsOldNameIsNotSimilarToNewName(oldBankName, newBankName) &&
                IsNewNameIsNotEmpty(newBankName))
            {
                Bank bankToEdit = new Bank()
                {
                    Id = bank.Id, BankName = newBankName
                };
                _bankRepository.EditBank(bankToEdit);

                MessageBox.Show(_bankRepository.StatusMessage);
                LoadBanksToListView();
            }
        }