示例#1
0
 public IEnumerable <Data.Models.Vendor> GetVendors()
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         return(db.Vendors.Select(x => x).ToList());
     }
 }
示例#2
0
 public IEnumerable <Expense> GetExpenses()
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         return(db.Expenses.Select(x => x).ToList());
     }
 }
示例#3
0
 public IEnumerable <Coffer> GetCoffers()
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         return(db.Coffers.Select(x => x).ToList());
     }
 }
示例#4
0
 public IEnumerable <Account> GetAccounts()
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         return(db.Accounts.Select(x => x).ToList());
     }
 }
示例#5
0
 public IEnumerable <Account> GetAccountsForTransactions()
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         return(db.Accounts.Where(x => x.Type == AccountTypes.Cash || x.Type == AccountTypes.Checking || x.Type == AccountTypes.Credit).Select(x => x).ToList());
     }
 }
示例#6
0
 public void AddVendor(string vendorName)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         db.Vendors.Add(new Data.Models.Vendor {
             Name = vendorName
         });
         db.SaveChanges();
     }
 }
示例#7
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();
     }
 }
示例#8
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();
     }
 }
示例#9
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();
     }
 }
示例#10
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();
     }
 }
示例#11
0
 public IEnumerable <Coffer> GetCoffersForFunding(int month)
 {
     using (TreasuryContext db = new TreasuryContext())
     {
         List <Coffer> cofferList = new List <Coffer>();
         cofferList.AddRange(db.Coffers.Where(x => x.AmountFunded < x.Amount && x.Month == month && x.Necessary).Select(x => x).OrderBy(x => x.Order));
         cofferList.AddRange(db.Coffers.Where(x => x.AmountFunded < x.Amount && x.Month == month && !x.Necessary).Select(x => x).OrderBy(x => x.Order));
         cofferList.AddRange(db.Coffers.Where(x => x.AmountFunded <x.Amount && x.Month> month && x.Month < month + 5 && x.Necessary).Select(x => x).OrderBy(x => x.Month).ThenBy(x => x.Order));
         cofferList.AddRange(db.Coffers.Where(x => x.AmountFunded <x.Amount && x.Month> month && x.Month < month + 5 && !x.Necessary).Select(x => x).OrderBy(x => x.Month).ThenBy(x => x.Order));
         return(cofferList);
     }
 }
示例#12
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();
         }
     }
 }
示例#13
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();
         }
     }
 }
示例#14
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();
         }
     }
 }
示例#15
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();
            }
        }
示例#16
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
     {
     }
 }
示例#17
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
     {
     }
 }