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 object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.http_response_headers == null)
            {
                throw new ApiArgumentException("http_response_headers");
            }
            if (!(model.http_response_headers is JObject))
            {
                throw new ApiArgumentException("http_response_headers");
            }

            string uuid = DynamicHelper.Value(model.http_response_headers.id);

            if (uuid == null)
            {
                throw new ApiArgumentException("http_response_headers.id");
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

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

            string configPath           = ManagementUnit.ResolveConfigScope(model);
            HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, id.Path, configPath);

            NameValueConfigurationElement header = RedirectHeadersHelper.Create(model, section);

            RedirectHeadersHelper.Add(header, section);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic h = RedirectHeadersHelper.ToJsonModel(header, site, id.Path);

            return(Created(RedirectHeadersHelper.GetLocation(h.id), h));
        }
        public object Get()
        {
            string uuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(uuid))
            {
                return(NotFound());
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

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

            List <NameValueConfigurationElement> headers = RedirectHeadersHelper.GetRedirectHeaders(site, id.Path);

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

            return(new {
                redirect_headers = headers.Select(h => RedirectHeadersHelper.ToJsonModelRef(h, site, id.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);
        }
Example #6
0
        private void ConfigureRedirectHeaders()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.RedirectHeadersResource.Guid, $"{Defines.REDIRECT_HEADERS_PATH}/{{id?}}", new { controller = "redirectheaders" });

            Environment.Hal.ProvideLink(Defines.RedirectHeadersResource.Guid, "self", redHeader => new { href = RedirectHeadersHelper.GetLocation(redHeader.id) });

            Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.RedirectHeadersResource.Name, redHeader => new { href = $"/{Defines.REDIRECT_HEADERS_PATH}?{Defines.IDENTIFIER}={redHeader.id}" });
        }