/// <summary>
        /// Retrieves all instances of ProductCategory that are leaves.
        /// </summary>
        /// <returns>GetAllProductCategoriesModelView with data regarding all of the leaf ProductCategory.</returns>
        /// <exception cref="ResourceNotFoundException">Throw when no leaf ProductCategory is found.</exception>
        public GetAllProductCategoriesModelView findLeaves()
        {
            IEnumerable <ProductCategory> leaves = PersistenceContext.repositories().createProductCategoryRepository().findLeaves();

            if (!leaves.Any())
            {
                throw new ResourceNotFoundException(ERROR_NO_CATEGORIES_FOUND);
            }

            return(ProductCategoryModelViewService.fromCollection(leaves));
        }
        /// <summary>
        /// Retrieves all instances of ProductCategory that are currently present within the repository.
        /// </summary>
        /// <returns>Returns a list with ModelViews of all the instances of ProductCategory in the repository. </returns>
        public GetAllProductCategoriesModelView findAllCategories()
        {
            IEnumerable <ProductCategory> categories = PersistenceContext.repositories().createProductCategoryRepository().findAll();

            //check if any categories have been added
            if (!categories.Any())
            {
                throw new ArgumentException(ERROR_NO_CATEGORIES_FOUND);
            }

            return(ProductCategoryModelViewService.fromCollection(categories));
        }
        /// <summary>
        /// Retrieves all instances of ProductCategory that are subcategories of the ProductCategory with the given identifier.
        /// </summary>
        /// <param name="parentId">Parent ProductCategory's database identifier.</param>
        /// <returns>Returns a list with ModelViews of all the instances of ProductCategory that are subcategories of the given ProductCategory.</returns>
        public GetAllProductCategoriesModelView findAllSubCategories(long parentId)
        {
            ProductCategoryRepository repository = PersistenceContext.repositories().createProductCategoryRepository();

            ProductCategory parentCategory = repository.find(parentId);

            if (parentCategory == null)
            {
                throw new ArgumentException(ERROR_PARENT_NOT_FOUND);
            }

            IEnumerable <ProductCategory> subCategories = repository.findSubCategories(parentCategory);

            //check if any categories have been added
            if (!subCategories.Any())
            {
                throw new ArgumentException(ERROR_NO_CATEGORIES_FOUND);
            }

            return(ProductCategoryModelViewService.fromCollection(subCategories));
        }