Exemplo n.º 1
0
 public void Process(IEnumerable <Transaction> transactions, FinanceDb db)
 {
     foreach (var trx in transactions)
     {
         Process(trx);
         db.Transactions.Add(trx);
     }
     db.SaveChanges();
 }
Exemplo n.º 2
0
        private static void AddOperation(string accountNumber, decimal amount, string description)
        {
            using (var financeDb = new FinanceDb())
            {
                var account = financeDb.Accounts.Single(a => a.Number == accountNumber);
                account.Balance += amount;

                if (account.Balance < account.MinimalBalance)
                {
                    throw new InvalidOperationException("Account balance insufficient.");
                }

                financeDb.Operations.Add(new Operation
                {
                    Account     = account,
                    Amount      = amount,
                    Description = description,
                    Time        = DateTime.Now
                });
                financeDb.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private static void CreateDatabases()
        {
            string dataDirectory = Path.Combine(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]));

            AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory);

            using (var financeDb = new FinanceDb())
            {
                if (!financeDb.Database.CreateIfNotExists())
                {
                    financeDb.Operations.RemoveRange(financeDb.Operations);
                    financeDb.Accounts.RemoveRange(financeDb.Accounts);
                }

                financeDb.Accounts.Add(new Account
                {
                    Name   = "IT Department",
                    Number = ItDepartment
                });

                financeDb.Accounts.Add(new Account
                {
                    Name    = "HR Department",
                    Number  = HrDepartment,
                    Balance = 500000
                });
                financeDb.SaveChanges();
            }

            using (var orderDb = new OrderDb())
            {
                if (!orderDb.Database.CreateIfNotExists())
                {
                    orderDb.Orders.RemoveRange(orderDb.Orders);
                    orderDb.SaveChanges();
                }
            }
        }