public object Post(dynamic model)
        {
            TraceRule            rule  = null;
            Site                 site  = null;
            HttpRequestTracingId hrtId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_tracing == null)
            {
                throw new ApiArgumentException("request_tracing");
            }
            if (!(model.request_tracing is JObject))
            {
                throw new ApiArgumentException("request_tracing", ApiArgumentException.EXPECTED_OBJECT);
            }
            string hrtUuid = DynamicHelper.Value(model.request_tracing.id);

            if (hrtUuid == null)
            {
                throw new ApiArgumentException("request_tracing.id");
            }

            hrtId = new HttpRequestTracingId(hrtUuid);

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

            string configPath = ManagementUnit.ResolveConfigScope(model);

            rule = RulesHelper.CreateRule(model, site, hrtId.Path, configPath);

            var section = Helper.GetTraceFailedRequestsSection(site, hrtId.Path, configPath);

            RulesHelper.AddRule(rule, section);

            ManagementUnit.Current.Commit();

            dynamic r = RulesHelper.ToJsonModel(rule, site, hrtId.Path);

            return(Created(RulesHelper.GetLocation(r.id), r));
        }
        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)
            {
                return(NotFound());
            }

            TraceRule rule = RulesHelper.GetRules(site, ruleId.AppPath).Where(r => r.Path.Equals(ruleId.Path)).FirstOrDefault();

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

            return(RulesHelper.ToJsonModel(rule, site, ruleId.AppPath));
        }
        public object Patch(string id, dynamic model)
        {
            RuleId ruleId = new RuleId(id);

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

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

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

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

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


            rule = RulesHelper.UpdateRule(rule, model, site, ruleId.AppPath, configPath);

            ManagementUnit.Current.Commit();

            dynamic rle = RulesHelper.ToJsonModel(rule, site, ruleId.AppPath);

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

            return(rle);
        }