Beispiel #1
0
        public FollowAsset FollowUnfollowAsset(int assetId, FollowActionType followActionType)
        {
            var user = GetValidUser();

            var asset = AssetBusiness.GetById(assetId);

            if (!asset.Enabled)
            {
                throw new BusinessException("Invalid asset.");
            }

            var followAsset = FollowAssetBusiness.Create(user.Id, assetId, followActionType);

            if (user.FollowedAssets != null)
            {
                if (followActionType == FollowActionType.Follow)
                {
                    user.FollowedAssets.Add(assetId);
                }
                else
                {
                    user.FollowedAssets.Remove(assetId);
                }

                SetUserToCache(user);
            }
            return(followAsset);
        }
Beispiel #2
0
 public Follow Create(int userId, FollowActionType actionType)
 {
     return(new Follow()
     {
         ActionType = actionType.Value,
         CreationDate = Data.GetDateTimeNow(),
         UserId = userId
     });
 }
Beispiel #3
0
        public FollowAdvisor Create(int userId, int advisorId, FollowActionType actionType)
        {
            using (var transaction = TransactionalDapperCommand)
            {
                var follow = FollowBusiness.Create(userId, actionType);
                transaction.Insert(follow);
                FollowAdvisor followAdvisor = new FollowAdvisor()
                {
                    Id           = follow.Id,
                    AdvisorId    = advisorId,
                    ActionType   = follow.ActionType,
                    UserId       = follow.UserId,
                    CreationDate = follow.CreationDate
                };
                transaction.Insert(followAdvisor);
                transaction.Commit();

                return(followAdvisor);
            }
        }
Beispiel #4
0
        public FollowAdvisor FollowUnfollowAdvisor(int advisorId, FollowActionType followActionType)
        {
            var user          = GetValidUser();
            var followAdvisor = FollowAdvisorBusiness.Create(user.Id, advisorId, followActionType);

            if (user.FollowedAdvisors != null)
            {
                if (followActionType == FollowActionType.Follow)
                {
                    user.FollowedAdvisors.Add(advisorId);
                }
                else if (user.FollowedAdvisors.Contains(advisorId))
                {
                    user.FollowedAdvisors.Remove(advisorId);
                }

                SetUserToCache(user);
            }
            if (user.FollowingUsers != null)
            {
                var advisorCache = GetUserFromCache(GetById(advisorId));
                if (advisorCache != null)
                {
                    if (followActionType == FollowActionType.Follow)
                    {
                        advisorCache.FollowingUsers.Add(user.Email);
                    }
                    else if (advisorCache.FollowingUsers.Contains(user.Email))
                    {
                        advisorCache.FollowingUsers.Remove(user.Email);
                    }

                    SetUserToCache(advisorCache);
                }
            }
            return(followAdvisor);
        }