public void Delete(string id) { UrlId urlId = new UrlId(id); Site site = urlId.SiteId == null ? null : SiteHelper.GetSite(urlId.SiteId.Value); if (urlId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } UrlRule url = UrlsHelper.GetUrls(site, urlId.Path).Where(u => u.Url.ToString().Equals(urlId.Url)).FirstOrDefault(); if (url != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, urlId.Path, ManagementUnit.ResolveConfigScope()); UrlsHelper.DeleteUrl(url, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; }
public object Patch(string id, [FromBody] dynamic model) { UrlId urlId = new UrlId(id); Site site = urlId.SiteId == null ? null : SiteHelper.GetSite(urlId.SiteId.Value); if (urlId.SiteId != null && site == null) { return(NotFound()); } UrlRule url = UrlsHelper.GetUrls(site, urlId.Path).FirstOrDefault(u => u.Url.Equals(urlId.Url, StringComparison.OrdinalIgnoreCase)); if (url == null) { return(NotFound()); } string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model); UrlsHelper.UpdateUrl(url, model, site, urlId.Path, configPath); ManagementUnit.Current.Commit(); dynamic urlModel = UrlsHelper.ToJsonModel(url, site, urlId.Path); if (urlModel.id != id) { return(LocationChanged(UrlsHelper.GetLocation(urlModel.id), urlModel)); } return(urlModel); }
public static object ToJsonModelRef(UrlRule url, Site site, string path) { if (url == null) { return(null); } UrlId urlId = new UrlId(site?.Id, path, url.Url); var obj = new { url = url.Url, id = urlId.Uuid, allow = url.Allow }; return(Core.Environment.Hal.Apply(Defines.UrlsResource.Guid, obj, false)); }
internal static object ToJsonModel(UrlRule url, Site site, string path) { if (url == null) { return(null); } UrlId urlId = new UrlId(site?.Id, path, url.Url); var obj = new { url = url.Url, id = urlId.Uuid, allow = url.Allow, request_filtering = RequestFilteringHelper.ToJsonModelRef(site, path) }; return(Core.Environment.Hal.Apply(Defines.UrlsResource.Guid, obj)); }
public object Get(string id) { UrlId urlId = new UrlId(id); Site site = urlId.SiteId == null ? null : SiteHelper.GetSite(urlId.SiteId.Value); if (urlId.SiteId != null && site == null) { return(NotFound()); } UrlRule url = UrlsHelper.GetUrls(site, urlId.Path).FirstOrDefault(u => u.Url.Equals(urlId.Url, StringComparison.OrdinalIgnoreCase)); if (url == null) { return(NotFound()); } return(UrlsHelper.ToJsonModel(url, site, urlId.Path)); }