public async Task <IdentityResult> DeleteCorsOriginAsync(Neo4jIdentityServer4Client client,
                                                                 Neo4jIdentityServer4ClientCorsOrigin corsOrigin,
                                                                 CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            corsOrigin.ThrowIfNull(nameof(corsOrigin));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->(corsOrigin:{
                        IdSrv4ClientCorsOrigin
                    })
                WHERE client.ClientId = $p0 AND corsOrigin.Origin = $p1 
                DETACH DELETE corsOrigin";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           corsOrigin.Origin
                                           ));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <Neo4jIdentityServer4ClientCorsOrigin> FindCorsOriginAsync(Neo4jIdentityServer4Client client,
                                                                                     Neo4jIdentityServer4ClientCorsOrigin corsOrigin,
                                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            corsOrigin.ThrowIfNull(nameof(corsOrigin));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->(corsOrigin:{
                    IdSrv4ClientCorsOrigin
                })
                WHERE client.ClientId = $p0 AND corsOrigin.Origin = $p1 
                RETURN corsOrigin{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    corsOrigin.Origin
                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientCorsOrigin>("corsOrigin"));

            return(foundRecord);
        }
        public async Task <IdentityResult> AddCorsOriginToClientAsync(Neo4jIdentityServer4Client client,
                                                                      Neo4jIdentityServer4ClientCorsOrigin corsOrigin,
                                                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            corsOrigin.ThrowIfNull(nameof(corsOrigin));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client} {{ClientId: $p0}})
                CREATE UNIQUE(
                    (client)-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->
                    (:{IdSrv4ClientCorsOrigin} {"$p1".AsMapForNoNull(corsOrigin)}))";


                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, corsOrigin));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
 /// <summary>
 /// Maps an entity to a model.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public static string ToModel(
     this Neo4jIdentityServer4ClientCorsOrigin entity)
 {
     return(Mapper.Map <string>(entity));
 }