public static object ToJsonModelRef(NameValueConfigurationElement header, Site site, string path) { if (header == null) { return(null); } RedirectHeaderId id = new RedirectHeaderId(site?.Id, path, header.Name); var obj = new { name = header.Name, value = header.Value, id = id.Uuid }; return(Core.Environment.Hal.Apply(Defines.RedirectHeadersResource.Guid, obj, false)); }
internal static object ToJsonModel(NameValueConfigurationElement header, Site site, string path) { if (header == null) { return(null); } RedirectHeaderId id = new RedirectHeaderId(site?.Id, path, header.Name); var obj = new { name = header.Name, value = header.Value, id = id.Uuid, http_response_headers = HttpResponseHeadersHelper.ToJsonModelRef(site, path), }; return(Core.Environment.Hal.Apply(Defines.RedirectHeadersResource.Guid, obj)); }
public object Get(string id) { 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()); } return(RedirectHeadersHelper.ToJsonModel(header, site, headerId.Path)); }
public void Delete(string id) { var headerId = new RedirectHeaderId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } NameValueConfigurationElement header = RedirectHeadersHelper.GetRedirectHeaders(site, headerId.Path).FirstOrDefault(h => h.Name.Equals(headerId.Name, StringComparison.OrdinalIgnoreCase)); if (header != null) { var section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, ManagementUnit.ResolveConfigScope()); RedirectHeadersHelper.Delete(header, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
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); }