public JsonResult InsertComment(string Content) { string mess = ""; CommentNew cm = new CommentNew(); if (NewsID != 0 && WebYoutube.Session.User.Id != 0) { cm.Content = Content; cm.NewsID = NewsID; cm.PeopleID = WebYoutube.Session.User.Id; cm.Status = true; var res = dao.InsertComment(cm); mess = res; } else { } return(Json(new { Mess = mess })); }
public JsonResult EditComment(string model) { JavaScriptSerializer seria = new JavaScriptSerializer(); CommentNew cm = seria.Deserialize <CommentNew>(model); //cm.NewsID = NewsID; //cm.PeopleID = WebYoutube.Session.User.Id; //cm. bool status = false; var res = dao.EditComment(cm.ID, cm); if (res == "") { status = true; } else { status = false; } return(Json(new { Mess = res, Status = status, })); }
public string EditComment(int id, CommentNew news) { try { var res = db.CommentNews.Find(id); res.Content = news.Content; db.SaveChanges(); return(""); } catch (Exception ex) { return(ex.ToString()); } }
public string InsertComment(CommentNew cm) { try { cm.CreateDate = DateTime.Now; db.CommentNews.Add(cm); db.SaveChanges(); return(""); } catch (Exception ex) { return(ex.ToString()); } }
public ActionResult Index(CommentNew newComment, int?id) { User activeUser = (User)Session["UserLogged"]; News activeNews = db.News.Find(id); ViewBag.Comments = db.CommentNews.Where(db => db.News_Id == activeNews.Id).ToList(); if (newComment.Content != null) { newComment.Users_Id = activeUser.Id; newComment.News_Id = activeNews.Id; newComment.Dates = DateTime.Now; db.CommentNews.Add(newComment); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Error = "Comment cannot be empty !"; } ViewBag.CommentCount = db.CommentNews.Where(db => db.News_Id == activeNews.Id).Count(); ViewBag.Author = db.Administrators.First(); ViewBag.BlogSingleMasking = db.Blog_Single_Masking.First(); ViewBag.Category = db.Categories.Where(db => db.Status == 0).ToList(); ViewBag.Post = db.Posts.Where(db => db.Status == 0).Take(3).ToList(); ViewBag.Tag = db.Tags.Where(db => db.Status == 0).ToList(); List <Category> ctg = db.Categories.Where(db => db.Status == 0).ToList(); List <int> newsCount = new List <int>(); foreach (var item in ctg) { var sum = db.News_To_Category.Where(db => db.Category_Id == item.Id).Count(); newsCount.Add(sum); } ViewBag.NewsCount = newsCount; ViewBag.ActiveNews = db.News.Find(id); if (activeNews != null) { return(View(activeNews)); } else { return(Content("There is no News with this Id")); } }