Skip to content

Commit

Permalink
Add delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Hammerl committed Oct 20, 2020
1 parent d25272e commit 5e45509
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ExpenseTracker.Api/Controllers/ExpenseController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ExpenseTracker.Models;
Expand Down Expand Up @@ -58,6 +58,17 @@ public async Task<IActionResult> Update(Expense expense)
return Ok(expense);
}

[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
var expense = await ctx.FindAsync<Expense>(id);
if (expense == null)
{
return NotFound();
}
ctx.Expenses.Remove(expense);
ctx.SaveChanges();
return NoContent();
}
}
}

0 comments on commit 5e45509

Please sign in to comment.