/// <summary> /// Adds bank account to the container /// </summary> /// <param name="account">Bank account</param> private void Add(DalBankAccount account) { using (var db = new AccountsContext()) { db.Accounts.Add(account); db.SaveChanges(); } }
public void Create(AccountDTO account) { using (var context = new AccountsContext()) { context.Accounts.Add(account); context.SaveChanges(); } }
/// <summary> /// Closes bank account /// </summary> /// <param name="accountID">Bank account ID</param> private void Close(string accountID) { using (var db = new AccountsContext()) { var closedAccount = db.Accounts.Where(p => p.BankAccountNumber == accountID).FirstOrDefault(); if (closedAccount != null) { closedAccount.IsClosed = true; db.Entry(closedAccount).State = EntityState.Modified; db.SaveChanges(); } } }
public void SaveAccount(DalBankAccount account) { using (var db = new AccountsContext()) { var savedAccount = db.Accounts.Where(p => p.BankAccountNumber == account.BankAccountNumber).FirstOrDefault(); if (savedAccount != null) { savedAccount.BonusScores = account.BonusScores; savedAccount.InvoiceAmount = account.InvoiceAmount; savedAccount.IsClosed = account.IsClosed; db.Entry(savedAccount).State = EntityState.Modified; db.SaveChanges(); } } }
public void Withdraw(int accountID, decimal amount) { using (var context = new AccountsContext()) { try { var account = (from a in context.Accounts where a.AccountID == accountID select a).Single(); account.Balance -= amount; context.SaveChanges(); } catch (InvalidOperationException) { // Ignore } } }
public void Remove(int accountID) { using (var context = new AccountsContext()) { try { var account = (from a in context.Accounts where a.AccountID == accountID select a).Single(); context.Accounts.Remove(account); context.SaveChanges(); } catch (InvalidOperationException) { // Ignore } } }