Answer the question
In order to leave comments, you need to log in
How to remove DELETE by write method?
Unable to delete a record from the database. Although I get the corresponding status code after deletion.
[Route("api/wishlist")]
[ApiController]
....
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
var item = _ItemService.GetIdAsync(id);
if (item == null)
{
return NotFound();
}
await _ItemService.DeleteAsync(id);
return NoContent();
}
public async Task<bool> DeleteAsync(int id)
{
bool status;
try
{
var entity = await _context.Set<Item>().FindAsync(id);
if (entity != null)
{
_context.Set<Item>().Remove(entity);
await _context.SaveChangesAsync();
}
status = true;
}
catch (Exception)
{
status = false;
}
return status;
}
public async Task<bool> DeleteAsync(int id)
{
return await _ItemRepository.DeleteAsync(id);
}
Answer the question
In order to leave comments, you need to log in
And what does Debug of the DeleteAsync method say? Entity finds or null? And you look in the same DB, or ConnectionString different can?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question