public object Patch(string id, [FromBody] dynamic model)
        {
            HeaderLimitId headerLimitId = new HeaderLimitId(id);

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

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

            string      configPath  = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            HeaderLimit headerLimit = HeaderLimitsHelper.GetHeaderLimits(site, headerLimitId.Path, configPath)
                                      .FirstOrDefault(h => h.Header.ToString().Equals(headerLimitId.Header));

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

            headerLimit = HeaderLimitsHelper.UpdateHeaderLimit(headerLimit, model);

            ManagementUnit.Current.Commit();

            dynamic head = HeaderLimitsHelper.ToJsonModel(headerLimit, site, headerLimitId.Path);

            if (head.id != id)
            {
                return(LocationChanged(HeaderLimitsHelper.GetLocation(head.id), head));
            }

            return(head);
        }
        public object Post([FromBody] dynamic model)
        {
            HeaderLimit        headerLimit = null;
            Site               site        = null;
            RequestFilteringId reqId       = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_filtering == null)
            {
                throw new ApiArgumentException("request_filtering");
            }
            if (!(model.request_filtering is JObject))
            {
                throw new ApiArgumentException(String.Empty, "request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

            if (reqUuid == null)
            {
                throw new ApiArgumentException("request_filtering.id");
            }

            reqId = new RequestFilteringId(reqUuid);

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

            string configPath = ManagementUnit.ResolveConfigScope(model);
            RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath);

            headerLimit = HeaderLimitsHelper.CreateHeaderLimit(model, section);

            HeaderLimitsHelper.AddHeaderLimit(headerLimit, section);

            ManagementUnit.Current.Commit();

            dynamic header_limit = HeaderLimitsHelper.ToJsonModel(headerLimit, site, reqId.Path);

            return(Created(HeaderLimitsHelper.GetLocation(header_limit.id), header_limit));
        }
        private void ConfigureHeaderLimits()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.HeaderLimitsResource.Guid, $"{ Defines.HEADER_LIMITS_PATH}/{{id?}}", new { controller = "headerlimits" });

            Environment.Hal.ProvideLink(Defines.HeaderLimitsResource.Guid, "self", hl => new { href = HeaderLimitsHelper.GetLocation(hl.id) });

            Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.HeaderLimitsResource.Name, rf => new { href = $"/{Defines.HEADER_LIMITS_PATH}?{Defines.IDENTIFIER}={rf.id}" });
        }