Example #1
0
        public async Task <IActionResult> AddComment(
            [FromBody] CommentPost newComment)
        {
            var curUser = await _userService.GetCurUser(HttpContext);

            var createdComment = new ArtefactComment
            {
                ArtefactId = newComment.ArtefactId,
                AuthorId   = curUser.Id,
                Author     = curUser,
                Body       = newComment.Body,
                CreatedAt  = System.DateTime.UtcNow,
            };

            try
            {
                await _context.AddAsync(createdComment);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                var sqlError = Helpers.GetSqlError((SqlException)e.GetBaseException());
                switch (sqlError.Number)
                {
                case 547:     // fk violation
                    return(NotFound($"Artefact '{newComment.ArtefactId}' does not exist."));

                default:
                    throw;
                }
            }

            return(new JsonResult(_converter.ToJson(createdComment)));
        }
Example #2
0
        public PartialViewResult ChildrenPostComment(CommentPost childCom)
        {
            ApplicationUser user = null;
            string          id   = GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }



            CurrentCommentPostViewModel vm = new CurrentCommentPostViewModel
            {
                LoggedUser = user,
                Com        = childCom
            };

            if (vm.Com.Children != null && vm.Com.Children.Count > 1)
            {
                vm.Com.Children = vm.Com.Children.OrderBy(a => a.DateOfInsert).ToList();
            }

            return(PartialView("_ChildrenComments", vm));
        }
Example #3
0
        public PartialViewResult AddChildCommentPost(int idOfParentId, string content)
        {
            if (SpamDetector.IsContentSpam(content))
            {
                return(null);
            }

            var  parentComment = context.CommentPosts.Find(idOfParentId);
            Post post          = context.Posts.Where(a => a.PostId == parentComment.PostId).First();

            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }

            CommentPost commentPost = new CommentPost()
            {
                Body                = content,
                DateOfInsert        = DateTime.Now,
                PostId              = post.PostId,
                UserId              = User.Identity.GetUserId(),
                User                = user,
                ParentCommentPostId = parentComment.CommentPostId,
                Parent              = parentComment
            };

            var sentimentalInt = new SentimentalInterpreter();
            var isContentHappy = sentimentalInt.IsHappy(commentPost.Body);

            if (isContentHappy)
            {
                commentPost.IsHappy = true;
            }

            parentComment.Children.Add(commentPost);
            context.CommentPosts.Add(commentPost);

            context.SaveChanges();



            CurrentCommentPostViewModel vm = new CurrentCommentPostViewModel
            {
                LoggedUser = user,
                Com        = parentComment
            };

            if (vm.Com.Children != null && vm.Com.Children.Count > 1)
            {
                vm.Com.Children = vm.Com.Children.OrderBy(a => a.DateOfInsert).ToList();
            }

            return(PartialView("~/Views/Post/_ChildrenComments.cshtml", vm));
        }
Example #4
0
        public ActionResult <ResponseMessage> Post([FromBody] CommentPost value)
        {
            using (AnimalProjectDbContext _context = new AnimalProjectDbContext())
            {
                ResponseMessage response = new ResponseMessage();
                try
                {
                    int result = 0;
                    if (value.description.Length < 2)
                    {
                        response.message = "Descripton lenght is not less than 2";
                    }
                    else
                    {
                        value.createdAt = DateTime.Now;
                        try
                        {
                            int maxid = 0;
                            if (_context.CommentPosts.Count() > 0)
                            {
                                maxid = _context.CommentPosts.OrderByDescending(a => a.id).FirstOrDefault().id;
                            }
                            value.id = maxid + 1;
                        }
                        catch (Exception e)
                        {
                            response.message = e.Message;
                        }
                        _context.CommentPosts.Add(value);
                        try
                        {
                            result = _context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            response.message += e.InnerException.Message;
                        }

                        if (result == 1)
                        {
                            response.message = "Success";
                        }
                        else
                        {
                            response.message = "Fail";
                        }
                    }
                }
                catch (Exception e)
                {
                    response.message = "Fail" + Environment.NewLine + e.Message;
                }
                return(response);
            }
        }
Example #5
0
 public IActionResult PostComment(CommentPost model)
 {
     if (ModelState.IsValid)
     {
         string query = $@"INSERT INTO comments (comment, users_id, messages_id) VALUES (
             '{model.commentPost}', {(int)HttpContext.Session.GetInt32("loggedUserID")}, '{model.messageID}')";
         DbConnector.Execute(query);
         return(RedirectToAction("TheWall"));
     }
     return(RedirectToAction("TheWall"));
 }
Example #6
0
        public async Task <IActionResult> Create([Bind("Id,Content,Enabled,ApplicationUserId,Created_date,PostId")] CommentPost commentPost)
        {
            if (ModelState.IsValid)
            {
                commentPost.ApplicationUser = _context.Users.Find(commentPost.ApplicationUserId);
                _context.Add(commentPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Posts", new { id = commentPost.PostId }));
            }
            //ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", commentPost.ApplicationUserId);
            //ViewData["PostId"] = new SelectList(_context.Posts, "Id", "Id", commentPost.PostId);
            return(View(commentPost));
        }
Example #7
0
        public bool CommentPost(CommentPost model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Comment
                    .Single(e => e.PostId == model.PostId && e.OwnerID == _userId);

                entity.Title       = model.Title;
                entity.Content     = model.Content;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task <IActionResult> Create([Bind("CategoryPostId,CommentBody")] CommentPost commentPost, string slug)
        {
            if (ModelState.IsValid)
            {
                commentPost.Created = DateTime.Now;

                //How do i tell my program that the Id of the Author of this comment is the Id of the User
                commentPost.BlogUserId = _userManager.GetUserId(User);

                _context.Add(commentPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "CategoryPosts", new { slug }));
            }
            return(RedirectToAction("Details", "CategoryPosts", new { slug }));
        }
Example #9
0
        public IActionResult PostComment(CommentPost parameters)
        {
            var userID = JWTUtility.GetUserID(HttpContext);

            var comment = new Comments
            {
                Comment   = parameters.Comment,
                Userid    = userID,
                Postid    = parameters.PostID,
                Createdon = DateTime.Now
            };

            _context.Comments.Add(comment);
            _context.SaveChanges();

            return(Ok());
        }
Example #10
0
 public IActionResult PostComments([FromBody] CommentPost comment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         if (comment.Fid < 0)
         {
             return(StatusCode(417));
         }
         else if (comment.Uid < 0)
         {
             return(StatusCode(417));
         }
         else if (comment.Comments.Length < 1 || comment.Comments.Length > 1400)
         {
             return(StatusCode(417));
         }
         else
         {
             string temp = repo.PostComment(comment);
             if (temp.Equals("Invalid User ID"))
             {
                 return(StatusCode(417));
             }
             else if (temp.Equals("Invalid Question"))
             {
                 return(StatusCode(417));
             }
             else if (temp.Equals("Invalid User"))
             {
                 return(Unauthorized());
             }
             else
             {
                 temp = "Success";
                 Reply obj = new Reply {
                     Message = temp
                 };
                 return(Ok(obj));
             }
         }
     }
 }
Example #11
0
        public ActionResult Index(CommentPost newComment, int?id)
        {
            ViewBag.ActivePost = db.Posts.Find(id);
            User activeUser = (User)Session["UserLogged"];
            Post activePost = db.Posts.Find(id);

            ViewBag.Comments = db.CommentPosts.Where(db => db.Post_Id == activePost.Id).OrderByDescending(db => db.Dates).ToList();
            if (newComment.Content != null)
            {
                newComment.Users_Id = activeUser.Id;
                newComment.Post_Id  = activePost.Id;
                newComment.Dates    = DateTime.Now;
                db.CommentPosts.Add(newComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Error = "Comment cannot be empty !";
            }
            ViewBag.Comments          = db.CommentPosts.Where(db => db.Post_Id == activePost.Id).OrderByDescending(db => db.Dates).ToList();
            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).OrderByDescending(db => db.Date).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.CommentCount = db.CommentPosts.Where(db => db.Post_Id == activePost.Id).Count();
            if (activePost != null)
            {
                return(View(activePost));
            }
            else
            {
                return(Content("There is no News with this Id"));
            }
        }
Example #12
0
 public ActionResult <List <CommentPost> > Post([FromBody] User user)
 {
     using (AnimalProjectDbContext _context = new AnimalProjectDbContext())
     {
         try
         {
             return(_context.CommentPosts.Where(a => a.creatorUsername == user.username).ToList());
         }
         catch (Exception e)
         {
             List <CommentPost> errorList = new List <CommentPost>();
             CommentPost        d         = new CommentPost();
             d.description = e.InnerException.Message;
             errorList.Add(d);
             return(errorList);
         }
     }
 }
Example #13
0
        public void GetComments(int id)
        {
            string strCon = System.Web
                            .Configuration
                            .WebConfigurationManager
                            .ConnectionStrings["WingtipToys"].ConnectionString;

            SqlConnection conn = new SqlConnection(strCon);

            conn.Open();
            SqlCommand     cmd = new SqlCommand("SELECT * FROM[Comments]WHERE CommentPostId = " + id, conn);
            DataSet        ds  = new DataSet();
            SqlDataAdapter da  = new SqlDataAdapter(cmd);

            da.Fill(ds);
            CommentPost.DataSource = ds;
            CommentPost.DataBind();
        }
Example #14
0
        public PartialViewResult AddComment(int postId, string content)
        {
            if (SpamDetector.IsContentSpam(content))
            {
                return(null);
            }
            Post            post = context.Posts.Where(a => a.PostId == postId).First();
            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }

            CommentPost commentPost = new CommentPost()
            {
                Body = content, DateOfInsert = DateTime.Now, PostId = post.PostId, UserId = User.Identity.GetUserId(), User = user
            };



            var sentimentalInt = new SentimentalInterpreter();
            var isContentHappy = sentimentalInt.IsHappy(commentPost.Body);

            if (isContentHappy)
            {
                commentPost.IsHappy = true;
            }

            context.CommentPosts.Add(commentPost);
            context.SaveChanges();

            post.Comments.Add(commentPost);

            CurrentPostUserViewModel vm = new CurrentPostUserViewModel
            {
                LoggedUser = user,
                Post       = post
            };

            vm.Post.Comments = vm.Post.Comments.OrderBy(a => a.DateOfInsert).ToList();
            return(PartialView("_ListOfComments", vm));
        }
Example #15
0
        public string AddPostComment(CommentPost commpost)
        {
            var contentpos = Request.Form["CommendPostcopne"];
            var posid      = Convert.ToInt32(Request["post_idcomm"]);
            var userid     = Convert.ToInt32(Session["User_id"]);

            if (!String.IsNullOrEmpty(contentpos))
            {
                commpost.Post_id = posid;
                commpost.User_id = userid;
                commpost.Content = contentpos;
                PostManage.AddCommentPost(commpost);
                return("success");
            }
            else
            {
                return("fail");
            }
        }
Example #16
0
        public ActionResult CommentPoster(CommentPostModel NewComment)
        {
            int usermodelidintcontainer = int.Parse(NewComment.UserIdContainer);


            var sentCommentpost = new CommentPost
            {
                BlogPostId  = NewComment.Items.ID,
                Comment     = NewComment.Items2.Comment,
                UserModelId = usermodelidintcontainer
            };



            db.CommentTable.Add(sentCommentpost);
            db.SaveChanges();


            return(View());
        }
Example #17
0
        public ActionResult <ResponseMessage> Put([FromBody] CommentPost value)
        {
            ResponseMessage response = new ResponseMessage();

            using (AnimalProjectDbContext _context = new AnimalProjectDbContext())
            {
                int result = 0;


                if (_context.CommentPosts.Any(a => a.id == value.id))
                {
                    response.message = "CommentPost is found";
                    _context.CommentPosts.Remove(_context.CommentPosts.Where(a => a.id == value.id).FirstOrDefault());
                    _context.CommentPosts.Add(value);
                    try
                    {
                        result = _context.SaveChanges();
                        if (result == 1)
                        {
                            response.message = "Success";
                        }
                        else
                        {
                            response.message = "Fail";
                        }
                    }
                    catch (Exception e)
                    {
                        response.message = "Error" + Environment.NewLine + e.InnerException.Message;
                    }
                }
                else
                {
                    response.message = "CommentPost not found";
                }
            }
            return(response);
        }
Example #18
0
        public async Task <IActionResult> AddQuestion(
            [FromBody] CommentPost newQuestion)
        {
            var curUser = await _userService.GetCurUser(HttpContext);

            // veryify answer
            var art = await _context
                      .Artefacts
                      .SingleOrDefaultAsync(a => a.Id == newQuestion.ArtefactId);

            if (art == null)
            {
                return(NotFound($"'ArtefactId' '{newQuestion.ArtefactId}' does not exist."));
            }
            if (art.OwnerId != curUser.Id)
            {
                return(Unauthorized("Only the artefact owner can post a question."));
            }

            var createdQuestion = new ArtefactQuestion
            {
                ArtefactId      = newQuestion.ArtefactId,
                AuthorId        = curUser.Id,
                Author          = curUser,
                Body            = newQuestion.Body,
                CreatedAt       = System.DateTime.UtcNow,
                IsAnswered      = false,
                AnswerCommentId = null,
            };

            // no need to catch the fk error - already checked for 404
            await _context.AddAsync(createdQuestion);

            await _context.SaveChangesAsync();

            return(new JsonResult(_converter.ToJson(createdQuestion)));
        }
Example #19
0
 public void UpdateCommend(CommentPost commpost)
 {
     db.Entry <CommentPost>(commpost).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Example #20
0
 //评论回复
 public static void AddCommentPost(CommentPost commPost)
 {
     pos.AddCommentPost(commPost);
 }
Example #21
0
 public static void UpdateCommend(CommentPost commpost)
 {
     pos.UpdateCommend(commpost);
 }
Example #22
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            // cập nhật thông tin bài viết
            tblPost p = new tblPost();

            p.IDPost       = idpost;
            p.TimePost     = DateTime.Parse(timepost);
            p.CountComment = tongsocomment;
            p.CountLike    = int.Parse(tongsoluonglike);
            if (danhgia == "Tích cực")
            {
                p.Status = "Tích cực";
            }
            else
            {
                p.Status = "Tiêu cực";
            }
            Post.Sua(p);
            // kết thúc cập nhật thông tin bài viết

            //thêm tài khoản người dùng
            for (int i = 0; i < lsIDTichCuc.Count; i++)
            {
                tblUserFB   newu  = new tblUserFB();
                tblLikePost newlp = new tblLikePost();
                newu.IDUser = lsIDTichCuc[i].ToString();
                newu.Name   = lsNameTichCuc[i].ToString();
                UserFB.Them(newu);
                newlp.IDPost   = idpost;
                newlp.IDUserFB = lsIDTichCuc[i].ToString();
                newlp.Status   = 1;
                LikePost.Them(newlp);
            }
            for (int i = 0; i < lsIDTieuCuc.Count; i++)
            {
                tblUserFB   newu  = new tblUserFB();
                tblLikePost newlp = new tblLikePost();
                newu.IDUser = lsIDTieuCuc[i].ToString();
                newu.Name   = lsNameTieuCuc[i].ToString();
                UserFB.Them(newu);
                newlp.IDPost   = idpost;
                newlp.IDUserFB = lsIDTieuCuc[i].ToString();
                newlp.Status   = -1;
                LikePost.Them(newlp);
            }
            //thêm từ những người bình luận
            for (int i = 0; i < LsNguoiDungBL.Items.Count; i++)
            {
                tblUserFB newu = new tblUserFB();
                newu.IDUser = lsIDUserBinhLuan[i];
                newu.Name   = LsNguoiDungBL.Items[i].Text;
                UserFB.Them(newu);

                //lưu người dùng bình luận vào sql
                tblCommentPost newcommentpost = new tblCommentPost();
                newcommentpost.IDPost      = idpost;
                newcommentpost.IDComment   = lsIDBinhLuan[i].ToString();
                newcommentpost.IDUser      = lsIDUserBinhLuan[i];
                newcommentpost.Description = lsNoiDungBL[i];
                newcommentpost.Status      = 0;

                CommentPost.Them(newcommentpost);
                //kết thúc lưu người dùng bình luận
            }
            //kết thúc thêm tài khoản
            MessageBox.Show("Đã lưu tất cả thông tin!");
        }
Example #23
0
        private void btnNguoiBinhLuan_Click(object sender, EventArgs e)
        {
            LsNguoiDungBL.Items.Clear();
            lsIDBinhLuan.Clear();
            lsNoiDungBL.Clear();
            lbTrangThaiBL.Visible  = true;
            ProgressQuetBL.Visible = true;
            ProgressQuetBL.Value   = 0;
            WebBrowser web1 = new WebBrowser();

            web1.Navigate("mobile.facebook.com/" + idpost);
            while (web1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            htmlcontent = web1.DocumentText;
            htmlcontent = htmlcontent.Replace("amp;", "");
            for (; ;)
            {
                int kt  = htmlcontent.IndexOf("<H3><A class=\"");
                int kt2 = htmlcontent.IndexOf("<h3><a class=\"d");
                //nếu như còn bình luận
                if (kt != -1 || kt2 != -1)
                {
                    if (kt == -1)
                    {
                        htmlcontent = htmlcontent.Substring(kt2 + 5);
                    }
                    else
                    {
                        htmlcontent = htmlcontent.Substring(kt + 5);
                    }
                    htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("href") + 4);
                    htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("\"") + 1);

                    //string idUserComment = htmlcontent.Remove(htmlcontent.IndexOf("refid"));
                    //idUserComment = idUserComment.Replace("?", "");
                    //idUserComment = idUserComment.Replace("rc=p", "");
                    string idUserComment = htmlcontent.Remove(htmlcontent.IndexOf("&"));


                    string NameBL = htmlcontent.Substring(htmlcontent.IndexOf(">") + 1);
                    NameBL = NameBL.Remove(NameBL.IndexOf("<"));


                    htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("class=") + 5);
                    htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf(">") + 1);

                    string NoiDung = htmlcontent.Remove(htmlcontent.IndexOf("/DIV") - 1);

                    string idcomment = htmlcontent.Substring(htmlcontent.IndexOf("like_comment_id=") + 16);
                    idcomment = idcomment.Remove(idcomment.IndexOf("&"));

                    string TimeBL = htmlcontent.Substring(htmlcontent.IndexOf("ABBR") + 5);
                    TimeBL = TimeBL.Remove(TimeBL.IndexOf("<"));
                    if (TimeBL.IndexOf("Tháng") == -1)
                    {
                        TimeBL = TimeBL + DateTime.Now.ToShortDateString();
                    }

                    if (CommentPost.KiemTraIDComment(idcomment) == false)
                    {
                        lsIDUserBinhLuan.Add(idUserComment);
                        lsIDBinhLuan.Add(idcomment);
                        lsNoiDungBL.Add(NoiDung);
                        lsTimeBinhLuan.Add(TimeBL);
                        LsNguoiDungBL.Items.Add(NameBL);
                    }
                }
                //nếu như hết bình luận cố tìm xem thêm bình luận
                else
                {
                    int ktseenext = htmlcontent.IndexOf("see_next");
                    if (ktseenext != -1)
                    {
                        htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("see_next") + 5);
                        htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("href") + 4);
                        htmlcontent = htmlcontent.Substring(htmlcontent.IndexOf("\"") + 1);
                        string urltiep = htmlcontent.Remove(htmlcontent.IndexOf("\""));
                        urltiep = urltiep.Replace("amp;", "");
                        web1.Navigate("mobile.facebook.com" + urltiep);
                        while (web1.ReadyState != WebBrowserReadyState.Complete)
                        {
                            Application.DoEvents();
                        }
                        htmlcontent = web1.DocumentText;
                    }
                    else
                    {
                        ProgressQuetBL.Value = 100;
                        lbTrangThaiBL.Text   = "Đã quét xong!";
                        MessageBox.Show("Đã tìm kiếm được " + LsNguoiDungBL.Items.Count + " bình luận mới");
                        tongsocomment = LsNguoiDungBL.Items.Count;
                        break;
                    }
                }
            }
        }