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
public HttpResponseMessage add(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")); } // 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")); } // Add the post Int64 insertId = StaticPage.AddMasterPost(post); post.id = Convert.ToInt32(insertId); StaticPage.AddLanguagePost(post, languageId); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added")); } // End of the add method
public ActionResult translate(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get all the form values Int32 translationLanguageId = Convert.ToInt32(collection["selectLanguage"]); Int32 id = Convert.ToInt32(collection["hiddenStaticPageId"]); string title = collection["txtTranslatedTitle"]; string linkname = collection["txtTranslatedLinkname"]; string description = collection["txtTranslatedDescription"]; string metadescription = collection["txtTranslatedMetadescription"]; string metakeywords = collection["txtTranslatedMetakeywords"]; string pagename = collection["txtTranslatedPagename"]; bool inactive = Convert.ToBoolean(collection["cbInactive"]); string returnUrl = collection["returnUrl"]; string keywords = collection["txtSearch"]; Int32 currentPage = Convert.ToInt32(collection["hiddenPage"]); // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor", "Translator" }) == true) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Get the standard static page StaticPage standardStaticPage = StaticPage.GetOneById(id, currentDomain.back_end_language); // Get translated texts KeyStringList tt = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); // Create the translated static page StaticPage translatedStaticPage = new StaticPage(); translatedStaticPage.id = id; translatedStaticPage.title = title; translatedStaticPage.link_name = linkname; translatedStaticPage.main_content = description; translatedStaticPage.meta_description = metadescription; translatedStaticPage.meta_keywords = metakeywords; translatedStaticPage.page_name = pagename; translatedStaticPage.inactive = inactive; // Check if the user wants to do a search if (collection["btnSearch"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = 1; ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "name", "ASC"); ViewBag.StandardStaticPage = standardStaticPage; ViewBag.TranslatedStaticPage = translatedStaticPage; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the translate view return View("translate"); } // Check if the user wants to do a search if (collection["btnPreviousPage"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = currentPage - 1; ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "name", "ASC"); ViewBag.StandardStaticPage = standardStaticPage; ViewBag.TranslatedStaticPage = translatedStaticPage; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the translate view return View("translate"); } // Check if the user wants to do a search if (collection["btnNextPage"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = currentPage + 1; ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "name", "ASC"); ViewBag.StandardStaticPage = standardStaticPage; ViewBag.TranslatedStaticPage = translatedStaticPage; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the translate view return View("translate"); } // Create a error message string errorMessage = string.Empty; // Get a static page on page name StaticPage pageOnPageName = StaticPage.GetOneByPageName(translatedStaticPage.page_name, currentDomain.back_end_language); // Check the page name if (pageOnPageName != null && translatedStaticPage.id != pageOnPageName.id) { errorMessage += "• " + String.Format(tt.Get("error_field_language_unique"), tt.Get("page_name")) + "<br/>"; } if (translatedStaticPage.page_name == string.Empty) { errorMessage += "• " + String.Format(tt.Get("error_field_required"), tt.Get("page_name")) + "<br/>"; } if (AnnytabDataValidation.CheckPageNameCharacters(translatedStaticPage.page_name) == false) { errorMessage += "• " + String.Format(tt.Get("error_field_bad_chars"), tt.Get("page_name")) + "<br/>"; } if (translatedStaticPage.page_name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("page_name"), "100") + "<br/>"; } if (translatedStaticPage.title.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "200") + "<br/>"; } if (translatedStaticPage.link_name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("link_name"), "100") + "<br/>"; } if (translatedStaticPage.meta_description.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("meta_description"), "200") + "<br/>"; } if (translatedStaticPage.meta_keywords.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("keywords"), "200") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Get the saved static page StaticPage staticPage = StaticPage.GetOneById(id, translationLanguageId); if (staticPage == null) { // Add a new translated static page StaticPage.AddLanguagePost(translatedStaticPage, translationLanguageId); } else { // Update values for the saved static page staticPage.title = translatedStaticPage.title; staticPage.link_name = translatedStaticPage.link_name; staticPage.main_content = translatedStaticPage.main_content; staticPage.meta_description = translatedStaticPage.meta_description; staticPage.meta_keywords = translatedStaticPage.meta_keywords; staticPage.page_name = translatedStaticPage.page_name; staticPage.inactive = translatedStaticPage.inactive; // Update the static page translation StaticPage.UpdateLanguagePost(staticPage, translationLanguageId); } // Redirect the user to the list return Redirect(returnUrl); } else { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = currentPage; ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "name", "ASC"); ViewBag.StandardStaticPage = standardStaticPage; ViewBag.TranslatedStaticPage = translatedStaticPage; ViewBag.ErrorMessage = errorMessage; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the translate view return View("translate"); } } // End of the translate method
public ActionResult edit(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters string returnUrl = collection["returnUrl"]; ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Get all the form values Int32 id = Convert.ToInt32(collection["txtId"]); string title = collection["txtTitle"]; string linkname = collection["txtLinkname"]; string description = collection["txtDescription"]; string metaDescription = collection["txtMetaDescription"]; string metaKeywords = collection["txtMetaKeywords"]; string pageName = collection["txtPageName"]; string metaRobots = collection["selectMetaRobots"]; byte connectionId = Convert.ToByte(collection["selectConnectionId"]); bool inactive = Convert.ToBoolean(collection["cbInactive"]); // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the static page StaticPage staticPage = StaticPage.GetOneById(id, adminLanguageId); // Check if the static page exists if (staticPage == null) { // Create an empty static page staticPage = new StaticPage(); } // Update values staticPage.title = title; staticPage.link_name = linkname; staticPage.main_content = description; staticPage.meta_description = metaDescription; staticPage.meta_keywords = metaKeywords; staticPage.page_name = pageName; staticPage.meta_robots = metaRobots; staticPage.connected_to_page = connectionId; staticPage.inactive = inactive; // Create a error message string errorMessage = string.Empty; // Get a static page on page name StaticPage pageOnPageName = StaticPage.GetOneByPageName(staticPage.page_name, adminLanguageId); // Check for errors if (pageOnPageName != null && staticPage.id != pageOnPageName.id) { errorMessage += "• " + String.Format(tt.Get("error_field_language_unique"), tt.Get("page_name")) + "<br/>"; } if (staticPage.page_name == string.Empty) { errorMessage += "• " + String.Format(tt.Get("error_field_required"), tt.Get("page_name")) + "<br/>"; } if (AnnytabDataValidation.CheckPageNameCharacters(staticPage.page_name) == false) { errorMessage += "• " + String.Format(tt.Get("error_field_bad_chars"), tt.Get("page_name")) + "<br/>"; } if (staticPage.page_name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("page_name"), "100") + "<br/>"; } if (staticPage.title.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "200") + "<br/>"; } if (staticPage.link_name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("link_name"), "100") + "<br/>"; } if (staticPage.meta_description.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("meta_description"), "200") + "<br/>"; } if (staticPage.meta_keywords.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("keywords"), "200") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Check if we should add or update the static page if (staticPage.id == 0) { // Add the static page Int64 insertId = StaticPage.AddMasterPost(staticPage); staticPage.id = Convert.ToInt32(insertId); StaticPage.AddLanguagePost(staticPage, adminLanguageId); } else { // Update the static page StaticPage.UpdateMasterPost(staticPage); StaticPage.UpdateLanguagePost(staticPage, adminLanguageId); } // Redirect the user to the list return Redirect("/admin_static_pages" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.StaticPage = staticPage; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method