Пример #1
0
        public int AddCommentsPlus(int commentId, int postsId, string title)
        {
            PostsRepository repository = new PostsRepository();

            Entity.m_PostsCommentsRecords model = new Entity.m_PostsCommentsRecords();
            model.CommentId   = commentId;
            model.AppendTime  = DateTime.Now;
            model.RecordsType = 1;
            model.UserId      = Framework.Core.Transform.GetInt(HttpContext.Session.GetString("UserId"), 0);
            //消息通知
            Entity.m_Message message = new Entity.m_Message();
            message.AppendUserId = model.UserId;
            message.Contents     = Common.MessageHtml.GetMessageContent(HttpContext.Session.GetString("NickName"), postsId, title, 14);
            message.IsRead       = false;
            message.MessageType  = 14;
            message.ObjId        = postsId;
            message.PostDate     = DateTime.Now;
            message.UserId       = repository.GetPostsCommentsByUserId(commentId);

            int resultCount = repository.AddCommentsRecordsByPlus(model, message);

            //消息推送
            if (resultCount > 0)
            {
                Extensions.SignalRCore.PushUserMessage(message.UserId.ToString(), _messageHubContext);
            }
            return(resultCount);
        }
Пример #2
0
        /// <summary>
        /// 添加评论点赞
        /// </summary>
        /// <param name="model"></param>
        /// <returns>-1 表示取消点赞 1表示增加点赞 0表示异常</returns>
        public int AddCommentsRecordsByPlus(Entity.m_PostsCommentsRecords model, Entity.m_Message message)
        {
            int result = 0;
            //加载是否已经存在点赞记录
            int queryCount = _dbContext.m_PostsCommentsRecords.Where(m => m.CommentId == model.CommentId && m.UserId == model.UserId).Count();

            using (var tran = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    if (queryCount > 0)
                    {
                        _dbContext.MangoRemove <Entity.m_PostsCommentsRecords>(m => m.CommentId == model.CommentId && m.UserId == model.UserId);
                        //
                        _dbContext.MangoUpdate <Entity.m_PostsComments>(m => m.Plus == m.Plus - 1, m => m.CommentId == model.CommentId);
                        tran.Commit();
                        result = -1;
                    }
                    else
                    {
                        //不存在则新增点赞记录
                        _dbContext.Add(message);
                        _dbContext.SaveChanges();
                        //
                        _dbContext.Add(model);
                        _dbContext.SaveChanges();
                        //
                        _dbContext.MangoUpdate <Entity.m_PostsComments>(m => m.Plus == m.Plus + 1, m => m.CommentId == model.CommentId);
                        tran.Commit();
                        result = 1;
                    }
                }
                catch
                {
                    tran.Rollback();
                    result = 0;
                }
            }

            return(result);
        }