public AdditionalService get_by_id(Int32 id = 0, Int32 languageId = 0) { // Create the post to return AdditionalService post = AdditionalService.GetOneById(id, languageId); // Return the post return(post); } // End of the get_by_id 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.StandardAdditionalService = AdditionalService.GetOneById(id, adminLanguageId); ViewBag.TranslatedAdditionalService = AdditionalService.GetOneById(id, languageId); ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.ReturnUrl = returnUrl; // Return the view if (ViewBag.StandardAdditionalService != null) { return View("translate"); } else { return Redirect("/admin_additional_services" + returnUrl); } } // End of the translate 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.Units = Unit.GetAll(adminLanguageId, "name", "ASC"); ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.AdditionalService = AdditionalService.GetOneById(id, adminLanguageId); ViewBag.ReturnUrl = returnUrl; // Create a new empty additional service if the service does not exist if (ViewBag.AdditionalService == null) { // Add data to the view ViewBag.AdditionalService = new AdditionalService(); } // Return the edit view return View("edit"); } // End of the edit method
public HttpResponseMessage update(AdditionalService 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 (Unit.MasterPostExists(post.unit_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The unit does not exist")); } else if (ValueAddedTax.MasterPostExists(post.value_added_tax_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The value added tax does not exist")); } // Make sure that the data is valid post.product_code = AnnytabDataValidation.TruncateString(post.product_code, 50); post.name = AnnytabDataValidation.TruncateString(post.name, 100); post.fee = AnnytabDataValidation.TruncateDecimal(post.fee, 0, 9999999999.99M); post.account_code = AnnytabDataValidation.TruncateString(post.account_code, 10); // Get the saved post AdditionalService savedPost = AdditionalService.GetOneById(post.id, languageId); // Check if the service exists if (savedPost == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist")); } // Update the post AdditionalService.UpdateMasterPost(post); AdditionalService.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(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 id = Convert.ToInt32(collection["hiddenAdditionalServiceId"]); string name = collection["txtTranslatedName"]; Int32 value_added_tax_id = Convert.ToInt32(collection["selectValueAddedTax"]); string account_code = collection["txtAccountCode"]; bool inactive = Convert.ToBoolean(collection["cbInactive"]); // Create the translated additional service AdditionalService translatedAdditionalService = new AdditionalService(); translatedAdditionalService.id = id; translatedAdditionalService.name = name; translatedAdditionalService.value_added_tax_id = value_added_tax_id; translatedAdditionalService.account_code = account_code; translatedAdditionalService.inactive = inactive; // Create a error message string errorMessage = string.Empty; // Check for errors if (translatedAdditionalService.name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>"; } if (translatedAdditionalService.value_added_tax_id == 0) { errorMessage += "• " + String.Format(tt.Get("error_select_value"), tt.Get("value_added_tax").ToLower()) + "<br/>"; } if (translatedAdditionalService.account_code.Length > 10) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("account_code"), "10") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Get the saved additional service AdditionalService additionalService = AdditionalService.GetOneById(id, translationLanguageId); if (additionalService == null) { // Add a new translated additional service AdditionalService.AddLanguagePost(translatedAdditionalService, translationLanguageId); } else { // Update the translated additional service additionalService.name = translatedAdditionalService.name; additionalService.value_added_tax_id = translatedAdditionalService.value_added_tax_id; additionalService.account_code = translatedAdditionalService.account_code; additionalService.inactive = translatedAdditionalService.inactive; AdditionalService.UpdateLanguagePost(additionalService, translationLanguageId); } // Redirect the user to the list return Redirect("/admin_additional_services" + returnUrl); } else { // Set form values ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC"); ViewBag.StandardAdditionalService = AdditionalService.GetOneById(id, adminLanguageId); ViewBag.TranslatedAdditionalService = translatedAdditionalService; 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 product_code = collection["txtProductCode"]; string name = collection["txtName"]; decimal fee = 0; decimal.TryParse(collection["txtFee"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out fee); Int32 unit_id = Convert.ToInt32(collection["selectUnit"]); bool price_based_on_mount_time = Convert.ToBoolean(collection["cbPriceBasedOnMountTime"]); Int32 value_added_tax_id = Convert.ToInt32(collection["selectValueAddedTax"]); string account_code = collection["txtAccountCode"]; 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 additional service AdditionalService additionalService = AdditionalService.GetOneById(id, adminLanguageId); // Check if the additional service exists if (additionalService == null) { // Create a empty additional service additionalService = new AdditionalService(); } // Update values additionalService.product_code = product_code; additionalService.name = name; additionalService.fee = fee; additionalService.unit_id = unit_id; additionalService.price_based_on_mount_time = price_based_on_mount_time; additionalService.value_added_tax_id = value_added_tax_id; additionalService.account_code = account_code; additionalService.inactive = inactive; // Create a error message string errorMessage = string.Empty; // Check for errors in the additional service if (additionalService.product_code.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("product_code"), "50") + "<br/>"; } if (additionalService.name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>"; } if (additionalService.fee < 0 || additionalService.fee > 9999999999.99M) { errorMessage += "• " + String.Format(tt.Get("error_field_range"), tt.Get("fee"), "9 999 999 999.99") + "<br/>"; } if (additionalService.account_code.Length > 10) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("account_code"), "10") + "<br/>"; } if (additionalService.unit_id == 0) { errorMessage += "• " + String.Format(tt.Get("error_select_value"), tt.Get("unit").ToLower()) + "<br/>"; } if (additionalService.value_added_tax_id == 0) { errorMessage += "• " + String.Format(tt.Get("error_select_value"), tt.Get("value_added_tax").ToLower()) + "<br/>"; } // Check if there is errors if (errorMessage == "") { // Check if we should add or update the additional service if (additionalService.id == 0) { // Add the additional service Int64 insertId = AdditionalService.AddMasterPost(additionalService); additionalService.id = Convert.ToInt32(insertId); AdditionalService.AddLanguagePost(additionalService, adminLanguageId); } else { // Update the additional service AdditionalService.UpdateMasterPost(additionalService); AdditionalService.UpdateLanguagePost(additionalService, adminLanguageId); } // Redirect the user to the list return Redirect("/admin_additional_services" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.Units = Unit.GetAll(adminLanguageId, "name", "ASC"); ViewBag.AdditionalService = additionalService; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method