public object Patch(string id, dynamic model) { CustomHeaderId headerId = new CustomHeaderId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { return(NotFound()); } NameValueConfigurationElement header = CustomHeadersHelper.GetCustomHeaders(site, headerId.Path).FirstOrDefault(h => h.Name.Equals(headerId.Name, StringComparison.OrdinalIgnoreCase)); if (header == null) { return(NotFound()); } var configScope = ManagementUnit.ResolveConfigScope(model); var section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, configScope); CustomHeadersHelper.Update(header, model, section); ManagementUnit.Current.Commit(); dynamic ch = CustomHeadersHelper.ToJsonModel(header, site, headerId.Path); if (ch.id != id) { return(LocationChanged(CustomHeadersHelper.GetLocation(ch.id), ch)); } return(ch); }
public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (model.http_response_headers == null) { throw new ApiArgumentException("http_response_headers"); } if (!(model.http_response_headers is JObject)) { throw new ApiArgumentException("http_response_headers"); } string uuid = DynamicHelper.Value(model.http_response_headers.id); if (uuid == null) { throw new ApiArgumentException("http_response_headers.id"); } HttpResponseHeadersId id = new HttpResponseHeadersId(uuid); Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, id.Path, configPath); NameValueConfigurationElement header = CustomHeadersHelper.Create(model, section); CustomHeadersHelper.Add(header, section); ManagementUnit.Current.Commit(); // // Create response dynamic ch = CustomHeadersHelper.ToJsonModel(header, site, id.Path); return(Created(CustomHeadersHelper.GetLocation(ch.id), ch)); }
private void ConfigureCustomHeaders() { // Register all controller routes in mvc framework Environment.Host.RouteBuilder.MapWebApiRoute(Defines.CustomHeadersResource.Guid, $"{Defines.CUSTOM_HEADERS_PATH}/{{id?}}", new { controller = "customheaders" }); // Provide self links for all plugin resources Environment.Hal.ProvideLink(Defines.CustomHeadersResource.Guid, "self", custHeader => new { href = CustomHeadersHelper.GetLocation(custHeader.id) }); // Provide link for the custom header sub resource Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.CustomHeadersResource.Name, custHeader => new { href = $"/{Defines.CUSTOM_HEADERS_PATH}?{Defines.IDENTIFIER}={custHeader.id}" }); }