public static bool UpdateComment(DBO.Comment comment) { using (IziWatchEntities bdd = new IziWatchEntities()) { try { T_Comment t_comment = bdd.T_Comment.Where(x => x.id == comment.Id).FirstOrDefault(); if (t_comment != null) { t_comment.id = comment.Id; t_comment.title = comment.Title; t_comment.text = comment.Text; t_comment.article_id = comment.ArticleId; t_comment.user_id = comment.UserId; bdd.SaveChanges(); return(true); } else { return(false); } } catch (Exception e) { return(false); } } }
public static List <DBO.Comment> GetListCommentByArticle(long article_id) { List <DBO.Comment> result = new List <DBO.Comment>(); try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { List <T_Comment> list = bdd.T_Comment.Where(x => x.id_article == article_id).ToList(); foreach (T_Comment comment in list) { DBO.Comment newComment = new DBO.Comment() { Id = comment.id, Content = comment.content, IdArticle = comment.id_article, Date = comment.date, IdUser = comment.id_user }; result.Add(newComment); } return(result); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(result); } }
public ActionResult Edit([Bind(Include = "Id,Title,Text,ArticleId,UserId")] DBO.Comment comment) { if (ModelState.IsValid) { //Generated : db.Entry(comment).State = EntityState.Modified; BusinessManagement.Comment.UpdateComment(comment); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(comment)); }
public ActionResult Create([Bind(Include = "Id,Title,Text,ArticleId,UserId")] DBO.Comment comment) { if (ModelState.IsValid) { //Generated : db.Comments.Add(comment); BusinessManagement.Comment.CreateComment(comment); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(comment)); }
// GET: Comments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //Generated : Comment comment = db.Comments.Find(id); DBO.Comment comment = BusinessManagement.Comment.GetComment((int)id); if (comment == null) { return(HttpNotFound()); } return(View(comment)); }
public static bool UpdateComment(DBO.Comment comment) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Comment oldComment = bdd.T_Comment.Where(x => x.id == comment.Id).FirstOrDefault(); oldComment.content = comment.Content; oldComment.id_article = comment.IdArticle; oldComment.id_user = comment.IdUser; oldComment.date = comment.Date; bdd.SaveChanges(); return(true); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(false); } }
public static bool CreateComment(DBO.Comment comment) { using (IziWatchEntities bdd = new IziWatchEntities()) { try { T_Comment t_comment = new T_Comment() { id = comment.Id, title = comment.Title, text = comment.Text, article_id = comment.ArticleId, user_id = comment.UserId }; bdd.T_Comment.Add(t_comment); bdd.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public static bool CreateComment(DBO.Comment comment) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Comment newComment = new T_Comment() { content = comment.Content, id_user = comment.IdUser, id_article = comment.IdArticle, date = comment.Date }; bdd.T_Comment.Add(newComment); bdd.SaveChanges(); return(true); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(false); } }
public static bool UpdateComment(DBO.Comment comment) { return(DataAccess.Comment.UpdateComment(comment)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DBO.User user = BusinessManagement.User.GetUserByUserIdentity(User); DBO.Article article = BusinessManagement.Article.GetArticle((int)id); DBO.Popularity popularity = null; List <DBO.Comment> comments = new List <DBO.Comment>(); int countLikes = 0; bool commentError = false; if (article == null) { return(HttpNotFound()); } else { if (user != null) { if (Request["action"] == "like") { BusinessManagement.Article.LikeArticle(article, user); } else if (Request["action"] == "unlike") { BusinessManagement.Article.UnlikeArticle(article, user); } else if (Request["action"] == "Commenter") { DBO.Comment comment = new DBO.Comment(); comment.Title = Request["commentTitle"]; comment.Text = Request["commentText"]; comment.ArticleId = article.Id; comment.UserId = user.Id; if (comment.Title == "" || comment.Text == "") { commentError = true; } else { BusinessManagement.Comment.CreateComment(comment); } } BusinessManagement.Article.ViewArticle(article, user); popularity = BusinessManagement.Popularity.GetPopularityByUserAndArticle(article, user); } BusinessManagement.Article.IncrementArticleViews(article); comments = BusinessManagement.Comment.GetCommentsByArticle(article); countLikes = BusinessManagement.Popularity.countLikeArticle(article); } ViewBag.userConnected = user; ViewBag.article = article; ViewBag.comments = comments; ViewBag.popularity = popularity; ViewBag.countLikes = countLikes; ViewBag.pageUrl = Request.Url; ViewBag.commentError = commentError; ViewBag.tweet_text = "https://twitter.com/intent/tweet?text=" + article.Title.Substring(0, @article.Title.Length).Replace(" ", "%20"); return(View()); }