public object AddRedirect([FromBody] JObject m) { var model = m.ToObject <AddRedirectOptions>(); try { // Some input validation if (string.IsNullOrWhiteSpace(model.OriginalUrl)) { throw new RedirectsException(Localize("redirects/errorNoUrl") + "----"); } if (string.IsNullOrWhiteSpace(model.Destination?.Url)) { throw new RedirectsException(Localize("redirects/errorNoDestination") + "\r\n\r\n" + m); } // Add the redirect RedirectItem redirect = _redirects.AddRedirect(model); // Return the redirect return(redirect); } catch (RedirectsException ex) { // Generate the error response return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message))); } }
public ActionResult AddRedirect([FromBody] JObject m) { AddRedirectOptions model = m.ToObject <AddRedirectOptions>(); try { // Some input validation if (model == null) { throw new RedirectsException("Failed parsing request body."); } if (string.IsNullOrWhiteSpace(model.OriginalUrl)) { throw new RedirectsException(_backOffice.Localize("errorNoUrl")); } if (string.IsNullOrWhiteSpace(model.Destination?.Url)) { throw new RedirectsException(_backOffice.Localize("errorNoDestination")); } // Add the redirect IRedirect redirect = _redirects.AddRedirect(model); // Map the result for the API return(new JsonResult(_backOffice.Map(redirect))); } catch (RedirectsException ex) { if (!ex.Is404) { _logger.LogError(ex, ex.Message); } // Generate the error response return(Error(ex)); } }
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 = _redirects.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))); } }