public async Task <IActionResult> Edit(long id, [Bind("Monthly,Type,Description,AccountNumber,StartDate")] SecurityAddVm securityVm) { if (ModelState.IsValid) { Security updatedSecurity = await _context.tbl_security.Where(e => e.Id == id).FirstAsync(); // Copy over properties updatedSecurity.StartDate = DateTime.Parse(securityVm.StartDate); updatedSecurity.Monthly = securityVm.Monthly; updatedSecurity.Type = securityVm.Type; updatedSecurity.Description = securityVm.Description; updatedSecurity.AccountNumber = securityVm.AccountNumber; try { _context.Update(updatedSecurity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SecuritiesExists(updatedSecurity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(securityVm)); }
public async Task <User> UpdateUserData(User user) { user.Total = 0; user.Negative = 0; user.Positive = 0; // update expenses var expenses = _context.Entry(user).Collection(u => u.Expenses).Query().AsEnumerable(); if (expenses != null) { foreach (var exp in expenses) { user.Negative += exp.Cost; } } // update incomes var incomes = _context.Entry(user).Collection(u => u.Incomes).Query().AsEnumerable(); if (incomes != null) { foreach (var inc in incomes) { user.Positive += inc.Amount; } } user.Total = user.Positive - user.Negative; // save changes to db _context.Update(user); await _context.SaveChangesAsync(); // return user to display details return(user); }
public async Task <IActionResult> Edit(long id, [Bind("Name,Amount,Variable,Amount,WorkHours,Function,Company,StartDate")] IncomesAddVm incomeVm) { if (ModelState.IsValid) { Income updatedIncome = await _context.tbl_incomes.Where(e => e.Id == id).FirstAsync(); // Copy over properties updatedIncome.Name = incomeVm.Name; updatedIncome.Variable = incomeVm.Variable; updatedIncome.Amount = incomeVm.Amount; updatedIncome.WorkHours = incomeVm.WorkHours; updatedIncome.Function = incomeVm.Function; updatedIncome.Company = incomeVm.Company; updatedIncome.StartDate = incomeVm.StartDate; try { _context.Update(updatedIncome); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IncomesExists(updatedIncome.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(incomeVm)); }
public async Task <IActionResult> Edit(long id, [Bind("Name,Life,Type,Variable,Cost,AccountNumber,Creditor,expenseTypes")] ExpenseAddVm expenseVm) { if (ModelState.IsValid) { Expense updatedExpense = await _context.tbl_expenses.Where(e => e.Id == id).FirstOrDefaultAsync(); // Copy over properties updatedExpense.Name = expenseVm.Name; updatedExpense.Life = expenseVm.Life; updatedExpense.Type = expenseVm.Type; updatedExpense.Variable = expenseVm.Variable; updatedExpense.Cost = expenseVm.Cost; updatedExpense.AccountNumber = expenseVm.AccountNumber; updatedExpense.Creditor = expenseVm.Creditor; try { _context.Update(updatedExpense); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExpenseExists(updatedExpense.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(expenseVm)); }
public async Task <IActionResult> Edit(long id, [Bind("Name,Longterm,Monthly,Type,Description,AccountNumber,StartDate")] SavingsAddVm savingVm) { if (ModelState.IsValid) { Saving updatedSaving = await _context.tbl_savings.Where(e => e.Id == id).FirstAsync(); // Copy over properties updatedSaving.Name = savingVm.Name; updatedSaving.Monthly = savingVm.Monthly; updatedSaving.Longterm = savingVm.Longterm; updatedSaving.Type = savingVm.Type; updatedSaving.Description = savingVm.Description; updatedSaving.AccountNumber = savingVm.AccountNumber; updatedSaving.StartDate = DateTime.Parse(savingVm.StartDate); try { _context.Update(updatedSaving); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SavingsExists(updatedSaving.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(savingVm)); }