Example #1
0
        public object GetRedirectsForContent(int contentId)
        {
            try {
                // Get a reference to the content item
                IContent content = Current.Services.ContentService.GetById(contentId);

                // Trigger an exception if the content item couldn't be found
                if (content == null)
                {
                    throw new RedirectsException(HttpStatusCode.NotFound, Localize("redirects/errorContentNoRedirects"));
                }

                // Generate the response
                return(JsonMetaResponse.GetSuccess(new {
                    content = new {
                        id = content.Id,
                        name = content.Name
                    },
                    redirects = _redirects.GetRedirectsByContentId(contentId)
                }));
            } catch (RedirectsException ex) {
                // Generate the error response
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }