private void ConfigureIPRestrictions() { // Register controller routes in mvc framework Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "iprestriction" }); // Self Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", ipRes => new { href = IPRestrictionsHelper.GetLocation(ipRes.id) }); // Web Server Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => { var id = GetIPRestrictionId(null, null); return(new { href = IPRestrictionsHelper.GetLocation(id.Uuid) }); }); // Site Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => { var siteId = new SiteId((string)site.id); Site s = SiteHelper.GetSite(siteId.Id); var id = GetIPRestrictionId(s, "/"); return(new { href = IPRestrictionsHelper.GetLocation(id.Uuid) }); }); // Application Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => { var appId = new ApplicationId((string)app.id); Site s = SiteHelper.GetSite(appId.SiteId); var id = GetIPRestrictionId(s, appId.Path); return(new { href = IPRestrictionsHelper.GetLocation(id.Uuid) }); }); }
public async Task <object> Post() { if (IPRestrictionsHelper.IsFeatureEnabled()) { throw new AlreadyExistsException(IPRestrictionsHelper.FEATURE_NAME); } await IPRestrictionsHelper.SetFeatureEnabled(true); dynamic settings = IPRestrictionsHelper.ToJsonModel(null, null); return(Created(IPRestrictionsHelper.GetLocation(settings.id), settings)); }
public object Get() { // Check if the scope of the request is for site or application Site site = ApplicationHelper.ResolveSite(); string path = ApplicationHelper.ResolvePath(); if (path == null) { return(NotFound()); } dynamic d = IPRestrictionsHelper.ToJsonModel(site, path); return(LocationChanged(IPRestrictionsHelper.GetLocation(d.id), d)); }