Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     using (BankAccountContext context = new BankAccountContext())
     {
         while (TryWithdrawFromAccount(context))
         {
             ;
         }
     }
 }
Ejemplo n.º 2
0
        private static void WithdrawFromAccount(BankAccountContext context, BankAccount bankAccount)
        {
            Console.WriteLine($"{bankAccount.Owner} has {bankAccount.Balance}$");

            Console.Write("How much you want to withdraw? ");
            bankAccount.Withdraw(decimal.Parse(Console.ReadLine()));

            if (ConfirmWithdraw(bankAccount) == "y")
            {
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private static bool TryWithdrawFromAccount(BankAccountContext context)
        {
            string      owner;
            BankAccount bankAccount;

            Console.Write("Type owner (or 'q' to exit): ");
            owner = Console.ReadLine();
            if (owner == "q")
            {
                return(false);
            }
            bankAccount = context.BanckAccounts.FirstOrDefault(ba => ba.Owner == owner);
            if (bankAccount != null)
            {
                WithdrawFromAccount(context, bankAccount);
            }
            return(true);
        }
Ejemplo n.º 4
0
        private static bool TryWithdrawFromAccount(BankAccountContext context)
        {
            string      owner;
            BankAccount bankAccount;

            Console.Write("Type owner (or 'q' to exit): ");
            owner = Console.ReadLine();
            if (owner == "q")
            {
                return(false);
            }
            bankAccount = TryGetBankAccountByOwner(context, owner);
            if (bankAccount != null)
            {
                WithdrawFromAccount(context, bankAccount);
            }
            return(true);
        }
Ejemplo n.º 5
0
 private static void UpdateBankAccount(BankAccountContext context, BankAccount bankAccount)
 {
     /*** Attach the modified object to the context ***/
     context.Entry(bankAccount).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
Ejemplo n.º 6
0
 private static BankAccount TryGetBankAccountByOwner(BankAccountContext context, string owner)
 {
     /*** Load detached object ***/
     return(context.BanckAccounts.AsNoTracking().FirstOrDefault(ba => ba.Owner == owner));
 }