public HttpResponseMessage add(Language 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 && languageId != 0) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The translation language does not exist")); } // Make sure that the data is valid post.name = AnnytabDataValidation.TruncateString(post.name, 50); post.language_code = AnnytabDataValidation.TruncateString(post.language_code, 2); post.country_code = AnnytabDataValidation.TruncateString(post.country_code, 2); // Add the master post Int64 insertId = Language.AddMasterPost(post); post.id = Convert.ToInt32(insertId); // Set the translation language to the same as the language if (languageId == 0) { languageId = post.id; } // Add the language post Language.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 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 languageId = Convert.ToInt32(collection["txtId"]); string name = collection["txtName"]; string languageCode = collection["txtLanguageCode"]; string countryCode = collection["txtCountryCode"]; // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the language Language language = Language.GetOneById(languageId, adminLanguageId); bool postExists = true; // Check if the language exists if (language == null) { // Create an empty language post language = new Language(); language.id = languageId; postExists = false; } // Update values for the language language.name = name; language.language_code = languageCode; language.country_code = countryCode; // Create a error message string errorMessage = string.Empty; // Check for errors in the language if (language.name.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>"; } if (language.language_code.Length > 2) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("language_code"), "2") + "<br/>"; } if (language.country_code.Length > 2) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("country_code"), "2") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Check if we should add or update the language if (postExists == false) { // Add the language long insertId = Language.AddMasterPost(language); language.id = Convert.ToInt32(insertId); Language.AddLanguagePost(language, adminLanguageId); } else { // Update the language Language.UpdateMasterPost(language); Language.UpdateLanguagePost(language, adminLanguageId); } // Redirect the user to the list return Redirect("/admin_languages" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.Language = language; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method