Ejemplo n.º 1
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var rewriteMapId = new RewriteMapId(id);

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

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

            RewriteMapsSection section = RewriteMapsHelper.GetSection(site, rewriteMapId.Path);
            RewriteMap         map     = section.RewriteMaps.FirstOrDefault(r => r.Name.Equals(rewriteMapId.Name, StringComparison.OrdinalIgnoreCase));

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

            RewriteMapsHelper.UpdateMap(model, map, section);

            ManagementUnit.Current.Commit();

            dynamic updatedMap = RewriteMapsHelper.MapToJsonModel(map, site, rewriteMapId.Path, Context.Request.GetFields(), true);

            if (updatedMap.id != id)
            {
                return(LocationChanged(RewriteMapsHelper.GetMapLocation(updatedMap.id), updatedMap));
            }

            return(updatedMap);
        }
Ejemplo n.º 2
0
        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);
            RewriteMapsSection section    = RewriteMapsHelper.GetSection(site, parentId.Path, configPath);

            RewriteMap map = RewriteMapsHelper.CreateMap(model, section);

            RewriteMapsHelper.AddMap(map, section);

            ManagementUnit.Current.Commit();

            dynamic r = RewriteMapsHelper.MapToJsonModel(map, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(RewriteMapsHelper.GetMapLocation(r.id), r));
        }
        public object Get()
        {
            RewriteHelper.ResolveRewrite(Context, out Site site, out string path);

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

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

            return(LocationChanged(RewriteMapsHelper.GetSectionLocation(d.id), d));
        }
        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(RewriteMapsHelper.SectionToJsonModel(site, rewriteId.Path));
        }
        public void Delete(string id)
        {
            var rewriteMapsId = new RewriteId(id);

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

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

            if (site != null)
            {
                var section = RewriteMapsHelper.GetSection(site, rewriteMapsId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
Ejemplo n.º 6
0
        public object Get(string id)
        {
            var rewriteMapId = new RewriteMapId(id);

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

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

            RewriteMap map = RewriteMapsHelper.GetSection(site, rewriteMapId.Path).RewriteMaps.FirstOrDefault(m => m.Name.Equals(rewriteMapId.Name, StringComparison.OrdinalIgnoreCase));

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

            return(RewriteMapsHelper.MapToJsonModel(map, site, rewriteMapId.Path, Context.Request.GetFields()));
        }
Ejemplo n.º 7
0
        public object Get()
        {
            string rewriteMapsId = Context.Request.Query[Defines.IDENTIFIER];

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

            var sectionId = new RewriteId(rewriteMapsId);

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

            RewriteMapCollection maps = RewriteMapsHelper.GetSection(site, sectionId.Path).RewriteMaps;

            this.Context.Response.SetItemsCount(maps.Count());

            return(new {
                entries = maps.Select(map => RewriteMapsHelper.MapToJsonModelRef(map, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
Ejemplo n.º 8
0
        public void Delete(string id)
        {
            RewriteMap map          = null;
            var        rewriteMapId = new RewriteMapId(id);

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

            if (rewriteMapId.SiteId == null || site != null)
            {
                map = RewriteMapsHelper.GetSection(site, rewriteMapId.Path).RewriteMaps.FirstOrDefault(m => m.Name.Equals(rewriteMapId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (map != null)
            {
                var section = RewriteMapsHelper.GetSection(site, rewriteMapId.Path, ManagementUnit.ResolveConfigScope());

                RewriteMapsHelper.DeleteMap(map, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var rewriteMapsId = new RewriteId(id);

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

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

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

            RewriteMapsHelper.UpdateSection(model, site, rewriteMapsId.Path, configPath);

            ManagementUnit.Current.Commit();

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

            builder.MapWebApiRoute(Defines.RewriteMapsSectionResource.Guid, $"{Defines.REWRITE_MAPS_SECTION_PATH}/{{id?}}", new { controller = "RewriteMapsSection" });
            builder.MapWebApiRoute(Defines.RewriteMapsResource.Guid, $"{Defines.REWRITE_MAPS_PATH}/{{id?}}", new { controller = "RewriteMaps" });

            // () -> Self
            hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, "self", sv => new { href = RewriteMapsHelper.GetSectionLocation(sv.id) });
            hal.ProvideLink(Defines.RewriteMapsResource.Guid, "self", ir => new { href = RewriteMapsHelper.GetMapLocation(ir.id) });

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

            // Section -> Maps
            hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, Defines.RewriteMapsResource.Name, section => new { href = $"/{Defines.REWRITE_MAPS_PATH}?{Defines.IDENTIFIER}={section.id}" });
        }