Esempio n. 1
0
        //public async Task<UserDto> GetUserDetails(Guid id)
        //{
        //    UserDto user = new UserDto();
        //    using (IUserService userSvc = new UserService())
        //    {
        //      UserDto userDto=  await userSvc.GetAll().Where(m => m.Id == id).Select(m =>new UserDto()
        //        {
        //          CreateTime = m.CreatTime,
        //            Email = m.Email,
        //            FansCount = m.FansCount,
        //            FoucusCount = m.FoucusCount,
        //            ImagePath = m.ImagePath,
        //            SiteName = m.SiteName,
        //            UserId = m.Id
        //        }).FirstOrDefaultAsync();
        //    }
        //    using (ArticleService articleSvc=new ArticleService())
        //    {
        //       List<Article> articles = articleSvc.GetAll().Where(m => m.UserId == id).ToList();
        //        foreach (Article article in articles)
        //        {

        //        }
        //    }
        //}

        /// <summary>
        /// 是否已经关注
        /// </summary>
        /// <param name="userId">关注者ID</param>
        /// <param name="focusUserId">被关注者ID</param>
        /// <returns></returns>
        public async Task <bool> IsFocused(Guid userId, Guid focusUserId)
        {
            using (IFanService fanSvc = new FanService())
            {
                return(await fanSvc.GetAll().Where(m => m.UserId == userId && m.FocusUserId == focusUserId).AnyAsync());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 关注用户
        /// </summary>
        /// <param name="userId">关注者ID</param>
        /// <param name="focusUserId">被关注者ID</param>
        /// <returns></returns>
        public async Task FocusUser(Guid userId, Guid focusUserId)
        {
            int userFansCount;
            int userFocusCount;
            int focusUserFansCount;
            int focusUserFocusCount;

            using (IFanService fanSvc = new FanService())
            {
                Fans fans = new Fans
                {
                    UserId      = userId,
                    FocusUserId = focusUserId
                };
                await fanSvc.CreatAsync(fans);

                userFocusCount = await fanSvc.GetAll().Where(m => m.UserId == userId).CountAsync();               //用户关注数量

                focusUserFocusCount = await fanSvc.GetAll().Where(m => m.UserId == focusUserId).CountAsync();     //被关注者关注数量

                userFansCount = await fanSvc.GetAll().Where(m => m.FocusUserId == userId).CountAsync();           //用户粉丝数量

                focusUserFansCount = await fanSvc.GetAll().Where(m => m.FocusUserId == focusUserId).CountAsync(); //被关注者粉丝数量
            }
            using (IUserService userSve = new UserService())
            {
                User user = await userSve.GetOneByIdAsync(userId);

                user.FansCount  = userFansCount;
                user.FocusCount = userFocusCount;
                await userSve.EditAsync(user);

                User focusUser = await userSve.GetOneByIdAsync(focusUserId);

                focusUser.FansCount  = focusUserFansCount;
                focusUser.FocusCount = focusUserFocusCount;
                await userSve.EditAsync(focusUser);
            }
        }