public IHttpActionResult PutCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.Id) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// POST: api/Comment public IHttpActionResult PostComment() { Comment comment = new Comment(); var httpRequest = HttpContext.Current.Request; comment.Content = httpRequest["Content"]; comment.ArticleId = int.Parse(httpRequest["ArticleId"]); comment.UserId = httpRequest["UserId"]; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Comments.Add(comment); db.SaveChanges(); return(Ok(comment));//CreatedAtRoute("DefaultApi", new { id = article.Id }, article); }