public static Permission ToCoreModel(this dataModel.PermissionEntity source)
        {
            var result = new Permission();
            result.InjectFrom(source);

            return result;
        }
 public static Permission ToCoreModel(this dataModel.RolePermissionEntity source, IPermissionScopeService scopeService)
 {
     var result = new Permission();
     result.InjectFrom(source.Permission);
     result.AssignedScopes = source.Scopes.Select(x => new { source = x, target = scopeService.GetScopeByTypeName(x.Type) })
                                           .Where(x=> x.target != null)
                                           .Select(x=> x.source.ToCoreModel(x.target))
                                           .ToArray();
     result.AvailableScopes = scopeService.GetAvailablePermissionScopes(result.Id).ToArray();
     return result;
 }
        public static Permission ToCoreModel(this PermissionEntity source)
        {
            var result = new Permission
            {
                Id = source.Id,
                Name = source.Name,
                Description = source.Description,
            };

            return result;
        }
		private static void AddOrUpdatePermissions(IPlatformRepository repository, Permission[] permissions)
        {
            if (permissions != null)
            {
                var permissionIds = permissions.Select(p => p.Id).ToArray();
                var existingPermissions = repository.Permissions.Where(p => permissionIds.Contains(p.Id)).ToArray();

                foreach (var permission in permissions)
                {
                    var sourceEntry = permission.ToDataModel();
                    var targetEntry = existingPermissions.FirstOrDefault(p => string.Equals(p.Id, permission.Id, StringComparison.OrdinalIgnoreCase));

                    if (targetEntry == null)
                    {
                        repository.Add(sourceEntry);
                    }
                    else
                    {
                        sourceEntry.Patch(targetEntry);
                    }
                }
            }
        }
 public virtual void Patch(Permission target)
 {
     target.Name      = Name;
     target.ModuleId  = ModuleId;
     target.GroupName = GroupName;
 }