public IEnumerable <DataSource> GetSources(CRN identifier)
 {
     return(this.context.DataSources
            .Include(x => x.Provider)
            .Where(s => s.Provider.CanonicalName == identifier.ToString())
            .ToList()
            .Select(s => new DataSource()
     {
         Identifier = CRN.FromValue(s.CanonicalName),
         Provider = CRN.FromValue(s.Provider.CanonicalName)
     }));
 }
 public IEnumerable <DataProviderPolicy> GetPolicies(CRN identifier)
 {
     return(this.context.DataProviderPolicies
            .Include(p => p.Provider)
            .Include(p => p.Schema)
            .Include(p => p.PolicyItems)
            .ThenInclude(i => i.Principal)
            .Where(p => p.Provider.CanonicalName == identifier.ToString())
            .ToList()
            .Select(p => new DataProviderPolicy()
     {
         Provider = CRN.FromValue(p.Provider.CanonicalName),
         Schema = CSN.FromValue(p.Schema.CanonicalName),
         Rule = p.PolicyItems.Select(i => new DataProviderPolicyRule()
         {
             Principal = CPN.FromValue(i.Principal.CanonicalName),
             Allow = i.Allow,
             Deny = i.Deny
         }).ToList()
     }));
 }
        public void Remove(CRN identifier)
        {
            var found = this.context.DataProviders.FirstOrDefault(p => p.CanonicalName == identifier.ToString());

            if (found == null)
            {
                return;
            }
            this.context.Remove(found);
            this.context.SaveChanges();
        }
        public void RemovePolicy(CRN identifier, CSN schema)
        {
            var provider    = this.context.DataProviders.FirstOrDefault(p => p.CanonicalName == identifier.ToString());
            var foundSchema = this.context.Schemas.FirstOrDefault(s => s.CanonicalName == schema.ToString());

            if (provider == null || foundSchema == null)
            {
                return;
            }

            var found = this.context.DataProviderPolicies.FirstOrDefault(p =>
                                                                         p.DataProviderId == provider.DataProviderId && p.SchemaId == foundSchema.SchemaId);

            if (found == null)
            {
                return;
            }
            this.context.Remove(found);
            this.context.SaveChanges();
        }
 public IEnumerable <Resource> FindByIdentifier(CRN identifier) => GetQuery().Where(r => r.CanonicalName == identifier.ToString()).ToList().Select(ToModel);