public object Post([FromBody] dynamic model)
        {
            Site   site = ApplicationHelper.ResolveSite(model);
            string path = ApplicationHelper.ResolvePath(model);

            if (site == null)
            {
                throw new ApiArgumentException("site/application");
            }

            Application app = ApplicationHelper.GetApplication(path, site);

            // Create VDir
            VirtualDirectory vdir = VDirHelper.CreateVDir(app, model, _fileProvider);

            // Check case of duplicate vdir. Adding duplicate vdir would result in System.Exception which we don't want to catch
            if (app.VirtualDirectories.Any(v => v.Path.Equals(vdir.Path, StringComparison.OrdinalIgnoreCase)))
            {
                throw new AlreadyExistsException("path");
            }

            // Add new virtual directory to application
            app.VirtualDirectories.Add(vdir);

            // Save it
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic virtualDir = (dynamic)VDirHelper.ToJsonModel(vdir, app, site, Context.Request.GetFields());

            return(Created((string)VDirHelper.GetLocation(virtualDir.id), virtualDir));
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            // Cut off the notion of uuid from beginning of request
            VDirId vdirId = new VDirId(id);

            Site site = SiteHelper.GetSite(vdirId.SiteId);

            // Get the parent application using data encoded in uuid
            Application app = ApplicationHelper.GetApplication(vdirId.AppPath, site);

            // Get the target vdir from the id data
            VirtualDirectory vdir = VDirHelper.GetVDir(vdirId.Path, app);

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

            // Make changes
            VDirHelper.UpdateVirtualDirectory(vdir, model, _fileProvider);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic virtualDir = VDirHelper.ToJsonModel(vdir, app, site, Context.Request.GetFields());

            // Id can change if path is different
            if (virtualDir.id != id)
            {
                return(LocationChanged(VDirHelper.GetLocation(virtualDir.id), virtualDir));
            }

            return(virtualDir);
        }
Ejemplo n.º 3
0
        public override void Start()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "virtualdirectories" });

            // Self
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", vdir => new { href = VDirHelper.GetLocation(vdir.id) });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => new { href = $"/{Defines.PATH}?{Sites.Defines.IDENTIFIER}={site.id}" });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => new { href = $"/{Defines.PATH}?{Applications.Defines.IDENTIFIER}={app.id}" });
        }