public HttpResponseMessage add(Country 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.country_code = AnnytabDataValidation.TruncateString(post.country_code, 2); post.name = AnnytabDataValidation.TruncateString(post.name, 50); // Add the post Int64 insertId = Country.AddMasterPost(post); post.id = Convert.ToInt32(insertId); Country.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 the return url 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 name = collection["txtName"]; string countryCode = collection["txtCountryCode"]; byte vatCode = Convert.ToByte(collection["selectVatCode"]); // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the country Country country = Country.GetOneById(id, adminLanguageId); // Check if the country exists (haha) if (country == null) { // Create a empty country country = new Country(); } // Update values country.name = name; country.country_code = countryCode; country.vat_code = vatCode; // Create a error message string errorMessage = string.Empty; // Check for errors in the country if (country.name.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>"; } if (country.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 country if (country.id == 0) { // Add the country Int64 insertId = Country.AddMasterPost(country); country.id = Convert.ToInt32(insertId); Country.AddLanguagePost(country, adminLanguageId); } else { // Update the country Country.UpdateMasterPost(country); Country.UpdateLanguagePost(country, adminLanguageId); } // Redirect the user to the list return Redirect("/admin_countries" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.Country = country; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method