Beispiel #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);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        public object Get()
        {
            string uuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(uuid))
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

            Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value);

            List <NameValueConfigurationElement> headers = CustomHeadersHelper.GetCustomHeaders(site, id.Path);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(headers.Count());

            return(new {
                custom_headers = headers.Select(h => CustomHeadersHelper.ToJsonModelRef(h, site, id.Path))
            });
        }
Beispiel #4
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;
        }