Example #1
0
        public User SaveUser(User user, bool rolePermission, bool bRole)
        {
            int userId = manager.SaveUserBasicInfo(user.UserId, user.UserName, user.EmpName, user.Password, user.Mobile, user.EmployeeId, user.IsActive);

            user.UserId = userId;
            if (bRole)
            {
                manager.DeleteUserRoleByRoleId(userId);
                for (int i = 0; i < user.UserRoleCount; i++)
                {
                    Role role = user[i, "notUse"];
                    manager.SaveUserRole(userId, role.RoleId);
                }
            }
            if (rolePermission)
            {
                for (int i = 0; i < user.UserRoleCount; i++)
                {
                    Role userRolePermission = user[i, "notUser"];
                    manager.DeleteUserRolePermissionByUserRoleId(userId, userRolePermission.RoleId);
                }

                for (int i = 0; i < user.UserRolePermissionCount; i++)
                {
                    UserRolePermission userRolePermission = user[i];

                    manager.SaveUserRolePermission(user.UserId, userRolePermission.Permission.PermissionId,
                                                   userRolePermission.Role.RoleId);
                }
            }
            return(user);
        }
Example #2
0
        public bool HaveRolePermission(Role role, Permission permission)
        {
            UserRolePermission rolePermission = new UserRolePermission();

            rolePermission.Permission = permission;
            rolePermission.Role       = role;
            return(userRolePermissions.HavePermission(rolePermission));
        }
Example #3
0
        public void AddPermission(Permission permission)
        {
            UserRolePermission rolePermission = new UserRolePermission();

            rolePermission.Permission = permission;
            rolePermission.Role       = Roles.DefaultRoles.AllPermission;
            AddRolePermission(rolePermission);
        }
Example #4
0
 public void AddRolePermission(UserRolePermission permission)
 {
     if (HavePermission(permission))
     {
         return;
     }
     permissions.Add(permission);
 }
Example #5
0
 public void AddPermission(Permission permission, Role role)
 {
     if (role.Permissions.HavePermission(permission))
     {
         UserRolePermission userRolePermission = new UserRolePermission();
         userRolePermission.Permission = permission;
         userRolePermission.Role       = role;
         //if (!userRoles.HaveRole(role))
         //{
         //    userRoles.AddRole(role);
         //}
         userRolePermissions.AddRolePermission(userRolePermission);
     }
 }
Example #6
0
        public RolePermissionCollection GetPermissionsByRole(Role role)
        {
            RolePermissionCollection rolePermissions = new RolePermissionCollection();

            for (int i = 0; i < permissions.Count; i++)
            {
                UserRolePermission rolePermission = permissions[i];
                if (rolePermission.Role.Equals(role))
                {
                    rolePermissions.AddPermission(rolePermission.Permission);
                }
            }
            return(rolePermissions);
        }
Example #7
0
 public void DeleteByRole(Role role)
 {
     for (int i = 0; i < permissions.Count;)
     {
         UserRolePermission userRolePermission = permissions[i];
         if (userRolePermission.Role.Equals(role))
         {
             permissions.RemoveAt(i);
         }
         else
         {
             i++;
         }
     }
 }
Example #8
0
        public IList <Module> GetModules(Role role)
        {
            IList <Module> modules = new List <Module>();

            for (int i = 0; i < userRolePermissions.Count; i++)
            {
                UserRolePermission rolePermission = userRolePermissions[i];
                if (rolePermission.Role.Equals(role))
                {
                    if (!modules.Contains(rolePermission.Permission.Module))
                    {
                        modules.Add(rolePermission.Permission.Module);
                    }
                }
            }
            return(modules);
        }
Example #9
0
 public void AddPermissionByAddRole(Role role)
 {
     if (!userRoles.HaveRole(role))
     {
         userRoles.AddRole(role);
     }
     for (int i = 0; i < role.Permissions.Count; i++)
     {
         Permission permission = role.Permissions[i];
         if (!userRolePermissions.HavePermission(permission))
         {
             UserRolePermission rolePermission = new UserRolePermission();
             rolePermission.Role       = role;
             rolePermission.Permission = permission;
             userRolePermissions.AddRolePermission(rolePermission);
         }
     }
 }
Example #10
0
 public bool HavePermission(UserRolePermission permission)
 {
     return(HavePermission(permission.Permission));
 }