public HttpResponseMessage Post(category newCategory) { if(ModelState.IsValid) { bool Ok = qDB.insertCategory(newCategory); if(Ok) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; } } return new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Could not insert new category") }; }
public bool insertCategory(category newCategory) { var category = new Category { categoryName = newCategory.categoryname }; try { db.Categories.Add(category); db.SaveChanges(); } catch(Exception e) { return false; } return true; }