/// <summary>
        /// Retrieves a ModelView representation of the instance of ProductCategory with a matching database identifier.
        /// </summary>
        /// <param name="id">Database identifier.</param>
        /// <returns>ModelView representation of the ProductCategory with the matching database identifier
        /// or null if no ProductCategory with a matching id was found.</returns>
        public GetProductCategoryModelView findByDatabaseId(long id)
        {
            ProductCategory category = PersistenceContext.repositories().createProductCategoryRepository().find(id);

            if (category == null)
            {   //category might not exist
                throw new ArgumentException(ERROR_CATEGORY_NOT_FOUND_ID);
            }

            return(ProductCategoryModelViewService.fromEntity(category));
        }
        /// <summary>
        /// Retrieves a ModelView representation of the instance of ProductCategory with a matching business identifier (name).
        /// </summary>
        /// <param name="name">Business identifier (name).</param>
        /// <returns>ModelView representation of the instance of ProductCategory with a matching business identifier.</returns>
        public GetProductCategoryModelView findByName(string name)
        {
            ProductCategory category = PersistenceContext.repositories().createProductCategoryRepository().find(name);

            if (category == null)
            {   //category might not exist
                throw new ArgumentException(ERROR_CATEGORY_NOT_FOUND_NAME);
            }

            return(ProductCategoryModelViewService.fromEntity(category));
        }
        /// <summary>
        /// Adds a new ProductCategory to the repository.
        /// </summary>
        /// <param name="modelView">ModelView containing ProductCategory information.</param>
        /// <returns>Returns the added ProductCategory's ModelView.</returns>
        public GetProductCategoryModelView addProductCategory(AddProductCategoryModelView modelView)
        {
            ProductCategoryRepository repository = PersistenceContext.repositories().createProductCategoryRepository();

            ProductCategory category = new ProductCategory(modelView.name);

            category = repository.save(category);

            //category was not able to be added (probably due to a violation of business identifiers)
            if (category == null)
            {
                throw new ArgumentException(ERROR_UNABLE_TO_ADD_CATEGORY);
            }

            return(ProductCategoryModelViewService.fromEntity(category));
        }
        /// <summary>
        /// Removes a ProductCategory from the repository.
        /// </summary>
        /// <param name="id">Database identifier of the ProductCategory to be removed.</param>
        /// <returns>A ModelView representation of the removed ProductCategory.</returns>
        public GetProductCategoryModelView removeProductCategory(long id)
        {
            ProductCategoryRepository categoryRepository = PersistenceContext.repositories().createProductCategoryRepository();

            ProductCategory category = categoryRepository.find(id);

            //category does not exist
            if (category == null)
            {
                throw new ArgumentException(ERROR_CATEGORY_NOT_FOUND_ID);
            }

            category = categoryRepository.remove(category);

            return(ProductCategoryModelViewService.fromEntity(category));
        }
        /// <summary>
        /// Updates a ProductCategory with a given database identifier with the data in given ModelView.
        /// </summary>
        /// <param name="id">ProductCategory's database identifier.</param>
        /// <param name="modelView">ModelView containing the data being updated.</param>
        /// <returns>A ModelView with the updated ProductCategory data.</returns>
        public GetProductCategoryModelView updateProductCategory(long id, UpdateProductCategoryModelView modelView)
        {
            ProductCategoryRepository repository = PersistenceContext.repositories().createProductCategoryRepository();

            ProductCategory category = repository.find(id);

            string newName = modelView.name;

            if (!category.changeName(newName))
            {
                throw new ArgumentException(ERROR_INVALID_NAME);
            }

            category = repository.update(category);

            if (category == null)
            {
                throw new ArgumentException(ERROR_DUPLICATE_NAME);
            }

            return(ProductCategoryModelViewService.fromEntity(category));
        }