Exemple #1
0
        public IActionResult GetUserInfo([FromQuery] string userName)
        {
            UserInfoProfileReturn ret = new UserInfoProfileReturn();

            try
            {
                Claim idClaim = User.FindFirst("sub");
                ret = _userInfoDataService.GetUserProfileInfo(userName, idClaim?.Value);
                ret.IsActionSucceed = true;
                return(Ok(Json(ret)));
            }
            catch (System.Exception ex)
            {
                ret.IsActionSucceed = false;
                ret.ErrorInformation.UserInformation = ex.Message;
                return(Ok(Json(ret)));
            }
        }
Exemple #2
0
        public UserInfoProfileReturn GetUserProfileInfo(string userName, string currUserId)
        {
            UserInfoProfileReturn ret;
            var uInfo = _context.Set <UserInfo>().AsNoTracking().Select(p => new { Entity = p, p.ProfilePicture }).FirstOrDefault(p => p.Entity.UName == userName);

            if (uInfo == null)
            {
                ret = new UserInfoProfileReturn();
                ret.IsActionSucceed                  = false;
                ret.ErrorInformation.ErrorType       = ErrorType.NotFound;
                ret.ErrorInformation.UserInformation = "User not found!";
                return(ret);
            }
            var followEntity   = _context.SetChild <FollowInfo>().AsNoTracking().FirstOrDefault(p => p.FollowerId == currUserId && p.FollowedId == uInfo.Entity.AppUserId);
            var followedEntity = _context.SetChild <FollowInfo>().AsNoTracking().FirstOrDefault(p => p.FollowerId == uInfo.Entity.AppUserId && p.FollowedId == currUserId);
            var followState    = followEntity == null ? FollowState.Unfollowed : followEntity.FollowState;
            var followedState  = followedEntity == null ? FollowState.Unfollowed : followedEntity.FollowState;

            ret = new UserInfoProfileReturn()
            {
                Id                       = uInfo.Entity.Id,
                Status                   = uInfo.Entity.Status,
                AppUserId                = uInfo.Entity.AppUserId,
                AlphaColor               = uInfo.Entity.AlphaColor,
                Username                 = uInfo.Entity.UName,
                Name                     = uInfo.Entity.Name,
                TotalReputation          = _userCacheService.GetUserReputation(uInfo.Entity.AppUserId) ?? GetUserReputation(uInfo.Entity.AppUserId, 0),
                ProfileImageUrl          = uInfo.Entity.ProfilePicture.SmallPath,
                Surname                  = uInfo.Entity.Surname,
                InterestCount            = _userCacheService.GetUserInterestCount(uInfo.Entity.AppUserId) ?? GetUserInterestCount(uInfo.Entity.AppUserId, 60),
                FollowingCount           = _userFollowCacheService.GetUserFollowingCount(uInfo.Entity.AppUserId) ?? GetUserFollowingCount(uInfo.Entity.AppUserId, 60),
                FollowerCount            = _userFollowCacheService.GetUserFollowerCount(uInfo.Entity.AppUserId) ?? GetUserFollowerCount(uInfo.Entity.AppUserId, 60),
                FollowingState           = followState,
                CurrentUserFollowedState = followedState,
            };
            return(ret);
        }