Пример #1
0
        public bool SetPermission(string userId, params string[] permissionIds)
        {
            var all = _permissionRoleUserOrganizationUnit.GetAll().Where(u => u.UserId == userId).ToList();

            if (all.Count > 0 && permissionIds.Length >= 0)
            {
                var remove = all.Where(u => !permissionIds.Contains(u.PermissionId)).ToList();
                if (remove.Count > 0)
                {
                    foreach (var permission in remove)
                    {
                        _permissionRoleUserOrganizationUnit.Delete(permission);
                    }
                }
            }

            foreach (var permissionId in permissionIds)
            {
                if (all.Exists(u => u.PermissionId == permissionId))
                {
                    continue;
                }
                PermissionRoleUserOrganizationUnit permission = new PermissionRoleUserOrganizationUnit()
                {
                    PermissionId = permissionId,
                    UserId       = userId
                };
                _permissionRoleUserOrganizationUnit.Insert(permission);
            }
            return(true);
        }
Пример #2
0
        public Task <bool> SetPermission(string organizationUnitId, params string[] permissionIds)
        {
            var all = _permissionRoleUserOrganizationUnitRepository.GetAll().Where(u => u.OrganizationUnitId == organizationUnitId).ToList();

            if (all.Count > 0 && permissionIds.Length >= 0)
            {
                var remove = all.Where(u => !permissionIds.Contains(u.PermissionId)).ToList();
                if (remove.Count > 0)
                {
                    foreach (var permission in remove)
                    {
                        _permissionRoleUserOrganizationUnitRepository.Delete(permission);
                    }
                }
            }

            foreach (var permissionId in permissionIds)
            {
                if (all.Exists(u => u.PermissionId == permissionId))
                {
                    continue;
                }
                PermissionRoleUserOrganizationUnit permission = new PermissionRoleUserOrganizationUnit()
                {
                    PermissionId       = permissionId,
                    OrganizationUnitId = organizationUnitId
                };
                _permissionRoleUserOrganizationUnitRepository.Insert(permission);
            }
            return(Task.FromResult(true));
        }