public HttpResponseMessage translate(StaticPage post, Int32 languageId = 0) { // Check for errors if (post == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null")); } else if (Language.MasterPostExists(languageId) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist")); } else if (StaticPage.MasterPostExists(post.id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The static page does not exist")); } // Make sure that the data is valid post.link_name = AnnytabDataValidation.TruncateString(post.link_name, 100); post.title = AnnytabDataValidation.TruncateString(post.title, 200); post.meta_description = AnnytabDataValidation.TruncateString(post.meta_description, 200); post.meta_keywords = AnnytabDataValidation.TruncateString(post.meta_keywords, 200); post.meta_robots = AnnytabDataValidation.TruncateString(post.meta_robots, 20); post.page_name = AnnytabDataValidation.TruncateString(post.page_name, 100); // Get a static page on page name StaticPage staticPageOnPageName = StaticPage.GetOneByPageName(post.page_name, languageId); // Check if the page name exists if (staticPageOnPageName != null && post.id != staticPageOnPageName.id) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The page name is not unique for the language")); } // Get the post StaticPage savedPost = StaticPage.GetOneById(post.id, languageId); // Check if we should add or update the post if (savedPost == null) { StaticPage.AddLanguagePost(post, languageId); } else { StaticPage.UpdateLanguagePost(post, languageId); } // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The translate was successful")); } // End of the translate method