public IHttpActionResult GetNews(int id) { News news = db.News.Find(id); if (news == null) { return(NotFound()); } return(Ok(NewsVm.FromNews(news))); }
public IHttpActionResult PostNews(NewsVm newsVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var news = newsVm.ToNews(); db.News.Add(news); db.SaveChanges(); return(CreatedAtRoute("PostNews", new { id = news.Id }, NewsVm.FromNews(news))); }
public IHttpActionResult DeleteNews(int id) { News news = db.News.Find(id); if (news == null) { return(NotFound()); } db.News.Remove(news); db.SaveChanges(); return(Ok(NewsVm.FromNews(news))); }