public IActionResult Put([FromBody] ArticlesViewModel model) { // http status 500 (Server Error) if (model == null) { return(new StatusCodeResult(500)); } var artc = new Articles(); // Properties artc.Title = model.Title; artc.Article_text = model.Article_text; artc.ArticleMid = model.ArticleMid; artc.Article_Btm = model.Article_Btm; artc.ArticleUrl = model.ArticleUrl; artc.LastModifiedDate = DateTime.Now; artc.LastModifiedBy = "CE1"; // Add to db DbContext.Articles.Add(artc); _ = DbContext.SaveChanges(); // Return return(new JsonResult(artc.Adapt <ArticlesViewModel>(), new JsonSerializerSettings() { Formatting = Formatting.Indented })); }
public IActionResult Get() { Articles articles = DbContext.Articles.Where(i => i.Id == 4).FirstOrDefault(); return(new JsonResult( articles.Adapt <ArticlesViewModel>(), new JsonSerializerSettings() { Formatting = Formatting.Indented })); }