public HttpResponseMessage Delete(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var categoryDb = _courseCategoryService.GetCategory(id); if (categoryDb == null) { response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Id."); } else { _courseCategoryService.Delete(categoryDb); _courseCategoryService.SaveCategory(); response = request.CreateResponse(HttpStatusCode.OK, true); } } return response; })); }