public HttpResponseMessage add(ValueAddedTax post) { // Check for errors if (post == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null")); } // Make sure that the data is valid post.value = AnnytabDataValidation.TruncateDecimal(post.value, 0, 9.99999M); // Add the post ValueAddedTax.Add(post); // 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 id = Convert.ToInt32(collection["txtId"]); decimal percent = 0; decimal.TryParse(collection["txtPercent"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out percent); // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the value added tax ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(id); bool postExists = true; // Check if the value added tax exists if (valueAddedTax == null) { // Create an empty value added tax valueAddedTax = new ValueAddedTax(); postExists = false; } // Update values valueAddedTax.value = percent; // Create a error message string errorMessage = string.Empty; // Check for errors in the value added tax if (valueAddedTax.value < 0 || valueAddedTax.value > 9.99999M) { errorMessage += "• " + String.Format(tt.Get("error_field_range"), tt.Get("percent"), "9.99999") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Check if we should add or update the static text if (postExists == false) { // Add the value added tax ValueAddedTax.Add(valueAddedTax); } else { // Update the value added tax ValueAddedTax.Update(valueAddedTax); } // Redirect the user to the list return Redirect("/admin_value_added_taxes" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.ValueAddedTax = valueAddedTax; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method