Simplifies all creation of UrlHelper, creates GetUmbracoApiServiceBaseUrl extensions for WebApi

This commit is contained in:
Shannon
2017-01-03 11:13:38 +11:00
parent ee925692e5
commit 790e30defd
10 changed files with 33 additions and 9 deletions

View File

@@ -122,5 +122,29 @@ namespace Umbraco.Web
}
}
}
/// <summary>
/// Return the Base Url (not including the action) for a Web Api service
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url"></param>
/// <param name="actionName"></param>
/// <returns></returns>
public static string GetUmbracoApiServiceBaseUrl<T>(this UrlHelper url, string actionName)
where T : UmbracoApiController
{
return url.GetUmbracoApiService<T>(actionName).TrimEnd(actionName);
}
public static string GetUmbracoApiServiceBaseUrl<T>(this UrlHelper url, Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
var method = Core.ExpressionHelper.GetMethodInfo(methodSelector);
if (method == null)
{
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) + " or the result ");
}
return url.GetUmbracoApiService<T>(method.Name).TrimEnd(method.Name);
}
}
}