public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            var userId = User.Identity.GetUserId();


            var user    = dbContext.Users.FirstOrDefault(u => u.Id == userId);
            var comment = dbContext.Comments.FirstOrDefault(p => p.Id == ComID);

            var subComments = new SubComments();

            if (subComment != null)
            {
                subComments.CommentMsg    = subComment.CommentMsg;
                subComments.CommentedDate = subComment.CommentedDate;
            }
            ;


            if (user != null && comment != null)
            {
                comment.SubComment.Add(subComments);
                user.SubComments.Add(subComments);

                dbContext.SaveChanges();
                //result = true;
            }


            return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID }));
        }
Exemplo n.º 2
0
        public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            SubComment subCommentEntity = null;
            int        userId           = (int)Session["UserID"];

            var user    = dbContext.Users.FirstOrDefault(u => u.UserID == userId);
            var comment = dbContext.Comments.FirstOrDefault(p => p.ComID == ComID);

            if (subComment != null)
            {
                subCommentEntity = new EDMX.SubComment
                {
                    CommentMsg    = subComment.CommentMsg,
                    CommentedDate = subComment.CommentedDate,
                };


                if (user != null && comment != null)
                {
                    comment.SubComments.Add(subCommentEntity);
                    user.SubComments.Add(subCommentEntity);

                    dbContext.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID }));
        }
Exemplo n.º 3
0
        public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            ReplayComment subCommentEntity = null;
            string        uname            = User.Identity.Name;
            var           obj    = db.Logins.Where(x => x.Username.Equals(uname)).FirstOrDefault();
            int           userId = obj.id;

            var user    = db.Logins.FirstOrDefault(u => u.id == userId);
            var comment = db.Comments.FirstOrDefault(p => p.id == ComID);

            if (subComment != null)
            {
                subCommentEntity = new ReplayComment
                {
                    Msg  = subComment.CommentMsg,
                    Date = subComment.CommentedDate,
                };


                if (user != null && comment != null)
                {
                    comment.ReplayComments.Add(subCommentEntity);
                    user.ReplayComments.Add(subCommentEntity);

                    db.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetSubComments", "Songs", new { ComID = ComID }));
        }
        public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            SubComment subCommentEntity = null;
            // int userId = (int)Session["UserID"];
            string      currentUserId = User.Identity.GetUserId();
            int         userId        = 1;
            List <User> GetUsers      = sp.GetUsers();

            var user    = GetUsers.FirstOrDefault(u => u.Id == currentUserId);
            var comment = sp.GetComments().FirstOrDefault(p => p.ComID == ComID);

            if (subComment != null)
            {
                subCommentEntity = new SubComment
                {
                    CommentMsg    = subComment.CommentMsg,
                    CommentedDate = DateTime.Now
                                    //subComment.CommentedDate,
                };


                if (user != null && comment != null)
                {
                    comment.SubComments.Add(subCommentEntity);
                    user.SubComments.Add(subCommentEntity);
                    sc.Commit();
                    su.Commit();
                    sp.Commit();
                    //  dbContext.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID }));
        }