Beispiel #1
0
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param name="followerId">关注者ID</param>
        /// <param name="unFollowPerId">取消关注者ID</param>
        /// <returns></returns>
        public async Task<bool> UnFollowAsync(long followerId, long unFollowPerId)
        {
            PersonXPersonHandler pxpHandler = new PersonXPersonHandler(_dbContext);

            //1. 检查关注人的关注名单是否已经关注了。
            PersonXPerson pxp = await pxpHandler.Fetch(x => x.FollowerID == followerId && x.FollowingID == unFollowPerId).SingleOrDefaultAsync();

            //2. 如果存在记录,则删除记录,取消关注。
            if(pxp != null)
            {
                pxpHandler.MarkAsDeleted(pxp);

                return await pxpHandler.SaveChangesAsync() > 0;
            }

            return true;
        }
Beispiel #2
0
        /// <summary>
        /// 关注
        /// </summary>
        /// <param name="followerId">关注者ID</param>
        /// <param name="followingId">被关注者ID</param>
        /// <returns></returns>
        public async Task<bool> FollowAsync(long followerId, long followingId)
        {
            GroupHandler groupHandler = new GroupHandler(_dbContext);
            PersonXPersonHandler pxpHandler = new PersonXPersonHandler(_dbContext);

            //1. 检查被关注人黑名单是否存在关注人,若已拉黑,则无法关注。
            Group blackGroup = await groupHandler.Include(x => x.GroupMembers).SingleOrDefaultAsync(x => x.PersonID == followingId && x.Type == GroupType.BlackList);
            
            if(blackGroup != null && blackGroup.GroupMembers.Count > 0)
            {
                bool isInGroupMember = blackGroup.GroupMembers.Select(x => x.PersonID).Contains(followerId);

                if(isInGroupMember)
                {
                    throw new DisplayableException("由于用户设置,你无法关注。");
                }
            }

            //2. 检查关注人的关注名单是否已经关注了。
            bool isFollow = await pxpHandler.Fetch(x => x.FollowerID == followerId && x.FollowingID == followingId).SingleOrDefaultAsync() != null;

            //3. 如果未关注则添加纪录。
            if(!isFollow)
            {
                PersonXPerson pxp = new PersonXPerson()
                {
                    FollowerID = followerId,
                    FollowingID = followingId
                };
                pxpHandler.Add(pxp);

                return await SaveChangesAsync() > 0;
            }

            return true;
        }