public async Task<Unit> Handle(RequestModels.Delete request, CancellationToken cancellationToken) { var product = context.Products.FindAsync(request.Id); if (product == null) throw new CustomException(HttpStatusCode.NotFound, new { description = "Product not found" }); context.Remove(product); var res = await context.SaveChangesAsync(cancellationToken); if (res > 0) return Unit.Value; else throw new CustomException(HttpStatusCode.InternalServerError, new { description = "Transaction not completed" }); }
public async Task <IActionResult> Delete(long id) { var category = await _dbContext .Categories .FirstOrDefaultAsync(p => p.Id == id); if (category == null) { return(NotFound()); } _dbContext.Remove(category); await _dbContext.SaveChangesAsync(); return(NoContent()); }