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 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.º 3
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;
        }
Ejemplo n.º 4
0
        public static object MapToJsonModel(RewriteMap map, Site site, string path, Fields fields = null, bool full = true)
        {
            if (map == null)
            {
                return(null);
            }

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

            var rewriteMapId = new RewriteMapId(site?.Id, path, map.Name);
            var section      = GetSection(site, path);

            dynamic obj = new ExpandoObject();

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

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

            //
            // default_value
            if (fields.Exists("default_value"))
            {
                obj.default_value = map.DefaultValue;
            }

            //
            // ignore_case
            if (fields.Exists("ignore_case"))
            {
                obj.ignore_case = map.IgnoreCase;
            }

            //
            // mappings
            if (fields.Exists("mappings"))
            {
                obj.mappings = map.KeyValuePairCollection.Select(kvp => new {
                    name  = kvp.Key,
                    value = kvp.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.RewriteMapsResource.Guid, obj, full));
        }