diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs index 36a4f3d24..485a050b8 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs @@ -169,6 +169,10 @@ namespace Orchard.Taxonomies.Services { } public IEnumerable GetTerms(int taxonomyId) { + // If taxonomyId isn't valid, return a empty list without executing the query. + if (taxonomyId <= 0) { + return Array.Empty(); + } var result = GetTermsQuery(taxonomyId) .OrderBy(x => x.FullWeight) .List(); @@ -177,6 +181,10 @@ namespace Orchard.Taxonomies.Services { } public IEnumerable GetRootTerms(int taxonomyId) { + // If taxonomyId isn't valid, return a empty list without executing the query. + if (taxonomyId <= 0) { + return Array.Empty(); + } var result = GetTermsQuery(taxonomyId) .Where(x => x.Path == "/") .OrderBy(x => x.FullWeight) @@ -202,11 +210,19 @@ namespace Orchard.Taxonomies.Services { } public int GetTermsCount(int taxonomyId) { + // If taxonomyId isn't valid, return 0 without executing the query. + if (taxonomyId <= 0) { + return 0; + } return GetTermsQuery(taxonomyId) .Count(); } public TermPart GetTerm(int id) { + // If term id isn't valid, return null without executing the query. + if (id <= 0) { + return null; + } return GetTermsQuery() .Where(x => x.Id == id).List().FirstOrDefault(); } @@ -231,6 +247,10 @@ namespace Orchard.Taxonomies.Services { } public TermPart GetTermByName(int taxonomyId, string name) { + // If taxonomyId isn't valid, return null without executing the query. + if (taxonomyId <= 0) { + return null; + } return GetTermsQuery(taxonomyId) .Join() .Where(r => r.Title == name)