public async Task <object> Post([FromBody] dynamic model)
        {
            // Create AppPool
            ApplicationPool pool = AppPoolHelper.CreateAppPool(model);

            if (!await IsAppPoolIdentityAllowed(pool))
            {
                return(null);
            }

            // Save it
            ManagementUnit.ServerManager.ApplicationPools.Add(pool);
            ManagementUnit.Current.Commit();

            // Refresh
            pool = AppPoolHelper.GetAppPool(pool.Name);

            //
            // Create response
            dynamic appPool = (dynamic)AppPoolHelper.ToJsonModel(pool, Context.Request.GetFields());

            // A newly created application should default to started state
            var state = WaitForPoolStatusResolve(pool);

            appPool.status = Enum.GetName(typeof(Status), state == Status.Unknown ? Status.Started : state).ToLower();

            return(Created((string)AppPoolHelper.GetLocation(appPool.id), appPool));
        }
        public object Post([FromBody] dynamic model)
        {
            // Create AppPool
            ApplicationPool pool = AppPoolHelper.CreateAppPool(model);

            EnsureAppPoolIdentityAllowed(pool);

            // Save it
            ManagementUnit.ServerManager.ApplicationPools.Add(pool);
            ManagementUnit.Current.Commit();

            // Refresh
            pool = AppPoolHelper.GetAppPool(pool.Name);

            WaitForPoolStatusResolve(pool);

            //
            // Create response
            dynamic appPool = (dynamic)AppPoolHelper.ToJsonModel(pool, Context.Request.GetFields());

            // A newly created application should default to started state
            if (pool.State == ObjectState.Unknown)
            {
                appPool.status = Enum.GetName(typeof(Status), Status.Started).ToLower();
            }

            return(Created((string)AppPoolHelper.GetLocation(appPool.id), appPool));
        }
        public object Get(string id)
        {
            // Extract the name of the target app pool from the uuid specified in the request
            string name = AppPoolId.CreateFromUuid(id).Name;

            ApplicationPool pool = AppPoolHelper.GetAppPool(name);

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

            return(AppPoolHelper.ToJsonModel(pool, Context.Request.GetFields()));
        }
        public void Delete(string id)
        {
            string name = AppPoolId.CreateFromUuid(id).Name;

            ApplicationPool pool = AppPoolHelper.GetAppPool(name);

            if (pool != null)
            {
                AppPoolHelper.DeleteAppPool(pool);
                ManagementUnit.Current.Commit();
            }

            // Sucess
            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }