Example #1
0
        public object GetRedirectsForContent(int contentId)
        {
            try {
                // Get a reference to the content item
                IContent content = ApplicationContext.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 = Repository.GetRedirectsByContentId(contentId)
                }));
            } catch (RedirectsException ex) {
                // Generate the error response
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }
        public object GetRedirectsForContent(int contentId)
        {
            IContent content = ApplicationContext.Services.ContentService.GetById(contentId);

            if (content == null)
            {
                throw new RedirectsException(HttpStatusCode.NotFound, "A content item with the specified ID could not be found.");
            }

            try {
                return(JsonMetaResponse.GetSuccess(new {
                    content = new {
                        id = content.Id,
                        name = content.Name
                    },
                    redirects = Repository.GetRedirectsByContentId(contentId)
                }));
            } catch (RedirectsException ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }