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");
            }

            // Get site the rule is for if applicable
            Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value);

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

            // Create rule
            InboundRule rule = InboundRulesHelper.CreateRule(model, site, parentId.Path, ManagementUnit.ResolveConfigScope(model));

            // Add it
            InboundRulesHelper.AddRule(rule, section, model);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic r = InboundRulesHelper.RuleToJsonModel(rule, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(InboundRulesHelper.GetRuleLocation(r.id), r));
        }
Example #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);
            RewriteMapsSection section    = RewriteMapsHelper.GetSection(site, parentId.Path, configPath);

            RewriteMap map = RewriteMapsHelper.CreateMap(model, section);

            RewriteMapsHelper.AddMap(map, section);

            ManagementUnit.Current.Commit();

            dynamic r = RewriteMapsHelper.MapToJsonModel(map, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(RewriteMapsHelper.GetMapLocation(r.id), r));
        }
Example #3
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));
        }
        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);
            ProvidersSection section    = ProvidersHelper.GetSection(site, parentId.Path, configPath);

            Provider provider = ProvidersHelper.CreateProvider(model, section);

            // Add it
            ProvidersHelper.AddProvider(provider, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic p = ProvidersHelper.ProviderToJsonModel(provider, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(ProvidersHelper.GetProviderLocation(p.id), p));
        }