public void Delete(UserRoleAssignmentCollection userRoleAssignments)
 {
     foreach (UserRoleAssignment ura in userRoleAssignments)
     {
         this.Delete(ura);
     }
 }
        /// <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
        }
 ///// <summary>
 ///// Adds the specified role,inserts the object role into the system.
 ///// </summary>
 ///// <param name="role">The role.</param>
 //public void Add(UserRoleAssignment userRoleAssignment)
 //{
 //    this.userRoleAssignmentDao.Insert(userRoleAssignment);
 //}
 /// <summary>
 /// Adds the specified roles,adding the Role objects into the RoleCollection.
 /// </summary>
 /// <param name="roles">The roles.</param>
 public void Add(UserRoleAssignmentCollection userRoleAssignments)
 {
     foreach (UserRoleAssignment assignment in userRoleAssignments)
         this.Add(assignment);
 }
 void PopulateDetails(UserRoleAssignmentCollection uras)
 {
     foreach(UserRoleAssignment ura in uras)
         this.PopulateDetails(ura);
 }