public object AddRedirect(int rootNodeId, string url, string linkMode, int linkId, string linkUrl, string linkName = null)
        {
            try {
                RedirectLinkItem redirect = RedirectLinkItem.Parse(new JObject {
                    { "id", linkId },
                    { "name", linkName + "" },
                    { "url", linkUrl },
                    { "mode", linkMode }
                });

                return(Repository.AddRedirect(rootNodeId, url, redirect));
            } catch (RedirectsException ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }
Example #2
0
        public object AddRedirect(int rootNodeId, string url, string linkMode, int linkId, string linkUrl, string linkName = null, bool permanent = true, bool regex = false, bool forward = false)
        {
            try {
                // Some input validation
                if (String.IsNullOrWhiteSpace(url))
                {
                    throw new RedirectsException(Localize("redirects/errorNoUrl"));
                }
                if (String.IsNullOrWhiteSpace(linkUrl))
                {
                    throw new RedirectsException(Localize("redirects/errorNoDestination"));
                }
                if (String.IsNullOrWhiteSpace(linkMode))
                {
                    throw new RedirectsException(Localize("redirects/errorNoDestination"));
                }

                // Parse the link mode
                RedirectLinkMode mode;
                switch (linkMode)
                {
                case "content": mode = RedirectLinkMode.Content; break;

                case "media": mode = RedirectLinkMode.Media; break;

                case "url": mode = RedirectLinkMode.Url; break;

                default: throw new RedirectsException(Localize("redirects/errorUnknownLinkMode"));
                }

                // Initialize a new link item
                RedirectLinkItem destination = new RedirectLinkItem(linkId, linkName, linkUrl, mode);

                // Add the redirect
                RedirectItem redirect = Repository.AddRedirect(rootNodeId, url, destination, permanent, regex, forward);

                // Return the redirect
                return(redirect);
            } catch (RedirectsException ex) {
                // Generate the error response
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }