コード例 #1
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            // Cut off the notion of uuid from beginning of request
            ApplicationId appId = new ApplicationId(id);

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

            Application app = ApplicationHelper.GetApplication(appId.Path, site);

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

            ApplicationHelper.UpdateApplication(app, site, model);

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


            //
            // Create response
            dynamic application = ApplicationHelper.ToJsonModel(app, site, Context.Request.GetFields());

            // The Id could change by changing path.
            if (application.id != id)
            {
                return(LocationChanged(ApplicationHelper.GetLocation(application.id), application));
            }

            return(application);
        }
コード例 #2
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            Site site = SiteHelper.ResolveSite(model);

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

            // Create app
            Application app = ApplicationHelper.CreateApplication(model, site);

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

            // Add to site
            app = site.Applications.Add(app);

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

            //
            // Create response
            dynamic application = (dynamic)ApplicationHelper.ToJsonModel(app, site, Context.Request.GetFields());

            return(Created((string)ApplicationHelper.GetLocation(application.id), application));
        }
コード例 #3
0
        public override void Start()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "applications" });

            var hal = Environment.Hal;

            hal.ProvideLink(Defines.Resource.Guid, "self", app => new { href = ApplicationHelper.GetLocation(app.id) });
            hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => new { href = $"/{Defines.PATH}?{Sites.Defines.IDENTIFIER}={site.id}" });
            hal.ProvideLink(AppPools.Defines.Resource.Guid, Defines.Resource.Name, pool => new { href = $"/{Defines.PATH}?{AppPools.Defines.IDENTIFIER}={pool.id}" });
        }