Exemple #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);
        }