Exemplo n.º 1
0
        public static Account CreateAccount(string emailAddress, AccountTypes typeOfAccount, decimal amount)
        {
            if (string.IsNullOrEmpty(emailAddress))
            {
                throw new ArgumentNullException("Email Addree cannot be empty. ");
            }
            if (amount < 0.0M)
            {
                throw new ArgumentException("Amount cannot be less thank zero");
            }
            var accountType = Enum.GetName(typeof(AccountTypes), typeOfAccount);

            if (string.IsNullOrEmpty(accountType))
            {
                throw new ArgumentException("Invalid account type. ");
            }
            var account = new Account
            {
                EmailAddress  = emailAddress,
                TypeOfAccount = (AccountTypes)typeOfAccount,
                CreatedDate   = DateTime.Now
            };

            account.Deposit(amount);
            //accounts.Add(account);
            db.Accounts.Add(account);
            db.SaveChanges();
            return(account);
        }
Exemplo n.º 2
0
        public static Customer CreateCustomer(string name, string emailAddress)
        {
            var customer = new Customer
            {
                CustomerName  = name,
                CustomerEmail = emailAddress
            };

            db.Customers.Add(customer);
            db.SaveChanges();
            return(customer);
        }
Exemplo n.º 3
0
 public static void CreateAccount(Account account)
 {
     using (var db = new BankModel())
     {
         db.Accounts.Add(account);
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public static void Deposit(int accountNumber, double amount)
 {
     using (var db = new BankModel())
     {
         var account = db.Accounts.Where(a => a.AccountNumber == accountNumber).First();
         var original = account;
         account.Deposit(amount);
         db.Entry(original).CurrentValues.SetValues(account);
         db.SaveChanges();
     }
 }
Exemplo n.º 5
0
 //private static List<Account> accounts = new List<Account>();
 public static Account CreateAccount(string name, int ssn)
 {
     using (var db = new BankModel())
     {
         var account = new Account(name);
         account.SSN = ssn;
         //accounts.Add(account);
         db.Accounts.Add(account);
         db.SaveChanges();
         return account;
     }
 }
Exemplo n.º 6
0
 public static decimal Deposit(int accountNumber, decimal amount )
 {
     using (var db = new BankModel())
     {
         var account = db.Accounts.Where(a => a.AccountNumber == accountNumber).First();
         var original = account;
         account.Deposit(amount);
         db.Entry(original).CurrentValues.SetValues(account);
         var transactionSuccess = CreateTransaction(DateTime.Now, "Deposit", amount, accountNumber, TransactionType.Credit);
         if (transactionSuccess)
         {
             db.SaveChanges();
         }
         return account.Balance;
     }
 }
Exemplo n.º 7
0
 public static Account CreateAccount(string name, int ssn, decimal amount, AccountType accountType, string emailAddress)
 {
     //var account = CreateAccount(name);
     //account.Deposit(amount);
     using (var db = new BankModel())
     {
         var account = new Account(name, amount);
         account.SSN = ssn;
         account.TypeOfAccount = accountType;
         account.EmailAddress = emailAddress;
         //accounts.Add(account);
         db.Accounts.Add(account);
         db.SaveChanges();
         return account;
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a bank account
 /// </summary>
 /// <param name="name">Name of the account holder</param>
 /// <param name="ssn">ssn</param>
 /// <param name="balance">initial balance to be deposited</param>
 /// <returns>Account number</returns>
 public static Account CreateAccount(string name, int ssn, double balance)
 {
     using (var db = new BankModel())
     {
         Account account = new Account(name);
         account.SSN = ssn;
         account.AccountType = TypeOfAccount.Checking;
         if (balance > 0)
         {
             account.Deposit(balance);
         }
         accounts.Add(account);
         db.Accounts.Add(account);
         db.SaveChanges();
         return account;
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a bank account
 /// </summary>
 /// <param name="name">Name of the account holder</param>
 /// <param name="ssn">ssn</param>
 /// <param name="balance">initial balance to be deposited</param>
 /// <returns>Account number</returns>
 public static Account CreateAccount(string name, int ssn, double balance)
 {
     using (var db = new BankModel())
     {
         Account account = new Account(name);
         account.SSN         = ssn;
         account.AccountType = TypeOfAccount.Checking;
         if (balance > 0)
         {
             account.Deposit(balance);
         }
         accounts.Add(account);
         db.Accounts.Add(account);
         db.SaveChanges();
         return(account);
     }
 }
Exemplo n.º 10
0
 public static void UpdateAccount(Account account)
 {
     using (var db = new BankModel())
     {
         var foundAccount = db.Accounts.Where(a => a.AccountNumber == account.AccountNumber).First();
         account.Balance = foundAccount.Balance;
         db.Entry(foundAccount).CurrentValues.SetValues(account);
         db.SaveChanges();
     }
 }
Exemplo n.º 11
0
 private static bool CreateTransaction(DateTime transactionDate, 
     string description, decimal amount, int accountnumber, 
     TransactionType transactionType)
 {
     try
     {
         using (var db = new BankModel())
         {
             var transaction =
                 new Transaction
                 {
                     AccountNumber = accountnumber,
                     TransactionDate = transactionDate,
                     Description = description,
                     Debit = (transactionType == TransactionType.Debit)
                                     ? amount : 0.0M,
                     Credit = (transactionType == TransactionType.Credit)
                                     ? amount : 0.0M
                 };
             db.Transactions.Add(transaction);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }