Exemple #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));
        }
Exemple #2
0
        public override void Start()
        {
            var host = Environment.Host;

            // Register all controller routes in mvc framework
            host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "HttpRedirect" });

            // Self
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", doc => new { href = RedirectHelper.GetLocation(doc.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = GetDefaultDocumentId(null, null);
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = GetDefaultDocumentId(s, "/");
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => {
                var appId = new ApplicationId((string)app.id);
                Site s    = SiteHelper.GetSite(appId.SiteId);
                var id    = GetDefaultDocumentId(s, appId.Path);
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });
        }
Exemple #3
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));
        }
Exemple #4
0
        public async Task <object> Post()
        {
            if (RedirectHelper.IsFeatureEnabled())
            {
                throw new AlreadyExistsException(RedirectHelper.FEATURE);
            }

            await RedirectHelper.SetFeatureEnabled(true);

            dynamic settings = RedirectHelper.ToJsonModel(null, null);

            return(Created(RedirectHelper.GetLocation(settings.id), settings));
        }
Exemple #5
0
        public object Get()
        {
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

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

            dynamic d = RedirectHelper.ToJsonModel(site, path);

            return(LocationChanged(RedirectHelper.GetLocation(d.id), d));
        }
Exemple #6
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);
            }
        }
Exemple #7
0
 private RedirectId GetDefaultDocumentId(Site site, string path)
 {
     return(new RedirectId(site?.Id, path, RedirectHelper.IsSectionLocal(site, path)));
 }