コード例 #1
0
        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);
        }
コード例 #2
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);
        }
コード例 #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));
        }
コード例 #4
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var outboundRuleId = new OutboundRuleId(id);

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

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

            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, outboundRuleId.Path);
            OutboundRule         rule    = (OutboundRule)section.Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));

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

            OutboundRulesHelper.UpdateRule(model, rule, section);

            ManagementUnit.Current.Commit();

            dynamic updatedRule = OutboundRulesHelper.RuleToJsonModel(rule, site, outboundRuleId.Path, Context.Request.GetFields(), true);

            if (updatedRule.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetRuleLocation(updatedRule.id), updatedRule));
            }

            return(updatedRule);
        }
コード例 #5
0
        public void Delete(string id)
        {
            var outboundRulesId = new RewriteId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

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

            if (site != null)
            {
                var section = OutboundRulesHelper.GetSection(site, outboundRulesId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
コード例 #6
0
        public object Get(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());
            }

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

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

            return(OutboundRulesHelper.PreConditionToJsonModel(precondition, site, preConditionId.Path, Context.Request.GetFields()));
        }
コード例 #7
0
        public object Get(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());
            }

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

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

            return(OutboundRulesHelper.TagsToJsonModel(tag, site, customTagsId.Path, Context.Request.GetFields()));
        }
コード例 #8
0
        public object Get(string id)
        {
            var outboundRuleId = new OutboundRuleId(id);

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

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

            OutboundRule rule = (OutboundRule)OutboundRulesHelper.GetSection(site, outboundRuleId.Path).Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));

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

            return(OutboundRulesHelper.RuleToJsonModel(rule, site, outboundRuleId.Path, Context.Request.GetFields()));
        }
コード例 #9
0
        public object Get()
        {
            string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(outboundRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(outboundRulesId);

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

            PreConditionCollection preconditions = OutboundRulesHelper.GetSection(site, sectionId.Path).PreConditions;

            this.Context.Response.SetItemsCount(preconditions.Count());

            return(new
            {
                preconditions = preconditions.Select(precondition => OutboundRulesHelper.PreConditionToJsonModelRef(precondition, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #10
0
        public void Delete(string id)
        {
            PreCondition preCondition   = null;
            var          preConditionId = new PreConditionId(id);

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

            if (preConditionId.SiteId == null || site != null)
            {
                preCondition = OutboundRulesHelper.GetSection(site, preConditionId.Path).PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (preCondition != null)
            {
                var section = OutboundRulesHelper.GetSection(site, preConditionId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeletePreCondition(preCondition, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #11
0
        public void Delete(string id)
        {
            TagsElement tags   = null;
            var         tagsId = new CustomTagsId(id);

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

            if (tagsId.SiteId == null || site != null)
            {
                tags = OutboundRulesHelper.GetSection(site, tagsId.Path).Tags.FirstOrDefault(t => t.Name.Equals(tagsId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (tags != null)
            {
                var section = OutboundRulesHelper.GetSection(site, tagsId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeleteCustomTags(tags, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #12
0
        public void Delete(string id)
        {
            OutboundRule rule           = null;
            var          outboundRuleId = new OutboundRuleId(id);

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

            if (outboundRuleId.SiteId == null || site != null)
            {
                rule = (OutboundRule)OutboundRulesHelper.GetSection(site, outboundRuleId.Path).Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (rule != null)
            {
                var section = OutboundRulesHelper.GetSection(site, outboundRuleId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeleteRule(rule, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #13
0
        public object Get()
        {
            string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(outboundRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(outboundRulesId);

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

            OutboundRulesCollection rules = OutboundRulesHelper.GetSection(site, sectionId.Path).Rules;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(rules.Count());

            return(new
            {
                rules = rules.Select(rule => OutboundRulesHelper.RuleToJsonModelRef((OutboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }