public object Patch(string id, [FromBody] dynamic model)
        {
            HeaderLimitId headerLimitId = new HeaderLimitId(id);

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

            if (headerLimitId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string      configPath  = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            HeaderLimit headerLimit = HeaderLimitsHelper.GetHeaderLimits(site, headerLimitId.Path, configPath)
                                      .FirstOrDefault(h => h.Header.ToString().Equals(headerLimitId.Header));

            if (headerLimit == null)
            {
                return(NotFound());
            }

            headerLimit = HeaderLimitsHelper.UpdateHeaderLimit(headerLimit, model);

            ManagementUnit.Current.Commit();

            dynamic head = HeaderLimitsHelper.ToJsonModel(headerLimit, site, headerLimitId.Path);

            if (head.id != id)
            {
                return(LocationChanged(HeaderLimitsHelper.GetLocation(head.id), head));
            }

            return(head);
        }
예제 #2
0
        public static object ToJsonModelRef(HeaderLimit headerLimit, Site site, string path)
        {
            if (headerLimit == null)
            {
                return(null);
            }

            HeaderLimitId id = new HeaderLimitId(site?.Id, path, headerLimit.Header);

            var obj = new {
                header     = headerLimit.Header,
                id         = id.Uuid,
                size_limit = headerLimit.SizeLimit
            };

            return(Core.Environment.Hal.Apply(Defines.HeaderLimitsResource.Guid, obj, false));
        }
예제 #3
0
        internal static object ToJsonModel(HeaderLimit headerLimit, Site site, string path)
        {
            if (headerLimit == null)
            {
                return(null);
            }

            HeaderLimitId id = new HeaderLimitId(site?.Id, path, headerLimit.Header);

            var obj = new {
                header            = headerLimit.Header,
                id                = id.Uuid,
                size_limit        = headerLimit.SizeLimit,
                request_filtering = RequestFilteringHelper.ToJsonModelRef(site, path)
            };

            return(Core.Environment.Hal.Apply(Defines.HeaderLimitsResource.Guid, obj));
        }
        public object Get(string id)
        {
            HeaderLimitId headerId = new HeaderLimitId(id);

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

            if (headerId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            HeaderLimit headerLimit = HeaderLimitsHelper.GetHeaderLimits(site, headerId.Path).FirstOrDefault(h => h.Header.Equals(headerId.Header));

            if (headerLimit == null)
            {
                return(NotFound());
            }

            return(HeaderLimitsHelper.ToJsonModel(headerLimit, site, headerId.Path));
        }
        public void Delete(string id)
        {
            HeaderLimitId headerId = new HeaderLimitId(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;
            }

            HeaderLimit headerLimit = HeaderLimitsHelper.GetHeaderLimits(site, headerId.Path).Where(h => h.Header.ToString().Equals(headerId.Header)).FirstOrDefault();

            if (headerLimit != null)
            {
                var section = RequestFilteringHelper.GetRequestFilteringSection(site, headerId.Path, ManagementUnit.ResolveConfigScope());

                HeaderLimitsHelper.DeleteHeaderLimit(headerLimit, section);
                ManagementUnit.Current.Commit();
            }

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