示例#1
0
        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 static object ToJsonModelRef(NameValueConfigurationElement header, Site site, string path)
        {
            if (header == null)
            {
                return(null);
            }

            CustomHeaderId id = new CustomHeaderId(site?.Id, path, header.Name);

            var obj = new {
                name  = header.Name,
                value = header.Value,
                id    = id.Uuid
            };

            return(Core.Environment.Hal.Apply(Defines.CustomHeadersResource.Guid, obj, false));
        }
        internal static object ToJsonModel(NameValueConfigurationElement header, Site site, string path)
        {
            if (header == null)
            {
                return(null);
            }

            CustomHeaderId id = new CustomHeaderId(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.CustomHeadersResource.Guid, obj));
        }
示例#4
0
        public object Get(string id)
        {
            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());
            }

            return(CustomHeadersHelper.ToJsonModel(header, site, headerId.Path));
        }
示例#5
0
        public void Delete(string id)
        {
            var headerId = new CustomHeaderId(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 = CustomHeadersHelper.GetCustomHeaders(site, headerId.Path).FirstOrDefault(h => h.Name.Equals(headerId.Name, StringComparison.OrdinalIgnoreCase));

            if (header != null)
            {
                var section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, ManagementUnit.ResolveConfigScope());

                CustomHeadersHelper.Delete(header, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }