public void Delete(string id)
        {
            RuleId ruleId = new RuleId(id);

            Site        site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);
            Application app  = ApplicationHelper.GetApplication(ruleId.Path, site);

            if (ruleId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            Rule rule = RulesHelper.GetRules(site, ruleId.Path).Where(r => r.Name.ToString().Equals(ruleId.Name)).FirstOrDefault();

            if (rule != null)
            {
                var section = RequestFilteringHelper.GetRequestFilteringSection(site, ruleId.Path, ManagementUnit.ResolveConfigScope());

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

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
        public object Get(string id)
        {
            RuleId ruleId = new RuleId(id);

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

            if (ruleId.SiteId != null && site == null)
            {
                // The rule id specified a site but we couldn't find it, therefore we can't get the rule
                return(NotFound());
            }

            Rule rule = RulesHelper.GetRules(site, ruleId.Path).Where(r => r.Name.ToString().Equals(ruleId.Name)).FirstOrDefault();

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

            return(RulesHelper.ToJsonModel(rule, site, ruleId.Path, Context.Request.GetFields(), true));
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            RuleId ruleId = new RuleId(id);

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

            if (ruleId.SiteId != null && site == null)
            {
                // The rule id specified a site but we couldn't find it, therefore we can't get the rule
                return(NotFound());
            }

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

            string configPath = ManagementUnit.ResolveConfigScope(model);
            Rule   rule       = RulesHelper.GetRules(site, ruleId.Path, configPath).Where(r => r.Name.ToString().Equals(ruleId.Name)).FirstOrDefault();

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

            rule = RulesHelper.UpdateRule(rule, model);

            ManagementUnit.Current.Commit();

            dynamic rle = RulesHelper.ToJsonModel(rule, site, ruleId.Path, null, true);

            if (rle.id != id)
            {
                return(LocationChanged(RulesHelper.GetLocation(rle.id), rle));
            }

            return(rle);
        }