public static LinkTransformationBuilder AddQueryStringValues(this LinkTransformationBuilder builder, IDictionary <string, string> values) { return(builder.Add(ctx => { var queryString = String.Join("&", values.Select(v => $"{v.Key}={v.Value?.ToString()}")); return string.Concat("?", queryString); })); }
public static LinkTransformationBuilder AddVirtualPath(this LinkTransformationBuilder builder, Func <LinkTransformationContext, string> getPath) { return(builder.Add(ctx => { var path = getPath(ctx); if (!path.StartsWith("/")) { path = String.Concat("/", path); } return path; })); }
public static LinkTransformationBuilder AddRoutePath(this LinkTransformationBuilder builder) { return(builder.Add(ctx => { if (string.IsNullOrEmpty(ctx.LinkSpec.RouteName)) { throw new InvalidOperationException($"Invalid route specified in link specification."); } var path = ctx.LinkGenerator.GetPathByRouteValues(ctx.HttpContext, ctx.LinkSpec.RouteName, ctx.LinkSpec.RouteValues); if (string.IsNullOrEmpty(path)) { throw new InvalidOperationException($"Invalid path when adding route '{ctx.LinkSpec.RouteName}'. RouteValues: {string.Join(",", ctx.ActionContext.RouteData.Values.Select(x => string.Concat(x.Key, "=", x.Value)))}"); } return path; })); }
public static LinkTransformationBuilder AddRoutePath(this LinkTransformationBuilder builder) { return(builder.Add(ctx => { if (string.IsNullOrEmpty(ctx.LinkSpec.RouteName)) { throw new InvalidOperationException($"Invalid route specified in link specification."); } var valuesDictionary = GetValuesDictionary(ctx.LinkSpec.RouteValues); var virtualPathContext = new VirtualPathContext(ctx.HttpContext, ctx.RouteValues, valuesDictionary, ctx.LinkSpec.RouteName); var virtualPathData = ctx.Router.GetVirtualPath(virtualPathContext); if (virtualPathData == null) { throw new InvalidOperationException($"Invalid virtualPathData when adding route '{ctx.LinkSpec.RouteName}'. RouteValues: {String.Join(",", valuesDictionary.Select(x => String.Concat(x.Key,"=",x.Value)))}"); } return virtualPathData.VirtualPath; })); }
public static LinkTransformationBuilder AddFragment(this LinkTransformationBuilder builder, Func <LinkTransformationContext, string> getFragment) { return(builder.Add(ctx => string.Concat("#", getFragment(ctx)))); }
public static LinkTransformationBuilder AddHost(this LinkTransformationBuilder builder) { return(builder.Add(ctx => ctx.HttpContext.Request.Host.ToUriComponent())); }
public static LinkTransformationBuilder AddProtocol(this LinkTransformationBuilder builder) { return(builder.Add(ctx => String.Concat(ctx.HttpContext.Request.Scheme, "://"))); }