コード例 #1
0
        public JsonResult addNewComment(commentDTO comment)
        {
            try
            {
                string userid   = User.Identity.Name;
                string username = dbContext.Users.Where(x => x.Email == userid).FirstOrDefault().Name;

                //XSkillsEntities1 context = new XSkillsEntities1();
                var _comment = new Comment()
                {
                    PostID      = comment.PostId,
                    ParentId    = comment.parentId,
                    CommentText = comment.commentText,
                    Username    = username,
                    CommentDate = DateTime.Now
                };

                context.Comments.Add(_comment);
                context.SaveChanges();
                var model = context.GetComments(postID: null, commentID: _comment.CommentID)
                            .Select(x => new commentViewModel
                {
                    PostId      = x.PostID,
                    commentId   = x.CommentID,
                    commentText = x.CommentText,
                    parentId    = x.ParentId,
                    commentDate = x.CommentDate,
                    username    = x.Username,
                    ImgUrl      = x.ImgUrl
                }).FirstOrDefault();

                return(Json(new { error = false, result = model }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //Handle Error here..
                string exception = ex.Message.ToString();
            }

            return(Json(new { error = true }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public JsonResult addNewComment(commentDTO comment)
        {
            try
            {
                string userid   = User.Identity.Name;
                string username = dbContext.Users.Where(x => x.Email == userid).FirstOrDefault().Name;

                var _comment = new ScratchPad()
                {
                    ParentId    = comment.parentId,
                    MesgFrom    = "Reply",
                    MesgTo      = username,
                    CommentText = comment.commentText,
                    Username    = username,
                    CommentDate = DateTime.Now
                };

                context.ScratchPads.Add(_comment);
                context.SaveChanges();
                var model = context.sp_GetMessages(username: username, commentID: _comment.CommentID)
                            .Select(x => new commentViewModel
                {
                    commentId   = x.CommentID,
                    commentText = x.CommentText,
                    parentId    = x.ParentId,
                    commentDate = x.CommentDate,
                    username    = x.Username,
                    ImgUrl      = x.ImgUrl
                }).FirstOrDefault();

                return(Json(new { error = false, result = model }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //Handle Error here..
                string exception = ex.Message.ToString();
            }

            return(Json(new { error = true }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public commentViewModel AddComment(commentDTO comment)
        {
            var _comment = new Comment()
            {
                ParentId    = comment.parentId,
                CommentText = comment.commentText,
                Username    = comment.username,
                CommentDate = DateTime.Now
            };

            context.Comments.Add(_comment);
            context.SaveChanges();
            return(context.Comments.Where(x => x.CommentID == _comment.CommentID)
                   .Select(x => new commentViewModel
            {
                commentId = x.CommentID,
                commentText = x.CommentText,
                parentId = x.ParentId,
                commentDate = x.CommentDate,
                username = x.Username
            }).FirstOrDefault());
        }