/// <summary>
        /// Saves the associate rights to role.
        /// </summary>
        /// <param name="role">The role.</param>
        /// <param name="rightIds">The right ids.</param>
        public void SaveAssociateSystemRoleToUsers([DataBind("role")]Role role, [DataBind("user.IsGranted")]int[] userIds)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            IUserRoleAssignmentSvc userRoleAssignmentSvc = GatekeeperFactory.UserRoleAssignmentSvc;

            //Gets role of a specified roleId.

            role = GatekeeperFactory.RoleSvc.Get(role.Id);

            //Gets application of a specified role.
            Application application = GatekeeperFactory.ApplicationSvc.Get(role.Application.Id);

            //Gets UserRoleAssignmentCollection of a specified role.

            UserRoleAssignmentCollection existingUserRoleAssignments = userRoleAssignmentSvc.Get(application,role,application.Guid);

            UserRoleAssignmentCollection selectedUserRoleAssignments = new UserRoleAssignmentCollection();

            SecurableObject securableobject = GatekeeperFactory.SecurableObjectSvc.Get(application.Guid);

            foreach (int userId in userIds)
            {
                UserRoleAssignment ura = new UserRoleAssignment()
                {
                    User = new User() { Id = userId },
                    Application = application,
                    SecurableObjectId = securableobject.Id,
                    //SecurableObjectType = new SecurableObjectType() { Id=application.SecurableObjectType.Id},
                    Role=role

              };

                selectedUserRoleAssignments.Add(ura);

            }

            UserRoleAssignmentCollection newRoleUserAssignments = new UserRoleAssignmentCollection();

            UserRoleAssignmentCollection deletedRoleUserAssignments = new UserRoleAssignmentCollection();

            foreach(UserRoleAssignment existingUra in existingUserRoleAssignments)
            {
                if (!selectedUserRoleAssignments.Contains(existingUra))
                    deletedRoleUserAssignments.Add(existingUra);

            }

            foreach (UserRoleAssignment selectedUra in selectedUserRoleAssignments)
            {
                if (!existingUserRoleAssignments.Contains(selectedUra))
                    newRoleUserAssignments.Add(selectedUra);

            }

            //Adds newUserRoleAssignments into the system.
            userRoleAssignmentSvc.Add(newRoleUserAssignments);

            //Deletes UserRoleAssignment from the system.
            userRoleAssignmentSvc.Delete(deletedRoleUserAssignments);

            Hashtable args = new Hashtable();
            args["roleId"] = role.Id;

            this.RedirectToAction("DisplayUsersBySystemRole", args);

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }