Esempio n. 1
0
        public void AddUserRole(int portalId, int userId, int roleId, RoleStatus status, bool isOwner, DateTime effectiveDate, DateTime expiryDate)
        {
            UserInfo     user     = UserController.GetUserById(portalId, userId);
            UserRoleInfo userRole = GetUserRole(portalId, userId, roleId);

            if (userRole == null)
            {
                //Create new UserRole
                userRole = new UserRoleInfo
                {
                    UserID        = userId,
                    RoleID        = roleId,
                    PortalID      = portalId,
                    Status        = status,
                    IsOwner       = isOwner,
                    EffectiveDate = effectiveDate,
                    ExpiryDate    = expiryDate
                };
                provider.AddUserToRole(portalId, user, userRole);
                EventLogController.Instance.AddLog(userRole, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.USER_ROLE_CREATED);
            }
            else
            {
                userRole.Status        = status;
                userRole.IsOwner       = isOwner;
                userRole.EffectiveDate = effectiveDate;
                userRole.ExpiryDate    = expiryDate;
                provider.UpdateUserRole(userRole);
                EventLogController.Instance.AddLog(userRole, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.USER_ROLE_UPDATED);
            }

            //Remove the UserInfo and Roles from the Cache, as they have been modified
            DataCache.ClearUserCache(portalId, user.Username);
            Instance.ClearRoleCache(portalId);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a User to a Role
        /// </summary>
        /// <remarks>Overload adds Effective Date</remarks>
        /// <param name="PortalID">The Id of the Portal</param>
        /// <param name="UserId">The Id of the User</param>
        /// <param name="RoleId">The Id of the Role</param>
        /// <param name="EffectiveDate">The expiry Date of the Role membership</param>
        /// <param name="ExpiryDate">The expiry Date of the Role membership</param>
        public void AddUserRole(int PortalID, int UserId, int RoleId, DateTime EffectiveDate, DateTime ExpiryDate)
        {
            UserInfo     objUser     = UserController.GetUser(PortalID, UserId, false);
            UserRoleInfo objUserRole = GetUserRole(PortalID, UserId, RoleId);

            if (objUserRole == null)
            {
                //Create new UserRole
                objUserRole               = new UserRoleInfo();
                objUserRole.UserID        = UserId;
                objUserRole.RoleID        = RoleId;
                objUserRole.PortalID      = PortalID;
                objUserRole.EffectiveDate = EffectiveDate;
                objUserRole.ExpiryDate    = ExpiryDate;
                provider.AddUserToRole(PortalID, objUser, objUserRole);
            }
            else
            {
                objUserRole.EffectiveDate = EffectiveDate;
                objUserRole.ExpiryDate    = ExpiryDate;
                provider.UpdateUserRole(objUserRole);
            }
        }