示例#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);
        }
示例#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));
        }
示例#3
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()));
        }