Ejemplo n.º 1
0
        /// <summary>
        /// 删除帖子
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Response DeletePost(int id)
        {
            if (id == 0)
            {
                throw new ArgumentNullException(nameof(id));
            }
            var response = new Response();

            using (var tran = DbBase.GetTransaction())
            {
                //删除帖子
                var r1 = DbBase.Delete <Posts>(id);
                //删除评论
                var r2 = DbBase.DeleteMany <Comment>().Where(p => p.PostId == id).Execute();

                tran.Complete();
                if (IsUpdateSuccess(r1))
                {
                    response.IsSuccess = true;
                    response.Message   = "操作成功";
                    return(response);
                }
            }
            response.Message = "操作失败";
            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据用户ID删除消息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Response DeleteAllMessages(int userId)
        {
            var response = new Response();
            var result   = DbBase.DeleteMany <Message>().Where(p => p.ToId == userId).Execute();

            if (IsUpdateSuccess(result))
            {
                response.IsSuccess = true;
                response.Message   = "删除成功";
                return(response);
            }
            response.Message = "删除失败";
            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 删除一条消息
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Response DeleteOneMessage(int messageId, int userId)
        {
            var response = new Response();
            //这里传用户ID主要是验证:如果是属性他的消息才可以删除
            var result = DbBase.DeleteMany <Message>().Where(p => p.Id == messageId && p.ToId == userId).Execute();

            if (IsUpdateSuccess(result))
            {
                response.IsSuccess = true;
                response.Message   = "删除成功";
                return(response);
            }
            response.Message = "删除失败";
            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 关注或取消
        /// </summary>
        /// <param name="likeuserid"></param>
        /// <param name="ok"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Response AddOrRemoveLike(int likeuserid, bool ok, int userId)
        {
            var response = new Response();
            var W_Users  = DbBase.SingleOrDefaultById <W_Users>(userId);

            if (W_Users == null)
            {
                response.Message = "非法操作";
                return(response);
            }
            using (var tran = DbBase.GetTransaction())
            {
                if (!ok)
                {
                    W_Users.LikeNum--;
                    DbBase.DeleteMany <AsterLikes>().Where(p => p.LikeUserId == likeuserid && p.UserId == userId).Execute();
                }
                else
                {
                    W_Users.LikeNum++;
                    DbBase.Insert(new AsterLikes
                    {
                        LikeUserId = likeuserid,
                        UserId     = userId
                    });
                }
                var result = DbBase.UpdateMany <W_Users>().OnlyFields(p => p.LikeNum).Where(p => p.Id == userId).Execute(W_Users);
                tran.Complete();
                if (IsUpdateSuccess(result))
                {
                    response.IsSuccess = true;
                    response.Message   = "操作成功";
                    return(response);
                }
            }
            response.Message = "操作失败";

            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加或减少赞
        /// </summary>
        /// <param name="commentId">评论Id</param>
        /// <param name="ok"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Response AddOrRemoveLike(int commentId, bool ok, int userId)
        {
            var response = new Response();
            var comment  = DbBase.SingleOrDefaultById <Comment>(commentId);

            if (comment == null)
            {
                response.Message = "非法操作";
                return(response);
            }
            using (var tran = DbBase.GetTransaction())
            {
                if (ok)
                {
                    comment.IsPraise--;
                    DbBase.DeleteMany <ArticleLikes>().Where(p => p.CommentId == commentId && p.UserId == userId).Execute();
                }
                else
                {
                    comment.IsPraise++;
                    DbBase.Insert(new ArticleLikes
                    {
                        CommentId = commentId,
                        UserId    = userId
                    });
                }
                var result = DbBase.UpdateMany <Comment>().OnlyFields(p => p.IsPraise).Where(p => p.Id == commentId).Execute(comment);
                tran.Complete();
                if (IsUpdateSuccess(result))
                {
                    response.IsSuccess = true;
                    response.Message   = "操作成功";
                    return(response);
                }
            }
            response.Message = "操作失败";

            return(response);
        }