コード例 #1
0
        public object Post([FromBody] dynamic model)
        {
            HiddenSegment      segment = 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("request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

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

            // Get the feature 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);

            segment = HiddenSegmentsHelper.CreateSegment(model, section);

            HiddenSegmentsHelper.AddSegment(segment, section);

            ManagementUnit.Current.Commit();

            dynamic hidden_segment = HiddenSegmentsHelper.ToJsonModel(segment, site, reqId.Path);

            return(Created(HiddenSegmentsHelper.GetLocation(hidden_segment.id), hidden_segment));
        }
コード例 #2
0
        private void ConfigureHiddenSegments()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.HiddenSegmentsResource.Guid, $"{ Defines.HIDDEN_SEGMENTS_PATH}/{{id?}}", new { controller = "hiddensegments" });

            Environment.Hal.ProvideLink(Defines.HiddenSegmentsResource.Guid, "self", hs => new { href = HiddenSegmentsHelper.GetLocation(hs.id) });

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