Simplifies all creation of UrlHelper, creates GetUmbracoApiServiceBaseUrl extensions for WebApi
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user