public object Patch([FromBody] dynamic model, string id)
        {
            var providerId = new ProviderId(id);

            Site site = providerId.SiteId == null ? null : SiteHelper.GetSite(providerId.SiteId.Value);

            if (providerId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            ProvidersSection section  = ProvidersHelper.GetSection(site, providerId.Path);
            Provider         provider = section.Providers.FirstOrDefault(r => r.Name.Equals(providerId.Name, StringComparison.OrdinalIgnoreCase));

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

            ProvidersHelper.UpdateProvider(model, provider, section);

            ManagementUnit.Current.Commit();

            dynamic updatedProvider = ProvidersHelper.ProviderToJsonModel(provider, site, providerId.Path, Context.Request.GetFields(), true);

            if (updatedProvider.id != id)
            {
                return(LocationChanged(ProvidersHelper.GetProviderLocation(updatedProvider.id), updatedProvider));
            }

            return(updatedProvider);
        }
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);

            if (parentId == null)
            {
                throw new ApiArgumentException("url_rewrite");
            }

            Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value);

            string           configPath = ManagementUnit.ResolveConfigScope(model);
            ProvidersSection section    = ProvidersHelper.GetSection(site, parentId.Path, configPath);

            Provider provider = ProvidersHelper.CreateProvider(model, section);

            // Add it
            ProvidersHelper.AddProvider(provider, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic p = ProvidersHelper.ProviderToJsonModel(provider, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(ProvidersHelper.GetProviderLocation(p.id), p));
        }
        public object Get(string id)
        {
            var providerId = new ProviderId(id);

            Site site = providerId.SiteId == null ? null : SiteHelper.GetSite(providerId.SiteId.Value);

            if (providerId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            Provider provider = ProvidersHelper.GetSection(site, providerId.Path).Providers.FirstOrDefault(p => p.Name.Equals(providerId.Name, StringComparison.OrdinalIgnoreCase));

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

            return(ProvidersHelper.ProviderToJsonModel(provider, site, providerId.Path, Context.Request.GetFields()));
        }