public IHttpActionResult PutNews_Comment(int id, News_Comment news_Comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != news_Comment.CommentID) { return(BadRequest()); } db.Entry(news_Comment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!News_CommentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
//public ActionResult Delete(int?id) //{ // if(id==null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // News_Comment newscomment = db.News_Comment.Find(id); // if(newscomment==null) // { // return HttpNotFound(); // } // return View(newscomment); //} //[HttpPost,ActionName("Delete")] //[ValidateAntiForgeryToken] //public ActionResult DeleteConfirmed(int id) //{ // News_Comment newscomment = db.News_Comment.Find(id); // db.News_Comment.Remove(newscomment); // db.SaveChanges(); // return RedirectToAction("Index"); //} public ActionResult Delete(int?id) { News_Comment nc = db.News_Comment.Find(id); db.News_Comment.Remove(nc); db.SaveChanges(); return(Content("<script>alert('删除成功!');window.open('" + Url.Action("Index", "News_Comment") + "','_self');</script>")); }
public IHttpActionResult GetNews_Comment(int id) { News_Comment news_Comment = db.News_Comment.Find(id); if (news_Comment == null) { return(NotFound()); } return(Ok(news_Comment)); }
public IHttpActionResult PostNews_Comment(News_Comment news_Comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.News_Comment.Add(news_Comment); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = news_Comment.CommentID }, news_Comment)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } News_Comment newscomment = db.News_Comment.Find(id); if (newscomment == null) { return(HttpNotFound()); } return(View(newscomment)); }
public IHttpActionResult DeleteNews_Comment(int id) { News_Comment news_Comment = db.News_Comment.Find(id); if (news_Comment == null) { return(NotFound()); } db.News_Comment.Remove(news_Comment); db.SaveChanges(); return(Ok(news_Comment)); }
public ActionResult Newscomment() { News_Comment news_Comment = new News_Comment(); news_Comment.article_id = Convert.ToInt32(Request["article_id"]); news_Comment.users_id = Convert.ToInt32(Session["User_id"]); news_Comment.content = Request["comment"]; int id = news_Comment.article_id; linxinDb.News_Comment.Add(news_Comment); linxinDb.SaveChanges(); newsClass.psy_News = linxinDb.Psy_news.Where(n => n.id == id).Select(n => n); newsClass.news_Comments = from n in linxinDb.News_Comment where n.article_id == id where n.parent_comment_id == null select n; ViewBag.likenum = linxinDb.likes_news.Where(n => n.news_id == id).Count(); return(View("News_article", newsClass)); }
public ActionResult NC_Add(News_Comment news_comment) { if (Session["UID"] != null) { string pcmes = Request["pcmes"]; int pic_ID = Convert.ToInt32(Request["picid"]); if (ModelState.IsValid) { news_comment.News_ID = pic_ID; news_comment.UID = Convert.ToInt32(Session["UID"].ToString()); news_comment.NC_Mes = pcmes; news_comment.NC_Time = System.DateTime.Now; db.News_Comment.Add(news_comment); db.SaveChanges(); return(Content("<script>alert('评论成功!');window.open('" + Url.Action("Details", "News", new { id = pic_ID }) + "','_self');</script>")); } return(RedirectToAction("Details", "News")); } else { return(Content("<script>;alert('你还没有登录哦');history.go(-1)</script>")); } }