示例#1
1
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var redId = new RedirectId(id);

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

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

            string configPath           = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            HttpRedirectSection section = RedirectHelper.GetRedirectSection(site, redId.Path, configPath);

            RedirectHelper.UpdateFeatureSettings(model, section);

            ManagementUnit.Current.Commit();

            return(RedirectHelper.ToJsonModel(site, redId.Path));
        }
示例#2
0
        public object Get(string id)
        {
            var redId = new RedirectId(id);

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

            return(RedirectHelper.ToJsonModel(site, redId.Path));
        }
        public static object ToJsonModelRef(Site site, string path)
        {
            var section = GetRedirectSection(site, path);
            var redId   = new RedirectId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                enabled = section.Enabled,
                id      = redId.Uuid,
                scope   = site == null ? string.Empty : site.Name + path
            };

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj, false));
        }
        public static object ToJsonModel(Site site, string path)
        {
            var section = GetRedirectSection(site, path);
            var redId   = new RedirectId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                id                = redId.Uuid,
                enabled           = section.Enabled,
                preserve_filename = section.ChildOnly,
                destination       = section.Destination,
                absolute          = section.ExactDestination,
                status_code       = (int)section.HttpResponseStatus,
                scope             = site == null ? string.Empty : site.Name + path,
                metadata          = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                website           = SiteHelper.ToJsonModelRef(site)
            };

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
示例#5
0
        public async Task Delete(string id)
        {
            var redId = new RedirectId(id);

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

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

            if (site != null)
            {
                var section = RedirectHelper.GetRedirectSection(site, redId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }

            if (redId.SiteId == null && RedirectHelper.IsFeatureEnabled())
            {
                await RedirectHelper.SetFeatureEnabled(false);
            }
        }