// DELETE: api/categories/5 public async Task <HttpResponseMessage> Delete(string id) { if (!string.IsNullOrWhiteSpace(id)) { bool hasChildren = await _categoryobj.ContainsSubCategories(id); if (!hasChildren) { try { var deletedcategory = await _categoryobj.DeleteItemAsync(id); return(Request.CreateResponse(HttpStatusCode.NoContent)); } catch (Microsoft.Azure.Documents.DocumentClientException e) { string message = "Category to be deleted doesn't exist or was not found "; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } } else { string message = "Category to be deleted has one or many subcategories , hence cannot be deleted "; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); } } else { string message = "Enter valid Category Id to be deleted "; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); } }