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);
        }
Exemplo n.º 2
0
        public static object ProviderToJsonModel(Provider provider, Site site, string path, Fields fields = null, bool full = true)
        {
            if (provider == null)
            {
                return(null);
            }

            if (fields == null)
            {
                fields = Fields.All;
            }

            var providerId = new ProviderId(site?.Id, path, provider.Name);

            dynamic obj = new ExpandoObject();

            //
            // name
            if (fields.Exists("name"))
            {
                obj.name = provider.Name;
            }

            //
            // id
            if (fields.Exists("id"))
            {
                obj.id = providerId.Uuid;
            }

            //
            // type
            if (fields.Exists("type"))
            {
                obj.type = provider.TypeName;
            }

            //
            // settings
            if (fields.Exists("settings"))
            {
                obj.settings = provider.Settings.Select(s => {
                    return(new {
                        name = s.Key,
                        value = s.Value
                    });
                });
            }

            //
            // url_rewrite
            if (fields.Exists("url_rewrite"))
            {
                obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
            }

            return(Core.Environment.Hal.Apply(Defines.ProvidersResource.Guid, obj));
        }
        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()));
        }
        public void Delete(string id)
        {
            Provider provider   = null;
            var      providerId = new ProviderId(id);

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

            if (providerId.SiteId == null || site != null)
            {
                provider = ProvidersHelper.GetSection(site, providerId.Path).Providers.FirstOrDefault(p => p.Name.Equals(providerId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (provider != null)
            {
                var section = ProvidersHelper.GetSection(site, providerId.Path, ManagementUnit.ResolveConfigScope());

                ProvidersHelper.DeleteProvider(provider, section);
                ManagementUnit.Current.Commit();
            }

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