예제 #1
0
        public Result CreateAttention(string userId, string attentionId)
        {
            if (CheckAttention(userId, attentionId))
            {
                return(Result.Error("关注关系已存在!"));
            }

            if (!ExistsUser(connection, null, userId))
            {
                return(Result.Error("当前用户不存在!"));
            }

            if (!ExistsUser(connection, null, attentionId))
            {
                return(Result.Error("关注用户不存在!"));
            }

            var sql   = "insert into T_UserAttentions(UserId,AttentionId) values(@UserId,@AttentionId)";
            var param = new { UserId = userId, AttentionId = attentionId };

            return(connection.Transaction("关注", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, userId);
                SnsUserHelper.UpdateCount(conn, trans, attentionId);
            }));
        }
예제 #2
0
        public Result RemoveFriend(string userId, string friendId)
        {
            if (!CheckFriend(userId, friendId))
            {
                return(Result.Error("好友关系不存在!"));
            }

            var sql   = "delete from T_UserFriends where UserId=@UserId and FriendId=@FriendId";
            var param = new { UserId = userId, FriendId = friendId };

            return(connection.Transaction("删除", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, userId);
            }));
        }
예제 #3
0
        public Result RemoveAttention(string userId, string attentionId)
        {
            if (!CheckAttention(userId, attentionId))
            {
                return(Result.Error("关注关系不存在!"));
            }

            var sql   = "delete from T_UserAttentions where UserId=@UserId and AttentionId=@AttentionId";
            var param = new { UserId = userId, AttentionId = attentionId };

            return(connection.Transaction("取消", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, userId);
                SnsUserHelper.UpdateCount(conn, trans, attentionId);
            }));
        }
예제 #4
0
        public Result CreateFriend(string userId, string friendId, bool isValidate, string requestMessage)
        {
            if (CheckFriend(userId, friendId, false))
            {
                return(Result.Error("好友关系已存在!"));
            }

            if (!ExistsUser(connection, null, userId))
            {
                return(Result.Error("当前用户不存在!"));
            }

            if (!ExistsUser(connection, null, friendId))
            {
                return(Result.Error("好友用户不存在!"));
            }

            if (isValidate && string.IsNullOrWhiteSpace(requestMessage))
            {
                return(Result.Error("验证消息不能为空!"));
            }

            var sql   = "insert into T_UserFriends(Id,UserId,FriendId,Status,RequestMessage,ResponseMessage,ResponseTime) values(@Id,@UserId,@FriendId,@Status,@RequestMessage,@ResponseMessage,@ResponseTime)";
            var param = new
            {
                Id              = Utils.NewGuid,
                UserId          = userId,
                FriendId        = friendId,
                Status          = isValidate ? "0" : "1",
                RequestMessage  = requestMessage,
                ResponseMessage = isValidate ? null : "无需验证",
                ResponseTime    = isValidate ? new DateTime?() : DateTime.Now
            };

            return(connection.Transaction("添加", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, userId);
            }));
        }
예제 #5
0
        public Result <Activity> PublishActivity(SnsUser user, ViewRange range, string content)
        {
            if (user == null || string.IsNullOrWhiteSpace(user.Id))
            {
                return(Result.Error <Activity>("当前用户不存在,请确认是否登录!"));
            }

            if (string.IsNullOrWhiteSpace(content))
            {
                return(Result.Error <Activity>("您不可以发布空内容!"));
            }

            var sql        = "insert into T_Activitys(Id,UserId,Content,CreateTime,ViewRange) values(@Id,@UserId,@Content,@CreateTime,@ViewRange)";
            var createTime = DateTime.Now;
            var param      = new
            {
                Id         = Utils.NewGuid,
                UserId     = user.Id,
                Content    = content,
                CreateTime = createTime,
                ViewRange  = (int)range
            };
            var activity = new Activity
            {
                Id         = param.Id,
                Content    = content,
                ViewRange  = range,
                CreateTime = createTime,
                User       = user,
                ViewCount  = 0,
                LikeCount  = 0
            };

            return(connection.Transaction("发布", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, user.Id);
            }, activity));
        }
예제 #6
0
        public Result AdoptFriend(string userId, string friendId, bool passed, string responseMessage)
        {
            if (!CheckFriend(userId, friendId))
            {
                return(Result.Error("好友关系不存在!"));
            }

            var sql   = "update T_UserFriends set Status=@Status,ResponseMessage=@ResponseMessage,ResponseTime=@ResponseTime where UserId=@UserId and FriendId=@FriendId";
            var param = new
            {
                Status          = passed ? "1" : "2",
                ResponseMessage = responseMessage,
                ResponseTime    = DateTime.Now,
                UserId          = userId,
                FriendId        = friendId
            };

            return(connection.Transaction("接受", (conn, trans) =>
            {
                conn.Execute(sql, param, trans);
                SnsUserHelper.UpdateCount(conn, trans, userId);
            }));
        }
예제 #7
0
 public void UpdateSnsCount(SnsUser user)
 {
     SnsUserHelper.UpdateCount(connection, user);
 }