Ejemplo n.º 1
0
 public void AddVendor(string vendorName)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Vendors.Add(new Data.Models.Vendor {
             Name = vendorName
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void AddAccount(string name, string type, double balance)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Accounts.Add(new Data.Models.Account {
             Name = name, Balance = balance, Type = GetType(type)
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void AddTransaction(TransactionModel model)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Transactions.Add(new Data.Models.Transaction {
             Amount = model.Amount, Description = model.Description, VendorId = model.VendorId, TransactionDate = DateTime.UtcNow, CofferId = model.CofferId, AccountId = model.AccountId
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public void AddIncome(double amount, string description, string source, int accountId)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Income.Add(new Data.Models.Income {
             Amount = amount, Description = description, AccountId = accountId, TransactionDate = DateTime.UtcNow, Source = source
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public void AddExpense(string name, string description)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Expenses.Add(new Data.Models.Expense {
             Name = name, Description = description
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void UpdateAccountBalance(int accountId, double amount)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         var account = db.Accounts.Where(a => a.Id == accountId).FirstOrDefault();
         if (account != null)
         {
             account.Balance = account.Balance - amount;
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 7
0
 public void ApplySpendingToCoffer(int cofferId, double amount)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         var coffer = db.Coffers.Where(x => x.Id == cofferId).FirstOrDefault();
         if (coffer != null)
         {
             coffer.AmountSpent = coffer.AmountSpent + amount;
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 8
0
 private void SetAmountFunded(int cofferId, double amountFunded)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         var cof = db.Coffers.Where(x => x.Id == cofferId).FirstOrDefault();
         if (cof != null)
         {
             cof.AmountFunded = amountFunded;
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 9
0
        public void TransferMoney(int transferFrom, int transferTo, double amount)
        {
            using (TreasuryContext db = new TreasuryContext())
            {
                var accountFrom = db.Accounts.Where(a => a.Id == transferFrom).FirstOrDefault();
                accountFrom.Balance = accountFrom.Balance - amount;

                var accountTo = db.Accounts.Where(a => a.Id == transferTo).FirstOrDefault();
                accountTo.Balance = accountTo.Balance + amount;


                db.SaveChanges();
            }
        }
Ejemplo n.º 10
0
 public void AddCoffer(decimal amount, int month, string name, int order, int budgetId, bool necessary)
 {
     try
     {
         using (TreasuryContext db = new TreasuryContext())
         {
             db.Coffers.Add(new Data.Models.Coffer {
                 Amount = double.Parse(amount.ToString()), Month = month, Name = name, Order = order, BudgetId = budgetId, Necessary = necessary
             });
             db.SaveChanges();
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 11
0
 public void SetUpBudgets(decimal amount, string name, int order, bool necessary, string type, string month, int expenseId, string description)
 {
     try
     {
         using (TreasuryContext db = new TreasuryContext())
         {
             db.Budgets.Add(new Data.Models.Budget {
                 Amount = double.Parse(amount.ToString()), Month = GetMonth(GetMonthInt(month)), Name = name, Order = order, ExpenseId = expenseId, Description = description, Necessary = necessary
             });
             db.SaveChanges();
             var budgetId = db.Budgets.Where(x => x.ExpenseId == expenseId && x.Name == name).FirstOrDefault().Id;
             SetUpMonthlyCoffers(amount, name, order, type, month, budgetId, necessary);
         }
     }
     catch
     {
     }
 }