private void ManageUserRelationshipStatus(int userRelationshipId, RelationshipStatus newStatus)
        {
            UserRelationship userRelationship = VerifyUserRelationshipExist(userRelationshipId);

            if (userRelationship == null)
            {
                return;
            }

            //TODO - apply business rules - throw exception if newStatus requested is not allowed
            bool save = false;

            switch (newStatus)
            {
            case RelationshipStatus.None:
                save = true;
                break;

            case RelationshipStatus.Pending:
                save = true;
                break;

            case RelationshipStatus.Accepted:
                save = true;
                break;
            }

            if (save)
            {
                userRelationship.Status = newStatus;
                SaveUserRelationship(userRelationship);
            }
        }
Exemple #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Remove an existing UserRelationship Request
        /// </summary>
        /// <param name="userRelationshipId">UserRelationshipId of the UserRelationship</param>
        /// <remarks>
        /// UserRelationship record is physically removed.
        /// </remarks>
        /// -----------------------------------------------------------------------------
        public void RemoveUserRelationship(int userRelationshipId)
        {
            UserRelationship userRelationship = VerifyUserRelationshipExist(userRelationshipId);

            if (userRelationship != null)
            {
                DeleteUserRelationship(userRelationship);
            }
        }
Exemple #3
0
        private UserRelationship VerifyUserRelationshipExist(int userRelationshipId)
        {
            UserRelationship userRelationship = GetUserRelationship(userRelationshipId);

            if (userRelationship == null)
            {
                throw new UserRelationshipDoesNotExistException(
                          Localization.GetExceptionMessage("UserRelationshipDoesNotExistError",
                                                           "UserRelationshipID '{0}' does not exist.", userRelationshipId));
            }

            return(userRelationship);
        }
Exemple #4
0
        public UserRelationship GetUserRelationship(UserInfo user, UserInfo relatedUser, Relationship relationship)
        {
            UserRelationship userRelationship = null;

            if (relationship != null)
            {
                userRelationship = CBO.FillObject <UserRelationship>(_dataService.GetUserRelationship(user.UserID, relatedUser.UserID,
                                                                                                      relationship.RelationshipId,
                                                                                                      GetRelationshipType(
                                                                                                          relationship.RelationshipTypeId).
                                                                                                      Direction));
            }
            return(userRelationship);
        }
Exemple #5
0
        private void ClearUserCache(UserRelationship userRelationship)
        {
            //Get Portal
            PortalSettings settings = PortalController.GetCurrentPortalSettings();

            if (settings != null)
            {
                //Get User
                UserInfo user = UserController.GetUserById(settings.PortalId, userRelationship.UserId);

                if (user != null)
                {
                    DataCache.ClearUserCache(settings.PortalId, user.Username);
                }
            }
        }
Exemple #6
0
        public void DeleteUserRelationship(UserRelationship userRelationship)
        {
            Requires.NotNull("userRelationship", userRelationship);

            _dataService.DeleteUserRelationship(userRelationship.UserRelationshipId);

            //log event
            string logContent =
                string.Format(Localization.GetString("UserRelationship_Deleted", Localization.GlobalResourceFile),
                              userRelationship.UserRelationshipId, userRelationship.UserId,
                              userRelationship.RelatedUserId);

            AddLog(logContent);

            //cache clear
            ClearUserCache(userRelationship);
        }
Exemple #7
0
        public void SaveUserRelationship(UserRelationship userRelationship)
        {
            Requires.NotNull("userRelationship", userRelationship);

            string localizationKey = (userRelationship.UserRelationshipId == Null.NullInteger)
                                         ? "UserRelationship_Added"
                                         : "UserRelationship_Updated";

            userRelationship.UserRelationshipId = _dataService.SaveUserRelationship(userRelationship,
                                                                                    UserController.GetCurrentUserInfo().
                                                                                    UserID);

            //log event
            string logContent = string.Format(Localization.GetString(localizationKey, Localization.GlobalResourceFile),
                                              userRelationship.UserRelationshipId, userRelationship.UserId,
                                              userRelationship.RelatedUserId);

            AddLog(logContent);

            //cache clear
            ClearUserCache(userRelationship);
        }
        public void RelationshipController_DeleteUserRelationship_Calls_EventLogController_AddLog()
        {
            //Arrange
            var mockEventLogController = new Mock<IEventLogController>();
            mockEventLogController.Setup(c => c.AddLog(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<EventLogController.EventLogType>()));
            CreateLocalizationProvider();

            var relationshipController = CreateRelationshipController(mockEventLogController);
            var userRelationship = new UserRelationship
                                        {
                                            UserRelationshipId = Constants.SOCIAL_UserRelationshipIDUser10User11,
                                            UserId = Constants.USER_ElevenId,
                                            RelatedUserId = Constants.USER_TenId
                                        };


            //Act
            relationshipController.DeleteUserRelationship(userRelationship);

            //Assert
            var logContent = string.Format(Constants.LOCALIZATION_UserRelationship_Deleted, Constants.SOCIAL_UserRelationshipIDUser10User11, Constants.USER_ElevenId, Constants.USER_TenId);
            mockEventLogController.Verify(e => e.AddLog("Message", logContent, EventLogController.EventLogType.ADMIN_ALERT));
        }
        public void DeleteUserRelationship(UserRelationship userRelationship)
        {
            Requires.NotNull("userRelationship", userRelationship);

            _dataService.DeleteUserRelationship(userRelationship.UserRelationshipId);

            //log event
            string logContent =
                string.Format(Localization.GetString("UserRelationship_Deleted", Localization.GlobalResourceFile),
                              userRelationship.UserRelationshipId, userRelationship.UserId,
                              userRelationship.RelatedUserId);
            AddLog(logContent);

            //cache clear
            ClearUserCache(userRelationship);
        }
Exemple #10
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Initiate an UserRelationship Request
        /// </summary>
        /// <param name="initiatingUser">UserInfo of the user initiating the request</param>
        /// <param name="targetUser">UserInfo of the user being solicited for initiating the request</param>
        /// <param name="relationship">Relationship to associate this request to (Portal-Level Relationship or User-Level Relationship)</param>
        /// <remarks>
        /// If all conditions are met UserRelationship object belonging to Initiating User is returned.
        /// </remarks>
        /// <returns>
        /// Relationship object belonging to the initiating user
        /// </returns>
        /// <exception cref="UserRelationshipBlockedException">Target user has Blocked any relationship request from Initiating user</exception>
        /// <exception cref="InvalidRelationshipTypeException">Relationship type does not exist</exception>
        /// -----------------------------------------------------------------------------
        public UserRelationship InitiateUserRelationship(UserInfo initiatingUser, UserInfo targetUser,
                                                         Relationship relationship)
        {
            Requires.NotNull("user1", initiatingUser);
            Requires.NotNull("user2", targetUser);
            Requires.NotNull("relationship", relationship);

            Requires.PropertyNotNegative("user1", "UserID", initiatingUser.UserID);
            Requires.PropertyNotNegative("user2", "UserID", targetUser.UserID);

            Requires.PropertyNotNegative("user1", "PortalID", initiatingUser.PortalID);
            Requires.PropertyNotNegative("user2", "PortalID", targetUser.PortalID);

            Requires.PropertyNotNegative("relationship", "RelationshipId", relationship.RelationshipId);

            //cannot be same user
            if (initiatingUser.UserID == targetUser.UserID)
            {
                throw new UserRelationshipForSameUsersException(
                          Localization.GetExceptionMessage("UserRelationshipForSameUsersError",
                                                           "Initiating and Target Users cannot have same UserID '{0}'.",
                                                           initiatingUser.UserID));
            }

            //users must be from same portal
            if (initiatingUser.PortalID != targetUser.PortalID)
            {
                throw new UserRelationshipForDifferentPortalException(
                          Localization.GetExceptionMessage("UserRelationshipForDifferentPortalError",
                                                           "Portal ID '{0}' of Initiating User is different from Portal ID '{1}' of Target  User.",
                                                           initiatingUser.PortalID, targetUser.PortalID));
            }

            //check for existing UserRelationship record
            UserRelationship existingRelationship = GetUserRelationship(initiatingUser, targetUser, relationship);

            if (existingRelationship != null)
            {
                throw new UserRelationshipExistsException(Localization.GetExceptionMessage(
                                                              "UserRelationshipExistsError",
                                                              "Relationship already exists for Initiating User '{0}' Target User '{1}' RelationshipID '{2}'.",
                                                              initiatingUser.UserID, targetUser.UserID, relationship.RelationshipId));
            }

            //no existing UserRelationship record found


            //use Relationship DefaultResponse as status
            RelationshipStatus status = relationship.DefaultResponse;

            //check if there is a custom relationship status setting for the user.
            //TODO - Is this check only applicable for portal or host list
            //if (relationship.IsPortalList || relationship.IsHostList)
            {
                UserRelationshipPreference preference = GetUserRelationshipPreference(targetUser.UserID,
                                                                                      relationship.RelationshipId);
                if (preference != null)
                {
                    status = preference.DefaultResponse;
                }
            }

            if (status == RelationshipStatus.None)
            {
                status = RelationshipStatus.Pending;
            }

            var userRelationship = new UserRelationship
            {
                UserRelationshipId = Null.NullInteger,
                UserId             = initiatingUser.UserID,
                RelatedUserId      = targetUser.UserID,
                RelationshipId     = relationship.RelationshipId,
                Status             = status
            };

            SaveUserRelationship(userRelationship);

            return(userRelationship);
        }
        public void SaveUserRelationship(UserRelationship userRelationship)
        {
            Requires.NotNull("userRelationship", userRelationship);

            string localizationKey = (userRelationship.UserRelationshipId == Null.NullInteger)
                                         ? "UserRelationship_Added"
                                         : "UserRelationship_Updated";

            userRelationship.UserRelationshipId = _dataService.SaveUserRelationship(userRelationship,
                                                                                    UserController.GetCurrentUserInfo().
                                                                                        UserID);

            //log event            
            string logContent = string.Format(Localization.GetString(localizationKey, Localization.GlobalResourceFile),
                                              userRelationship.UserRelationshipId, userRelationship.UserId,
                                              userRelationship.RelatedUserId);
            AddLog(logContent);

            //cache clear
            ClearUserCache(userRelationship);
        }
        public void RelationshipController_SaveUserRelationship_Calls_EventLogController_AddLog()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.SaveUserRelationship(It.IsAny<UserRelationship>(), It.IsAny<int>()))
                                .Returns(Constants.SOCIAL_UserRelationshipIDUser10User11);
            var mockEventLogController = new Mock<IEventLogController>();
            mockEventLogController.Setup(c => c.AddLog(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<EventLogController.EventLogType>()));
            CreateLocalizationProvider();

            var relationshipController = new RelationshipControllerImpl(mockDataService.Object, mockEventLogController.Object);
            var userRelationship = new UserRelationship
                                            {
                                                UserRelationshipId = Constants.SOCIAL_UserRelationshipIDUser10User11,
                                                UserId = Constants.USER_ElevenId,
                                                RelatedUserId = Constants.USER_TenId
                                            };


            //Act
            relationshipController.SaveUserRelationship(userRelationship);

            //Assert
            var logContent = string.Format(Constants.LOCALIZATION_UserRelationship_Updated, Constants.SOCIAL_UserRelationshipIDUser10User11, Constants.USER_ElevenId, Constants.USER_TenId);
            mockEventLogController.Verify(e => e.AddLog("Message", logContent, EventLogController.EventLogType.ADMIN_ALERT));
        }
        public void RelationshipController_SaveUserRelationship_Calls_DataService()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var relationshipController = CreateRelationshipController(mockDataService);
            var userRelationship = new UserRelationship()
                                            {
                                                UserRelationshipId = Constants.SOCIAL_UserRelationshipIDUser10User11
                                            };

            //Act
            relationshipController.SaveUserRelationship(userRelationship);

            //Assert
            mockDataService.Verify(d => d.SaveUserRelationship(userRelationship, It.IsAny<int>()));
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Initiate an UserRelationship Request
        /// </summary>
        /// <param name="initiatingUser">UserInfo of the user initiating the request</param>        
        /// <param name="targetUser">UserInfo of the user being solicited for initiating the request</param>        
        /// <param name="relationship">Relationship to associate this request to (Portal-Level Relationship or User-Level Relationship)</param>        
        /// <remarks>
        /// If all conditions are met UserRelationship object belonging to Initiating User is returned.
        /// </remarks>
        /// <returns>
        /// Relationship object belonging to the initiating user
        /// </returns>
        /// <exception cref="UserRelationshipBlockedException">Target user has Blocked any relationship request from Initiating user</exception>
        /// <exception cref="InvalidRelationshipTypeException">Relationship type does not exist</exception>
        /// -----------------------------------------------------------------------------
        public UserRelationship InitiateUserRelationship(UserInfo initiatingUser, UserInfo targetUser,
                                                         Relationship relationship)
        {
            Requires.NotNull("user1", initiatingUser);
            Requires.NotNull("user2", targetUser);
            Requires.NotNull("relationship", relationship);

            Requires.PropertyNotNegative("user1", "UserID", initiatingUser.UserID);
            Requires.PropertyNotNegative("user2", "UserID", targetUser.UserID);

            Requires.PropertyNotNegative("user1", "PortalID", initiatingUser.PortalID);
            Requires.PropertyNotNegative("user2", "PortalID", targetUser.PortalID);

            Requires.PropertyNotNegative("relationship", "RelationshipId", relationship.RelationshipId);

            //cannot be same user
            if (initiatingUser.UserID == targetUser.UserID)
            {
                throw new UserRelationshipForSameUsersException(
                    Localization.GetExceptionMessage("UserRelationshipForSameUsersError",
                                                     "Initiating and Target Users cannot have same UserID '{0}'.",
                                                     initiatingUser.UserID));
            }

            //users must be from same portal
            if (initiatingUser.PortalID != targetUser.PortalID)
            {
                throw new UserRelationshipForDifferentPortalException(
                    Localization.GetExceptionMessage("UserRelationshipForDifferentPortalError",
                                                     "Portal ID '{0}' of Initiating User is different from Portal ID '{1}' of Target  User.",
                                                     initiatingUser.PortalID, targetUser.PortalID));
            }

            //check for existing UserRelationship record
            UserRelationship existingRelationship = GetUserRelationship(initiatingUser, targetUser, relationship);
            if (existingRelationship != null)
            {
                throw new UserRelationshipExistsException(Localization.GetExceptionMessage(
                    "UserRelationshipExistsError",
                    "Relationship already exists for Initiating User '{0}' Target User '{1}' RelationshipID '{2}'.",
                    initiatingUser.UserID, targetUser.UserID, relationship.RelationshipId));
            }

            //no existing UserRelationship record found 


            //use Relationship DefaultResponse as status
            RelationshipStatus status = relationship.DefaultResponse;

            //check if there is a custom relationship status setting for the user. 
            //TODO - Is this check only applicable for portal or host list
            //if (relationship.IsPortalList || relationship.IsHostList)
            {
                UserRelationshipPreference preference = GetUserRelationshipPreference(targetUser.UserID,
                                                                                      relationship.RelationshipId);
                if (preference != null)
                {
                    status = preference.DefaultResponse;
                }
            }

            if (status == RelationshipStatus.None)
            {
                status = RelationshipStatus.Pending;
            }

            var userRelationship = new UserRelationship
                                       {
                                           UserRelationshipId = Null.NullInteger,
                                           UserId = initiatingUser.UserID,
                                           RelatedUserId = targetUser.UserID,
                                           RelationshipId = relationship.RelationshipId,
                                           Status = status
                                       };

            SaveUserRelationship(userRelationship);

            return userRelationship;
        }
        public void RelationshipController_DeleteUserRelationship_Calls_DataService()
        {
            //Arrange
            var mockDataService = CreateMockDataServiceWithRelationshipTypes();
            var relationshipController = CreateRelationshipController(mockDataService);
            var userRelationship = new UserRelationship()
                                    {
                                        UserRelationshipId = Constants.SOCIAL_UserRelationshipIDUser10User11
                                    };

            //Act
            relationshipController.DeleteUserRelationship(userRelationship);

            //Assert
            mockDataService.Verify(d => d.DeleteUserRelationship(Constants.SOCIAL_UserRelationshipIDUser10User11));
        }
 internal RelationshipEventArgs(UserRelationship relationship, int portalId)
 {
     Relationship = relationship;
     PortalID = portalId;
 }
        private void ClearUserCache(UserRelationship userRelationship)
        {
            //Get Portal
            PortalSettings settings = PortalController.GetCurrentPortalSettings();

            if (settings != null)
            {
                //Get User
                UserInfo user = UserController.GetUserById(settings.PortalId, userRelationship.UserId);

                if (user != null)
                {
                    DataCache.ClearUserCache(settings.PortalId, user.Username);
                }

                //Get Related User
                UserInfo relatedUser = UserController.GetUserById(settings.PortalId, userRelationship.RelatedUserId);

                if (relatedUser != null)
                {
                    DataCache.ClearUserCache(settings.PortalId, relatedUser.Username);
                }
            }
        }