コード例 #1
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var customTagsId = new CustomTagsId(id);

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

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

            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, customTagsId.Path);
            TagsElement          tags    = section.Tags.FirstOrDefault(t => t.Name.Equals(customTagsId.Name, StringComparison.OrdinalIgnoreCase));

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

            OutboundRulesHelper.UpdateCustomTags(model, tags, section);

            ManagementUnit.Current.Commit();

            dynamic updatedCustomTags = OutboundRulesHelper.TagsToJsonModel(tags, site, customTagsId.Path, Context.Request.GetFields(), true);

            if (updatedCustomTags.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetCustomTagsLocation(updatedCustomTags.id), updatedCustomTags));
            }

            return(updatedCustomTags);
        }
コード例 #2
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);

            if (parentId == null)
            {
                throw new ApiArgumentException("url_rewrite");
            }

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

            string configPath            = ManagementUnit.ResolveConfigScope(model);
            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, parentId.Path, configPath);

            TagsElement tags = OutboundRulesHelper.CreateCustomTags(model, section);

            OutboundRulesHelper.AddCustomTags(tags, section);

            ManagementUnit.Current.Commit();

            dynamic pc = OutboundRulesHelper.TagsToJsonModel(tags, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(OutboundRulesHelper.GetCustomTagsLocation(pc.id), pc));
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: zyonet/IIS.Administration
        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}" });
        }