protected IQueryable <Package> GetPackagesByIdQueryable(
            string id,
            PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None)
        {
            var packages = _packageRepository
                           .GetAll()
                           .Include(p => p.LicenseReports)
                           .Include(p => p.PackageRegistration)
                           .Include(p => p.User)
                           .Include(p => p.SymbolPackages)
                           .Where(p => p.PackageRegistration.Id == id);

            if (deprecationFields == PackageDeprecationFieldsToInclude.Deprecation)
            {
                packages = packages
                           .Include(p => p.Deprecations);
            }
            else if (deprecationFields == PackageDeprecationFieldsToInclude.DeprecationAndRelationships)
            {
                packages = packages
                           .Include(p => p.Deprecations.Select(d => d.AlternatePackage.PackageRegistration))
                           .Include(p => p.Deprecations.Select(d => d.AlternatePackageRegistration))
                           .Include(p => p.Deprecations.Select(d => d.Cves))
                           .Include(p => p.Deprecations.Select(d => d.Cwes));
            }

            return(packages);
        }
示例#2
0
        protected IQueryable <Package> GetPackagesByIdQueryable(
            string id,
            PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None)
        {
            bool includeDeprecation;
            bool includeDeprecationRelationships;

            switch (deprecationFields)
            {
            case PackageDeprecationFieldsToInclude.None:
                includeDeprecation = false;
                includeDeprecationRelationships = false;
                break;

            case PackageDeprecationFieldsToInclude.Deprecation:
                includeDeprecation = true;
                includeDeprecationRelationships = false;
                break;

            case PackageDeprecationFieldsToInclude.DeprecationAndRelationships:
                includeDeprecation = true;
                includeDeprecationRelationships = true;
                break;

            default:
                throw new NotSupportedException($"Unknown deprecation fields '{deprecationFields}'");
            }

            return(GetPackagesByIdQueryable(
                       id,
                       includeLicenseReports: true,
                       includePackageRegistration: true,
                       includeUser: true,
                       includeSymbolPackages: true,
                       includeDeprecation: includeDeprecation,
                       includeDeprecationRelationships: includeDeprecationRelationships));
        }
 public virtual IReadOnlyCollection <Package> FindPackagesById(
     string id,
     PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None)
 {
     return(GetPackagesByIdQueryable(id, deprecationFields).ToList());
 }