private void Delete_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (InfoLB.SelectedIndex < 0)
            {
                new MyMessageBox("Select any Item first...").ShowDialog();
                return;
            }

            switch (_nameOfData)
            {
            case nameof(Account):
                var account = InfoLB.SelectedItem as Account;
                if (account.IsDeleted == true)
                {
                    new MyMessageBox($"Account with id={account.Id} has already been deleted!").ShowDialog();
                }
                else
                {
                    using (var repo = new AccountRepository())
                        repo.Delete(account);
                    new MyMessageBox($"Account with id={account.Id} deleted!").ShowDialog();
                }
                break;

            case nameof(Client):
                var client = InfoLB.SelectedItem as Client;
                if (client.IsDeleted == true)
                {
                    new MyMessageBox($"Client with id={client.Id} has already been deleted!").ShowDialog();
                }
                else
                {
                    using (var repo = new ClientRepository())
                        repo.Delete(client);
                    new MyMessageBox($"Client with id={client.Id} deleted!").ShowDialog();
                }
                break;

            case nameof(Deposit):
                var deposit = InfoLB.SelectedItem as Deposit;
                if (deposit.IsDeleted == true)
                {
                    new MyMessageBox($"Deposit with id={deposit.Id} has already been deleted!").ShowDialog();
                }
                else
                {
                    using (var repo = new DepositRepository())
                        repo.Delete(deposit);
                    new MyMessageBox($"Deposit with id={deposit.Id} deleted!").ShowDialog();
                }
                break;

            case nameof(Transaction):
                new MyMessageBox("Transactions can't be deleted...").ShowDialog();
                break;

            default:
                return;
            }
        }
Example #2
0
        public void DeleteDeposit()
        {
            repo.includes.Add("Booking");
            IEnumerable <Deposit> listDeposits = repo.GetList(p => p.HomeId == (int)ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie").ClientId);

            foreach (var cur in listDeposits)
            {
                int savedBookingId = (int)cur.Booking.Id;
                int savedId        = cur.Id;
                repo.Delete(cur);
                repo.Save();
                Assert.IsNotNull(repo.GetUniq <Booking>(p => p.Id == savedBookingId));
                Assert.IsNull(repo.GetUniq(p => p.Id == savedId));
            }
        }