Beispiel #1
0
        /// <summary>
        /// Return the Url for a Web Api service
        /// </summary>
        /// <param name="url"></param>
        /// <param name="umbracoApiControllerTypeCollection"></param>
        /// <param name="actionName"></param>
        /// <param name="apiControllerType"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string?GetUmbracoApiService(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, Type apiControllerType, object?id = null)
        {
            if (actionName == null)
            {
                throw new ArgumentNullException(nameof(actionName));
            }
            if (string.IsNullOrWhiteSpace(actionName))
            {
                throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
            }
            if (apiControllerType == null)
            {
                throw new ArgumentNullException(nameof(apiControllerType));
            }

            var area = "";

            var apiController = umbracoApiControllerTypeCollection.SingleOrDefault(x => x == apiControllerType);

            if (apiController == null)
            {
                throw new InvalidOperationException("Could not find the umbraco api controller of type " + apiControllerType.FullName);
            }
            var metaData = PluginController.GetMetadata(apiController);

            if (metaData.AreaName.IsNullOrWhiteSpace() == false)
            {
                //set the area to the plugin area
                area = metaData.AreaName;
            }
            return(url.GetUmbracoApiService(actionName, ControllerExtensions.GetControllerName(apiControllerType), area !, id));
        }