public IEnumerable <Data.Models.Vendor> GetVendors() { using (TreasuryContext db = new TreasuryContext()) { return(db.Vendors.Select(x => x).ToList()); } }
public IEnumerable <Expense> GetExpenses() { using (TreasuryContext db = new TreasuryContext()) { return(db.Expenses.Select(x => x).ToList()); } }
public IEnumerable <Coffer> GetCoffers() { using (TreasuryContext db = new TreasuryContext()) { return(db.Coffers.Select(x => x).ToList()); } }
public IEnumerable <Account> GetAccounts() { using (TreasuryContext db = new TreasuryContext()) { return(db.Accounts.Select(x => x).ToList()); } }
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()); } }
public void AddVendor(string vendorName) { using (TreasuryContext db = new TreasuryContext()) { db.Vendors.Add(new Data.Models.Vendor { Name = vendorName }); db.SaveChanges(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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); } }
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(); } } }
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(); } } }
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(); } } }
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(); } }
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 { } }
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 { } }