public async Task <object> Post() { if (DefaultDocumentHelper.IsFeatureEnabled()) { throw new AlreadyExistsException(DefaultDocumentHelper.FEATURE_NAME); } await DefaultDocumentHelper.SetFeatureEnabled(true); dynamic settings = DefaultDocumentHelper.ToJsonModel(null, null); return(Created(DefaultDocumentHelper.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 = DefaultDocumentHelper.ToJsonModel(site, path); return(LocationChanged(DefaultDocumentHelper.GetLocation(d.id), d)); }
public override void Start() { var host = Environment.Host; // Register all controller routes in mvc framework host.RouteBuilder.MapWebApiRoute(Defines.FilesResource.Guid, $"{Defines.FILES_PATH}/{{id?}}", new { controller = "defaultdocumentfiles" }); host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "defaultdocument" }); // // Provide HAL // // Self Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", doc => new { href = DefaultDocumentHelper.GetLocation(doc.id) }); // Files Environment.Hal.ProvideLink(Defines.Resource.Guid, "files", doc => new { href = $"/{Defines.FILES_PATH}?{Defines.IDENTIFIER}={doc.id}" }); // DefaultDocument File Environment.Hal.ProvideLink(Defines.FilesResource.Guid, "self", file => new { href = FilesHelper.GetLocation(file.id) }); // Web Server Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => { var id = GetDefaultDocumentId(null, null); return(new { href = DefaultDocumentHelper.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 = GetDefaultDocumentId(s, "/"); return(new { href = DefaultDocumentHelper.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 = GetDefaultDocumentId(s, appId.Path); return(new { href = DefaultDocumentHelper.GetLocation(id.Uuid) }); }); }