public IActionResult Delete([FromForm] ExpenseDeleteViewModel expense, [FromRoute] int id) { if (TryValidateModel(expense)) { _expenseDatabase.Delete(id); return(RedirectToAction(nameof(Index))); } else { return(View(expense)); } }
public async Task <IActionResult> Delete(int id) { Expense expenseToDelete = await _dbContext.Expenses.FindAsync(id); ExpenseDeleteViewModel dvm = new ExpenseDeleteViewModel() { Id = expenseToDelete.Id, Amount = (decimal)expenseToDelete.Amount, Description = (string)expenseToDelete.Description, Date = (DateTime)expenseToDelete.Date }; return(View(dvm)); }
public async Task <IActionResult> Delete(int id) { string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var expense = await _expenseDbContext.Expenses .FirstOrDefaultAsync(x => x.Id == id && x.ExpenseAppUserId == userId); var expenseDelete = new ExpenseDeleteViewModel { Id = expense.Id, Amount = expense.Amount, Date = expense.Date, }; return(View(expenseDelete)); }
public async Task <IActionResult> Delete(int id) { Expense domainExpense = await _expenseDatabase.Expenses.FindAsync(id); if (domainExpense.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) { ExpenseDeleteViewModel vm = new ExpenseDeleteViewModel() { Id = domainExpense.Id, Amount = domainExpense.Amount, Description = domainExpense.Description, Date = domainExpense.Date }; return(View(vm)); } else { return(RedirectToAction("NoSneakyStuff")); } }