示例#1
0
        public User GetValidUser()
        {
            var cacheKey = GetUserCacheKey(LoggedEmail);
            var user     = MemoryCache.Get <User>(cacheKey);

            if (user == null)
            {
                UserBusiness.EmailValidation(LoggedEmail);
                user = UserBusiness.GetByEmail(LoggedEmail);
                if (user == null)
                {
                    throw new NotFoundException("User cannot be found.");
                }

                Parallel.Invoke(() => user.FollowedAdvisors = FollowAdvisorBusiness.ListAdvisorsFollowed(user.Id),
                                () => user.FollowingUsers   = FollowAdvisorBusiness.ListFollowers(new int[] { user.Id }, true).Select(c => c.User.Email).ToList(),
                                () => user.FollowedAssets   = FollowAssetBusiness.ListAssetsFollowed(user.Id));

                SetUserToCache(user);
                return(user);
            }
            else
            {
                if (UserBusiness.IsValidAdvisor(user))
                {
                    user = MemoryCache.Get <DomainObjects.Advisor.Advisor>(cacheKey);
                }
                return(user);
            }
        }
示例#2
0
        public User GetUserFromCache(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(null);
            }

            var cacheKey = GetUserCacheKey(email);
            var user     = MemoryCache.Get <User>(cacheKey);

            if (user == null)
            {
                UserBusiness.EmailValidation(email);
                user = UserBusiness.GetByEmail(email);

                if (user != null)
                {
                    Parallel.Invoke(() => user.FollowedAdvisors = FollowAdvisorBusiness.ListAdvisorsFollowed(user.Id),
                                    () => user.FollowingUsers   = FollowAdvisorBusiness.ListFollowers(new int[] { user.Id }, true).Select(c => c.User.Email).ToList(),
                                    () => user.FollowedAssets   = FollowAssetBusiness.ListAssetsFollowed(user.Id));
                }
                SetUserToCache(user);
            }
            else if (UserBusiness.IsValidAdvisor(user))
            {
                user = MemoryCache.Get <DomainObjects.Advisor.Advisor>(cacheKey);
            }

            return(user);
        }
示例#3
0
        public new void Update(User user)
        {
            Data.Update(user);

            Parallel.Invoke(() => user.FollowedAdvisors = FollowAdvisorBusiness.ListAdvisorsFollowed(user.Id),
                            () => user.FollowingUsers   = FollowAdvisorBusiness.ListFollowers(new int[] { user.Id }, true).Select(c => c.User.Email).ToList(),
                            () => user.FollowedAssets   = FollowAssetBusiness.ListAssetsFollowed(user.Id));

            SetUserToCache(user);
        }