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));
        }
Ejemplo n.º 3
0
        public object Get()
        {
            RewriteHelper.ResolveRewrite(Context, out Site site, out string path);

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

            dynamic d = ProvidersHelper.SectionToJsonModel(site, path);

            return(LocationChanged(ProvidersHelper.GetSectionLocation(d.id), d));
        }
Ejemplo n.º 4
0
        public object Get(string id)
        {
            var rewriteId = new RewriteId(id);

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

            if (rewriteId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            return(ProvidersHelper.SectionToJsonModel(site, rewriteId.Path));
        }
Ejemplo n.º 5
0
        public void Delete(string id)
        {
            var providersId = new RewriteId(id);

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

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

            if (site != null)
            {
                var section = ProvidersHelper.GetSection(site, providersId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
        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 object Get()
        {
            string providersId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(providersId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(providersId);

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

            ProvidersCollection providers = ProvidersHelper.GetSection(site, sectionId.Path).Providers;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(providers.Count());

            return(new {
                entries = providers.Select(provider => ProvidersHelper.ProviderToJsonModelRef(provider, site, sectionId.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;
        }
Ejemplo n.º 9
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var providersId = new RewriteId(id);

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

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

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            ProvidersHelper.UpdateSection(model, site, providersId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(ProvidersHelper.SectionToJsonModel(site, providersId.Path));
        }
Ejemplo n.º 10
0
        private void ConfigureProviders()
        {
            var builder = Environment.Host.RouteBuilder;
            var hal     = Environment.Hal;

            builder.MapWebApiRoute(Defines.ProvidersSectionResource.Guid, $"{Defines.PROVIDERS_SECTION_PATH}/{{id?}}", new { controller = "ProvidersSection" });
            builder.MapWebApiRoute(Defines.ProvidersResource.Guid, $"{Defines.PROVIDERS_PATH}/{{id?}}", new { controller = "Providers" });

            hal.ProvideLink(Defines.ProvidersSectionResource.Guid, "self", p => new { href = ProvidersHelper.GetSectionLocation(p.id) });
            hal.ProvideLink(Defines.ProvidersResource.Guid, "self", p => new { href = ProvidersHelper.GetProviderLocation(p.id) });

            // Rewrite -> Section
            hal.ProvideLink(Defines.Resource.Guid, Defines.ProvidersSectionResource.Name, rewrite => new { href = ProvidersHelper.GetSectionLocation(rewrite.id) });

            // Section -> providers
            hal.ProvideLink(Defines.ProvidersSectionResource.Guid, Defines.ProvidersResource.Name, providersSection => new { href = $"/{Defines.PROVIDERS_PATH}?{Defines.IDENTIFIER}={providersSection.id}" });
        }