public Task <IdentityAdminResult <CreateResult> > CreateAsync(IEnumerable <PropertyValue> properties) { var IdentityResourceNameClaim = properties.Single(x => x.Type == "IdentityResourceName"); var IdentityResourceName = IdentityResourceNameClaim.Value; string[] exclude = { "IdentityResourceName" }; var otherProperties = properties.Where(x => !exclude.Contains(x.Type)).ToArray(); var metadata = GetMetadata(); var createProps = metadata.CreateProperties; var inMemoryIdentityResource = new InMemoryIdentityResource { Id = _identityResources.Count + 1, Name = IdentityResourceName, Enabled = true, Required = false, ShowInDiscoveryDocument = true }; foreach (var prop in otherProperties) { var propertyResult = SetProperty(createProps, inMemoryIdentityResource, prop.Type, prop.Value); if (!propertyResult.IsSuccess) { return(Task.FromResult(new IdentityAdminResult <CreateResult>(propertyResult.Errors.ToArray()))); } } _identityResources.Add(inMemoryIdentityResource); return(Task.FromResult(new IdentityAdminResult <CreateResult>(new CreateResult { Subject = inMemoryIdentityResource.Id.ToString() }))); }
protected string GetProperty(PropertyMetadata propMetadata, InMemoryIdentityResource identityResource) { string val; if (propMetadata.TryGet(identityResource, out val)) { return(val); } throw new Exception("Invalid property type " + propMetadata.Type); }
protected IdentityAdminResult SetProperty(IEnumerable <PropertyMetadata> propsMeta, InMemoryIdentityResource identityResource, string type, string value) { IdentityAdminResult result; if (propsMeta.TrySet(identityResource, type, value, out result)) { return(result); } throw new Exception("Invalid property type " + type); }