示例#1
0
        public void Apply(ControllerModel controller)
        {
            (var grainType, var resourceType) = controller.ControllerTypes();
            if (grainType == null || resourceType == null)
            {
                return;
            }

            controller.ControllerName = grainType.Name;

            controller.Selectors[0].AttributeRouteModel.Template = controller.ControllerName.ToLowerInvariant();
        }
示例#2
0
        public void Apply(ControllerModel controller)
        {
            var(grainType, resourceType) = controller.ControllerTypes();

            if (grainType == null || resourceType == null)
            {
                return;
            }

            var routeAttr = controller.Actions.First().Selectors[0].AttributeRouteModel;

            if (routeAttr?.Template == DefaultRoute && resourceType != grainType)
            {
                routeAttr.Template = "{id}/" + resourceType.Name.ToLowerInvariant();
            }

            if (controller.ControllerType.IsGenericType && controller.ControllerType.GetGenericTypeDefinition() == typeof(DeleteByIdController <,>))
            {
                routeAttr.Template = "{id}/" + resourceType.Name.ToLowerInvariant() + "/{itemId}";
            }
        }