public IHttpActionResult PutBlogModel(int id, BlogsData blogModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogModel.Id) { return(BadRequest()); } db.Entry(blogModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BlogModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetBlogModel(int id) { BlogsData blogModel = db.BlogsDatas.Find(id); if (blogModel == null) { return(NotFound()); } return(Ok(blogModel)); }
public IHttpActionResult DeleteBlogModel(int id) { BlogsData blogModel = db.BlogsDatas.Find(id); if (blogModel == null) { return(NotFound()); } db.BlogsDatas.Remove(blogModel); db.SaveChanges(); return(Ok(blogModel)); }
public IHttpActionResult PostBlogModel(BlogsData blogModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (blogModel.Id == 0) { db.BlogsDatas.Add(blogModel); } else { db.Entry(blogModel).State = EntityState.Modified; } db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = blogModel.Id }, blogModel)); }