public void Apply(ControllerModel controllerModel) { const string RouteTemplate = "/api/projects/<id>/[action]"; var routeId = _configuration["RouteIds:" + controllerModel.ControllerName]; var firstSelector = controllerModel.Selectors[0]; if (firstSelector.AttributeRouteModel == null) { firstSelector.AttributeRouteModel = new AttributeRouteModel(); } firstSelector.AttributeRouteModel.Template = RouteTemplate.Replace("<id>", routeId); }
private string FillControllerTokenInRouteTemplate() { if (string.IsNullOrWhiteSpace(RouteTemplate)) { return(string.Empty); } if (!RouteTemplate.Contains("[controller]") && !RouteTemplate.Contains("[Controller]")) { return(RouteTemplate); } var controllerNameReplacement = RemoveControllerFromName(Type.Name); return(RouteTemplate.Replace("[controller]", controllerNameReplacement).Replace("[Controller]", controllerNameReplacement)); }
/// <summary> /// Возвращает относительный путь до метода контроллера. /// </summary> /// <param name="action">Метод контроллера.</param> protected string GetControllerActionPath(string action = null) { var route = RouteTemplate .Replace("[controller]", Controller, StringComparison.InvariantCultureIgnoreCase); if (route.Contains("[action]", StringComparison.InvariantCultureIgnoreCase)) { route = route.Replace("[action]", action ?? string.Empty, StringComparison.InvariantCultureIgnoreCase); } else if (!string.IsNullOrEmpty(action)) { route = route + "/" + action; } return(route); }
/// <summary> /// Replace a variable in the <c>RouteTemplate</c> with a specified value. /// </summary> /// <param name="variableName">The variable name to replace.</param> /// <param name="variableValue">The value to replace with.</param> /// <param name="workingRoute">An 'in progress' route that may contain values that have already been replaced.</param> /// <returns>A <c>workingRoute</c></returns> public string SetVariable(string variableName, string variableValue, string workingRoute = null) { if (!variableName.StartsWith(VariableStartChar.ToString()) && !variableName.EndsWith(VariableEndChar.ToString())) { variableName = $"{VariableStartChar}{variableName}{VariableEndChar}"; } return(!string.IsNullOrEmpty(workingRoute) ? workingRoute.Replace(variableName, variableValue) : RouteTemplate.Replace(variableName, variableValue)); }