public HttpResponseMessage update(OptionType 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.title = AnnytabDataValidation.TruncateString(post.title, 100); post.google_name = AnnytabDataValidation.TruncateString(post.google_name, 50); // Get the saved post OptionType savedPost = OptionType.GetOneById(post.id, languageId); // Check if the post exists if (savedPost == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist")); } // Update the post OptionType.UpdateMasterPost(post); OptionType.UpdateLanguagePost(post, languageId); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful")); } // End of the update method
public ActionResult translate(Int32 id = 0, string returnUrl = "") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // 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 default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get the language id int languageId = 0; if (Request.Params["lang"] != null) { Int32.TryParse(Request.Params["lang"], out languageId); } // Add data to the form ViewBag.LanguageId = languageId; ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC"); ViewBag.StandardOptionType = OptionType.GetOneById(id, adminLanguageId); ViewBag.StandardOptions = Option.GetByOptionTypeId(id, adminLanguageId); ViewBag.TranslatedOptionType = OptionType.GetOneById(id, languageId); ViewBag.TranslatedOptions = Option.GetByOptionTypeId(id, languageId); ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.ReturnUrl = returnUrl; // Return the view if (ViewBag.StandardOptionType != null) { return(View("translate")); } else { return(Redirect("/admin_options" + returnUrl)); } } // End of the translate method
public OptionType get_by_id(Int32 id = 0, Int32 languageId = 0) { // Create the post to return OptionType post = OptionType.GetOneById(id, languageId); // Return the post return(post); } // End of the get_by_id method
public ActionResult edit(Int32 id = 0, string returnUrl = "") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters 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 the default admin language Int32 adminLanguageId = currentDomain.back_end_language; // Add data to the view ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.OptionType = OptionType.GetOneById(id, adminLanguageId); ViewBag.Options = Option.GetByOptionTypeId(id, adminLanguageId); ViewBag.ReturnUrl = returnUrl; // Create new empty options if the option type does not exist if (ViewBag.OptionType == null) { // Add data to the view ViewBag.OptionType = new OptionType(); ViewBag.Options = new List <Option>(); } // Return the edit view return(View("edit")); } // End of the edit method
public ActionResult translate(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", "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 admin default language Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get all the form values Int32 translationLanguageId = Convert.ToInt32(collection["selectLanguage"]); Int32 optionTypeId = Convert.ToInt32(collection["hiddenOptionTypeId"]); string optionTypeTitle = collection["txtTranslatedTitle"]; string[] optionIds = collection.GetValues("optionId"); string[] optionTitles = collection.GetValues("optionTranslatedTitle"); // Create the translated option type OptionType translatedOptionType = new OptionType(); translatedOptionType.id = optionTypeId; translatedOptionType.title = optionTypeTitle; // Create a list of translated options Int32 optionCount = optionIds != null ? optionIds.Length : 0; List <Option> translatedOptions = new List <Option>(optionCount); for (int i = 0; i < optionCount; i++) { // Create a new option Option translatedOption = new Option(); translatedOption.id = Convert.ToInt32(optionIds[i]); translatedOption.title = optionTitles[i]; translatedOption.option_type_id = optionTypeId; // Add the translated option translatedOptions.Add(translatedOption); } // Create a error message string errorMessage = string.Empty; // Check the option type title if (optionTypeTitle.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "200") + "<br/>"; } // Check for errors in options for (int i = 0; i < optionCount; i++) { if (optionTitles[i].Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), optionTitles[i], "50") + "<br/>"; } } // Check if there is errors if (errorMessage == string.Empty) { // Get the saved option type OptionType optionType = OptionType.GetOneById(optionTypeId, translationLanguageId); if (optionType == null) { // Add a new translated option type OptionType.AddLanguagePost(translatedOptionType, translationLanguageId); } else { // Update the translated option type optionType.title = translatedOptionType.title; OptionType.UpdateLanguagePost(optionType, translationLanguageId); } // Translate options for (int i = 0; i < translatedOptions.Count; i++) { // Get the option Option option = Option.GetOneById(translatedOptions[i].id, translationLanguageId); if (option == null) { // Add the translated option Option.AddLanguagePost(translatedOptions[i], translationLanguageId); } else { // Update the option option.title = translatedOptions[i].title; Option.UpdateLanguagePost(option, translationLanguageId); } } // Redirect the user to the list return(Redirect("/admin_options" + returnUrl)); } else { // Set form values ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC"); ViewBag.StandardOptionType = OptionType.GetOneById(optionTypeId, adminLanguageId); ViewBag.StandardOptions = Option.GetByOptionTypeId(optionTypeId, adminLanguageId); ViewBag.TranslatedOptionType = translatedOptionType; ViewBag.TranslatedOptions = translatedOptions; 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 optionTypeId = Convert.ToInt32(collection["txtId"]); string optionTypeTitle = collection["txtTitle"]; string google_name = collection["selectGoogleName"]; string[] optionIds = collection.GetValues("optionId"); string[] optionTitles = collection.GetValues("optionTitle"); string[] optionSuffix = collection.GetValues("optionSuffix"); // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the option type OptionType optionType = OptionType.GetOneById(optionTypeId, adminLanguageId); // Check if the option type exists if (optionType == null) { // Create the option type optionType = new OptionType(); } // Update values optionType.title = optionTypeTitle; optionType.google_name = google_name; // Count the options Int32 optionCount = optionIds != null ? optionIds.Length : 0; // Create the list of options List <Option> options = new List <Option>(optionCount); // Add all options to the list for (int i = 0; i < optionCount; i++) { if (optionTitles[i] != string.Empty) { // Create a option Option option = new Option(); option.id = Convert.ToInt32(optionIds[i]); option.title = optionTitles[i]; option.product_code_suffix = optionSuffix[i]; option.sort_order = Convert.ToInt16(i); option.option_type_id = optionType.id; // Add the option to the list options.Add(option); } } // Create a error message string errorMessage = string.Empty; // Check for errors in the option type if (optionType.title.Length > 200) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "100") + "<br/>"; } if (optionType.google_name.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("google_name"), "50") + "<br/>"; } // Check for errors in options foreach (Option option in options) { if (option.title.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), option.title, "50") + "<br/>"; } if (option.product_code_suffix.Length > 10) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), option.product_code_suffix, "10") + "<br/>"; } } // Check if there is errors if (errorMessage == string.Empty) { // Check if we should add or update the option if (optionType.id == 0) { // Add the option AddOption(optionType, options, adminLanguageId); } else { // Update the option UpdateOption(optionType, options, adminLanguageId); } // Update the option count OptionType.UpdateCount(optionType.id); // Redirect the user to the list return(Redirect("/admin_options" + returnUrl)); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.OptionType = optionType; ViewBag.Options = options; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return(View("edit")); } } // End of the edit method