Skip to content

Commit

Permalink
Add update method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Hammerl committed Oct 20, 2020
1 parent c5cb8f3 commit d25272e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ExpenseTracker.Api/Controllers/ExpenseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public async Task<IActionResult> Create(Expense expense)
await ctx.SaveChangesAsync();
return Ok(expense);
}

[HttpPut]
public async Task<IActionResult> Update(Expense expense)
{
var expenseToUpdate = await ctx.FindAsync<Expense>(expense.ExpenseID);
if (expenseToUpdate == null)
{
return NotFound();
}
ctx.Entry(expenseToUpdate).CurrentValues.SetValues(expense);
ctx.SaveChanges();
return Ok(expense);
}

}
}
}

0 comments on commit d25272e

Please sign in to comment.