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 = RedirectHeadersHelper.Create(model, section); RedirectHeadersHelper.Add(header, section); ManagementUnit.Current.Commit(); // // Create response dynamic h = RedirectHeadersHelper.ToJsonModel(header, site, id.Path); return(Created(RedirectHeadersHelper.GetLocation(h.id), h)); }
public object Patch(string id, dynamic model) { RedirectHeaderId headerId = new RedirectHeaderId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { return(NotFound()); } NameValueConfigurationElement header = RedirectHeadersHelper.GetRedirectHeaders(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); RedirectHeadersHelper.Update(header, model, section); ManagementUnit.Current.Commit(); // // Create Response dynamic redirectHeader = RedirectHeadersHelper.ToJsonModel(header, site, headerId.Path); if (redirectHeader.id != id) { return(LocationChanged(RedirectHeadersHelper.GetLocation(redirectHeader.id), redirectHeader)); } return(redirectHeader); }
private void ConfigureRedirectHeaders() { Environment.Host.RouteBuilder.MapWebApiRoute(Defines.RedirectHeadersResource.Guid, $"{Defines.REDIRECT_HEADERS_PATH}/{{id?}}", new { controller = "redirectheaders" }); Environment.Hal.ProvideLink(Defines.RedirectHeadersResource.Guid, "self", redHeader => new { href = RedirectHeadersHelper.GetLocation(redHeader.id) }); Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.RedirectHeadersResource.Name, redHeader => new { href = $"/{Defines.REDIRECT_HEADERS_PATH}?{Defines.IDENTIFIER}={redHeader.id}" }); }