public object Patch([FromBody] dynamic model, string id)
        {
            var preConditionId = new PreConditionId(id);

            Site site = preConditionId.SiteId == null ? null : SiteHelper.GetSite(preConditionId.SiteId.Value);

            if (preConditionId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRulesSection section      = OutboundRulesHelper.GetSection(site, preConditionId.Path);
            PreCondition         precondition = section.PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));

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

            OutboundRulesHelper.UpdatePreCondition(model, precondition, section);

            ManagementUnit.Current.Commit();

            dynamic updatedPreCondition = OutboundRulesHelper.PreConditionToJsonModel(precondition, site, preConditionId.Path, Context.Request.GetFields(), true);

            if (updatedPreCondition.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetPreConditionLocation(updatedPreCondition.id), updatedPreCondition));
            }

            return(updatedPreCondition);
        }
Beispiel #2
0
        private void ConfigureOutboundRules()
        {
            var builder = Environment.Host.RouteBuilder;
            var hal     = Environment.Hal;

            builder.MapWebApiRoute(Defines.OutboundRulesSectionResource.Guid, $"{Defines.OUTBOUND_RULES_SECTION_PATH}/{{id?}}", new { controller = "OutboundRulesSection" });
            builder.MapWebApiRoute(Defines.OutboundRulesResource.Guid, $"{Defines.OUTBOUND_RULES_PATH}/{{id?}}", new { controller = "OutboundRules" });
            builder.MapWebApiRoute(Defines.PreConditionsResource.Guid, $"{Defines.PRECONDITIONS_PATH}/{{id?}}", new { controller = "PreConditions" });
            builder.MapWebApiRoute(Defines.CustomTagsResource.Guid, $"{Defines.CUSTOM_TAGS_PATH}/{{id?}}", new { controller = "CustomTags" });

            // () -> Self
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, "self", ir => new { href = OutboundRulesHelper.GetSectionLocation(ir.id) });
            hal.ProvideLink(Defines.OutboundRulesResource.Guid, "self", ir => new { href = OutboundRulesHelper.GetRuleLocation(ir.id) });
            hal.ProvideLink(Defines.PreConditionsResource.Guid, "self", pc => new { href = OutboundRulesHelper.GetPreConditionLocation(pc.id) });
            hal.ProvideLink(Defines.CustomTagsResource.Guid, "self", tags => new { href = OutboundRulesHelper.GetCustomTagsLocation(tags.id) });

            // Rewrite -> Section
            hal.ProvideLink(Defines.Resource.Guid, Defines.OutboundRulesSectionResource.Name, rewrite => new { href = OutboundRulesHelper.GetSectionLocation(rewrite.id) });

            // Section -> Rules
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.OutboundRulesResource.Name, outboundRulesSection => new { href = $"/{Defines.OUTBOUND_RULES_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });

            // Section -> PreConditions
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.PreConditionsResource.Name, outboundRulesSection => new { href = $"/{Defines.PRECONDITIONS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });

            // Section -> CustomTags
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.CustomTagsResource.Name, outboundRulesSection => new { href = $"/{Defines.CUSTOM_TAGS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });
        }