Ejemplo n.º 1
0
        private void ConfigureGlobalRules()
        {
            var builder = Environment.Host.RouteBuilder;

            //
            // Use conditional hal to provide global rules only at webserver level
            var hal = Environment.Hal as IConditionalHalService;

            builder.MapWebApiRoute(Defines.GlobalRulesSectionResource.Guid, $"{Defines.GLOBAL_RULES_SECTION_PATH}/{{id?}}", new { controller = "GlobalRulesSection" });
            builder.MapWebApiRoute(Defines.GlobalRulesResource.Guid, $"{Defines.GLOBAL_RULES_PATH}/{{id?}}", new { controller = "GlobalRules" });

            if (hal != null)
            {
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetSectionLocation(ir.id) });
                hal.ProvideLink(Defines.GlobalRulesResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetRuleLocation(ir.id) });

                // Rewrite -> Section
                hal.ProvideLink(
                    Defines.Resource.Guid,
                    Defines.GlobalRulesSectionResource.Name,
                    rewrite => new { href = GlobalRulesHelper.GetSectionLocation(rewrite.id) },
                    rewrite => string.IsNullOrEmpty(rewrite.scope));

                // Section -> Rules
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, Defines.GlobalRulesResource.Name, globalRulesSection => new { href = $"/{Defines.GLOBAL_RULES_PATH}?{Defines.IDENTIFIER}={globalRulesSection.id}" });
            }
        }
        public object Get()
        {
            RewriteHelper.ResolveRewrite(Context, out Site site, out string path);

            if (path == null)
            {
                return(NotFound());
            }

            dynamic d = GlobalRulesHelper.SectionToJsonModel(site, path);

            return(LocationChanged(GlobalRulesHelper.GetSectionLocation(d.id), d));
        }