diff --git a/ExpenseTracker.Api/Controllers/ExpenseController.cs b/ExpenseTracker.Api/Controllers/ExpenseController.cs index 429b7f7..cfab280 100644 --- a/ExpenseTracker.Api/Controllers/ExpenseController.cs +++ b/ExpenseTracker.Api/Controllers/ExpenseController.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using ExpenseTracker.Models; @@ -58,6 +58,17 @@ public async Task Update(Expense expense) return Ok(expense); } + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var expense = await ctx.FindAsync(id); + if (expense == null) + { + return NotFound(); + } + ctx.Expenses.Remove(expense); + ctx.SaveChanges(); + return NoContent(); } } }