public ActionResult DeleteConfirmed(int id) { BudgetItemCategory budgetItemCategory = db.BudgetItemCategories.Find(id); var budgetId = budgetItemCategory.BudgetId; db.BudgetItemCategories.Remove(budgetItemCategory); db.SaveChanges(); return(RedirectToAction("Details", "Budgets", new { id = budgetId })); }
public ActionResult Edit([Bind(Include = "Id,Name, BudgetId")] BudgetItemCategory budgetItemCategory) { TempData["BudgetId"] = budgetItemCategory.BudgetId; if (ModelState.IsValid) { db.Entry(budgetItemCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", "Budgets", new { id = budgetItemCategory.BudgetId })); } return(RedirectToAction("Details", "Budgets", new { id = budgetItemCategory.BudgetId, editBiId = budgetItemCategory.Id })); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItemCategory budgetItemCategory = db.BudgetItemCategories.Include(b => b.BudgetItems).FirstOrDefault(b => b.Id == id); if (budgetItemCategory == null) { return(HttpNotFound()); } return(View(budgetItemCategory)); }
public ActionResult CreateFromUploads([Bind(Include = "Id, Name")] BudgetItemCategory budgetItemCategory) { var budgetId = budgetHelper.GetBudgetId(); if (ModelState.IsValid && budgetId != null) { budgetItemCategory.BudgetId = budgetId; db.BudgetItemCategories.Add(budgetItemCategory); db.SaveChanges(); TempData["Message"] = "Category Created"; return(RedirectToAction("NextTransaction", "UploadedTransactions")); } TempData["Message"] = "ERROR - Category NOT Created!"; return(RedirectToAction("NextTransaction", "UploadedTransactions")); }
public ActionResult Create([Bind(Include = "Name,Amount")] Budget budget, List <int> BudgetItems) { if (ModelState.IsValid) { var user = db.Users.Find(User.Identity.GetUserId()); var sampleCategories = db.SampleBudgetItemCategories.AsNoTracking().ToList(); budget.HouseholdId = (int)user.HouseholdId; budget.Created = DateTimeOffset.Now; budget.Active = true; db.Budgets.Add(budget); db.SaveChanges(); foreach (var c in sampleCategories) { var category = new BudgetItemCategory(); category.Name = c.Name; category.BudgetId = budget.Id; db.BudgetItemCategories.Add(category); } db.SaveChanges(); BudgetItem budgetItem; SampleBudgetItem sampleBudgetItem; SampleBudgetItemCategory sampleCategory; foreach (var bid in BudgetItems) { budgetItem = new BudgetItem(); sampleBudgetItem = db.SampleBudgetItems.AsNoTracking().FirstOrDefault(b => b.Id == bid); sampleCategory = db.SampleBudgetItemCategories.FirstOrDefault(c => c.Id == sampleBudgetItem.CategoryId); budgetItem.Name = sampleBudgetItem.Name; budgetItem.Amount = sampleBudgetItem.Amount; budgetItem.CategoryId = db.BudgetItemCategories.FirstOrDefault(c => c.Name == sampleCategory.Name && c.BudgetId == budget.Id).Id; budgetItem.BudgetId = budget.Id; budgetItem.Active = true; budget.BudgetItems.Add(budgetItem); db.BudgetItems.Add(budgetItem); db.Entry(budget).State = EntityState.Modified; //db.SaveChanges(); } db.SaveChanges(); return(RedirectToAction("Details", new { id = budget.Id })); } ViewBag.BudgetItems = new MultiSelectList(db.BudgetItems, "Id", "Name"); return(View(budget)); }
public ActionResult Create([Bind(Include = "Id,Name")] BudgetItemCategory budgetItemCategory) { var budgetId = (int)TempData["BudgetId"]; if (ModelState.IsValid) { budgetItemCategory.BudgetId = budgetId; db.BudgetItemCategories.Add(budgetItemCategory); db.SaveChanges(); return(RedirectToAction("Details", "Budgets", new { id = budgetId })); } return(RedirectToAction("Details", "Budgets", new { id = budgetId })); }
public ActionResult _PartialEditCategory(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItemCategory budgetItemCategory = db.BudgetItemCategories.Find(id); if (budgetItemCategory == null) { return(HttpNotFound()); } TempData["BudgetId"] = (int)TempData["BudgetId"]; return(PartialView(budgetItemCategory)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItemCategory budgetItemCategory = db.BudgetItemCategories.Find(id); if (budgetItemCategory == null) { return(HttpNotFound()); } var budgetId = (int)TempData["BudgetId"]; TempData["BudgetId"] = (int)TempData["BudgetId"]; return(RedirectToAction("Details", "Budgets", new { id = budgetId, editCatId = id })); }
public string CreatHouseholdData() { var user = db.Users.Find(HttpContext.Current.User.Identity.GetUserId()); if (user != null) { //Check for registered user //Check if user has household if (user.HouseholdId == null) { return("You must create a household first"); } //Get user household and delete existing bank accounts, budget, and categories, which will also delete items and transactions Household household = db.Households.Include(h => h.Members).FirstOrDefault(h => h.Id == user.HouseholdId); var bankAccounts = db.BankAccounts.Where(ba => ba.HouseholdId == user.HouseholdId).ToList(); if (bankAccounts.Count > 0) { foreach (var account in bankAccounts) { db.BankAccounts.Remove(account); } } var budget = db.Budgets.FirstOrDefault(b => b.HouseholdId == user.HouseholdId); if (budget != null) { var budgetItems = db.BudgetItems.Where(b => b.BudgetId == budget.Id).ToList(); var categories = db.BudgetItemCategories.Where(b => b.BudgetId == budget.Id).ToList(); if (categories.Count > 0) { foreach (var category in categories) { db.BudgetItemCategories.Remove(category); } } db.SaveChanges(); } //If no budget exists yet if (budget == null) { budget = new Budget(); budget.HouseholdId = (int)user.HouseholdId; budget.Name = "Budget for " + household.Name; budget.Amount = 3000; budget.Created = DateTimeOffset.Now; budget.Active = true; db.Budgets.Add(budget); db.SaveChanges(); } //Start to create new stuff var sampleCategories = db.SampleBudgetItemCategories; foreach (var c in sampleCategories) { var category = new BudgetItemCategory(); category.Name = c.Name; category.BudgetId = budget.Id; db.BudgetItemCategories.Add(category); } db.SaveChanges(); var BudgetItems = db.SampleBudgetItems.Include(b => b.Category).ToList(); foreach (var bi in BudgetItems) { var budgetItem = new BudgetItem(); int catNameId = db.BudgetItemCategories.FirstOrDefault(b => b.Name == bi.Category.Name && b.BudgetId == budget.Id).Id; budgetItem.Name = bi.Name; budgetItem.Amount = bi.Amount; budgetItem.CategoryId = catNameId; budgetItem.BudgetId = budget.Id; budgetItem.Active = true; db.BudgetItems.Add(budgetItem); } db.SaveChanges(); var SavedBudgetItems = db.BudgetItems.Include(b => b.Category).ToList(); for (int ba = 1; ba <= 4; ba++) { var bankAccount = new BankAccount(); bankAccount.Name = "Account " + ba + " for household " + household.Name; bankAccount.Balance = 3000; bankAccount.WarningBalance = 100; bankAccount.BankName = "First Bank"; bankAccount.AccountNumber = 123450 + ba; bankAccount.HouseholdId = household.Id; bankAccount.AccountTypeId = db.AccountTypes.FirstOrDefault(a => a.Type == "Checking").Id; bankAccount.AccountOwnerId = user.Id; db.BankAccounts.Add(bankAccount); db.SaveChanges(); Transaction transaction; for (int x = 0; x <= 36; x++) { decimal total = 0.00M; foreach (var bi in SavedBudgetItems) { var count = 1; transaction = new Transaction(); transaction.Description = "Trans " + count + " for " + bankAccount.Name; transaction.Created = DateTimeOffset.Now.AddMonths(-x); transaction.Amount = Math.Abs((bi.Amount * .25M) + count - x); transaction.EnteredById = user.Id; transaction.BudgetItemId = bi.Id; transaction.BankAccountId = bankAccount.Id; transaction.IncomeExpenseId = db.IncomeExpenses.FirstOrDefault(i => i.Type == "Expense").Id; total += transaction.Amount; db.Transactions.Add(transaction); } db.SaveChanges(); transaction = new Transaction(); transaction.Description = "Deposit for " + bankAccount.Name; transaction.Created = DateTimeOffset.Now.AddMonths(-x); transaction.Amount = total * 1.05M; transaction.EnteredById = user.Id; transaction.BudgetItemId = null; transaction.BankAccountId = bankAccount.Id; transaction.IncomeExpenseId = db.IncomeExpenses.FirstOrDefault(i => i.Type == "Income").Id; db.Transactions.Add(transaction); db.SaveChanges(); } } return("Data has been generated"); } return("Something went wrong!"); }