/// <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
        }
 public void Delete(UserRoleAssignment userRoleAssignment)
 {
     this.userRoleAssignmentDao.Delete(userRoleAssignment);
 }
 public void Add(UserRoleAssignment userRoleAssignment)
 {
     this.userRoleAssignmentDao.Add(userRoleAssignment);
 }
        void PopulateDetails(UserRoleAssignment ura)
        {
            if(ura == null) return;

            ura.Application = appSvc.Get(ura.Application.Id);
            ura.Role = roleSvc.Get(ura.Role.Id);
            ura.User = userSvc.Get(ura.User.Id);
        }
 /// <summary>
 /// Adds the specified role,inserts the object role into the system.
 /// </summary>
 /// <param name="role">The role.</param>
 public void Save(UserRoleAssignment userRoleAssignment)
 {
     this.Save(userRoleAssignment.Application, userRoleAssignment.User, userRoleAssignment.Role, userRoleAssignment.SecurableObject);
 }
        public void Save(Application application, User user, Role role, SecurableObject securableObject)
        {
            UserRoleAssignmentDao uraDao = new UserRoleAssignmentDao();
            //long securableObjectId = new SecurableObjectDao().GetId(securableObject.SecurableObjectGuid);
            UserRoleAssignment ura = uraDao.Get(application, user, securableObject);

            if (ura == null)
            {
                ura = new UserRoleAssignment()
                {
                    Application = application,
                    User = user,
                    Role = role,
                    SecurableObjectId = securableObject.Id
                };

                uraDao.Add(ura);
            }
            else
            {
                ura.Role = role;
                uraDao.Update(ura);
            }
        }