public Task <IdentityAdminResult <ScopeDetail> > GetScopeAsync(string subject) { int parsedId; if (int.TryParse(subject, out parsedId)) { var inMemoryScope = _scopes.FirstOrDefault(p => p.Id == parsedId); if (inMemoryScope == null) { return(Task.FromResult(new IdentityAdminResult <ScopeDetail>((ScopeDetail)null))); } var result = new ScopeDetail { Subject = subject, Name = inMemoryScope.Name, Description = inMemoryScope.Description, }; var metadata = GetMetadata(); var props = from prop in metadata.ScopeMetaData.UpdateProperties select new PropertyValue { Type = prop.Type, Value = GetScopeProperty(prop, inMemoryScope), }; result.Properties = props.ToArray(); result.ScopeClaimValues = new List <ScopeClaimValue>(); Mapper.Map(inMemoryScope.ScopeClaims.ToList(), result.ScopeClaimValues); return(Task.FromResult(new IdentityAdminResult <ScopeDetail>(result))); } return(Task.FromResult(new IdentityAdminResult <ScopeDetail>((ScopeDetail)null))); }
public ScopeDetailResource(ScopeDetail scope, UrlHelper url, IdentityAdminMetadata idmAdminMeta) { if (scope == null) { throw new ArgumentNullException("scope"); } if (url == null) { throw new ArgumentNullException("url"); } if (idmAdminMeta == null) { throw new ArgumentNullException("idmAdminMeta"); } Data = new ScopeDetailDataResource(scope, url, idmAdminMeta); var links = new Dictionary <string, string>(); if (idmAdminMeta.ClientMetaData.SupportsDelete) { links["Delete"] = url.Link(Constants.RouteNames.DeleteScope, new { subject = scope.Subject }); } Links = links; }
public ScopeDetailDataResource(ScopeDetail scope, UrlHelper url, IdentityAdminMetadata idmAdminMeta) { if (scope == null) { throw new ArgumentNullException("scope"); } if (url == null) { throw new ArgumentNullException("url"); } if (idmAdminMeta == null) { throw new ArgumentNullException("idmAdminMeta"); } this["Name"] = scope.Name; this["Description"] = scope.Description; this["Subject"] = scope.Subject; if (scope.Properties != null) { var props = from p in scope.Properties let m = (from m in idmAdminMeta.ScopeMetaData.UpdateProperties where m.Type == p.Type select m).SingleOrDefault () where m != null select new { Data = m.Convert(p.Value), Meta = m, Links = new { update = url.Link(Constants.RouteNames.UpdateScopeProperty, new { subject = scope.Subject, type = p.Type.ToBase64UrlEncoded() } ) } }; if (props.Any()) { this["Properties"] = props.ToArray(); } } #region Claims if (scope.ScopeClaimValues != null) { var claimValues = from c in scope.ScopeClaimValues.ToArray() select new { Data = c, Links = new { delete = url.Link(Constants.RouteNames.RemoveScopeClaim, new { subject = scope.Subject, id = c.Id }) } }; this["Claims"] = new { Data = claimValues.ToArray(), Links = new { create = url.Link(Constants.RouteNames.AddScopeClaim, new { subject = scope.Subject }) } }; } #endregion }