public PaymentOption get_by_id(Int32 id = 0, Int32 languageId = 0) { // Create the post to return PaymentOption post = PaymentOption.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.StandardPaymentOption = PaymentOption.GetOneById(id, adminLanguageId); ViewBag.TranslatedPaymentOption = PaymentOption.GetOneById(id, languageId); ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.ReturnUrl = returnUrl; // Return the view if (ViewBag.StandardPaymentOption != null) { return View("translate"); } else { return Redirect("/admin_payment_options" + returnUrl); } } // End of the translate method
public ActionResult print(Int32 id = 0) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // 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 order Order order = Order.GetOneById(id); // Check if the order is null if (order == null) { return RedirectToAction("index"); } // Set form data ViewBag.CurrentDomain = currentDomain; ViewBag.Order = order; ViewBag.OrderRows = OrderRow.GetByOrderId(order.id); ViewBag.InvoiceCountry = Country.GetOneById(order.invoice_country_id, adminLanguageId); ViewBag.DeliveryCountry = Country.GetOneById(order.delivery_country_id, adminLanguageId); ViewBag.PaymentOption = PaymentOption.GetOneById(order.payment_option, adminLanguageId); ViewBag.Company = Company.GetOneById(order.company_id); ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.CultureInfo = Tools.GetCultureInfo(Language.GetOneById(currentDomain.back_end_language)); // Return the view return View(); } // End of the print 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.PaymentOption = PaymentOption.GetOneById(id, adminLanguageId); ViewBag.ReturnUrl = returnUrl; // Create new empty payment option if the payment option does not exist if (ViewBag.PaymentOption == null) { // Create a new payment option ViewBag.PaymentOption = new PaymentOption(); } // Return the edit view return View("edit"); } // End of the edit method
public HttpResponseMessage update(PaymentOption 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.payment_term_code = AnnytabDataValidation.TruncateString(post.payment_term_code, 10); post.fee = AnnytabDataValidation.TruncateDecimal(post.fee, 0, 9999999999.99M); post.account_code = AnnytabDataValidation.TruncateString(post.account_code, 10); // Get the saved post PaymentOption savedPost = PaymentOption.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 PaymentOption.UpdateMasterPost(post); PaymentOption.UpdateLanguagePost(post, languageId); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful")); } // End of the update method
public async Task <HttpResponseMessage> payex_callback() { // Read the content string content = await Request.Content.ReadAsStringAsync(); // Check for errors if (content == null || content == "") { return(Request.CreateResponse <string>(HttpStatusCode.OK, "FAILURE")); } // Convert the content to a name value collection NameValueCollection collection = System.Web.HttpUtility.ParseQueryString(content); // Get the data string orderRef = collection["orderRef"] != null ? collection["orderRef"] : ""; // Complete the order Dictionary <string, string> response = PayExManager.CompleteOrder(orderRef); // Get response variables string error_code = response.ContainsKey("error_code") == true ? response["error_code"] : ""; string transaction_status = response.ContainsKey("transaction_status") == true ? response["transaction_status"] : ""; string transaction_number = response.ContainsKey("transaction_number") == true ? response["transaction_number"] : ""; string payment_method = response.ContainsKey("payment_method") == true ? response["payment_method"] : ""; bool alreadyCompleted = response.ContainsKey("already_completed") == true?Convert.ToBoolean(response["already_completed"]) : false; Int32 order_id = 0; if (response.ContainsKey("order_id") == true) { Int32.TryParse(response["order_id"], out order_id); } // Get the current domain Domain domain = Tools.GetCurrentDomain(); // Get the order Order order = Order.GetOneById(order_id); // Make sure that the order exists if (order == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The order does not exist")); } // Make sure that callback is accepted if (error_code == "OK") { // Save the transaction number Order.SetPaymentToken(order.id, transaction_number); // Get the payment option PaymentOption paymentOption = PaymentOption.GetOneById(order.payment_option, domain.back_end_language); if (paymentOption.connection == 403 && transaction_status == "3") { // Update the order status Order.UpdatePaymentStatus(order.id, "payment_status_invoice_approved"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if (paymentOption.connection == 402 && transaction_status == "0") { // Update the order status Order.UpdatePaymentStatus(order.id, "payment_status_paid"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if ((paymentOption.connection == 401 || paymentOption.connection == 404) && transaction_status == "0") { // Update the order status Order.UpdatePaymentStatus(order.id, "payment_status_paid"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if (paymentOption.connection == 403 && transaction_status != "5") { // Update the order status Order.UpdatePaymentStatus(order.id, "payment_status_invoice_not_approved"); } } // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "OK")); } // End of the payex_callback 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 customer_email = collection["txtEmail"]; string customer_org_number = collection["txtOrgNumber"]; string customer_vat_number = collection["txtVatNumber"]; string customer_phone = collection["txtPhoneNumber"]; string customer_mobile_phone = collection["txtMobilePhoneNumber"]; string customer_name = collection["txtCustomerName"]; string invoice_name = collection["txtInvoiceName"]; string invoice_address_1 = collection["txtInvoiceAddress1"]; string invoice_address_2 = collection["txtInvoiceAddress2"]; string invoice_post_code = collection["txtInvoicePostCode"]; string invoice_city = collection["txtInvoiceCity"]; string invoice_country_id = collection["selectInvoiceCountry"]; string delivery_name = collection["txtDeliveryName"]; string delivery_address_1 = collection["txtDeliveryAddress1"]; string delivery_address_2 = collection["txtDeliveryAddress2"]; string delivery_post_code = collection["txtDeliveryPostCode"]; string delivery_city = collection["txtDeliveryCity"]; string delivery_country_id = collection["selectDeliveryCountry"]; string payment_status = collection["selectPaymentStatus"]; string order_status = collection["selectOrderStatus"]; bool exported_to_erp = Convert.ToBoolean(collection["cbExportedToErp"]); DateTime desired_date_of_delivery = DateTime.MinValue; DateTime.TryParse(collection["txtDesiredDateOfDelivery"], out desired_date_of_delivery); string discount_code = collection["txtDiscountCode"]; // Get translated texts KeyStringList tt = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); // Get the saved order Order order = Order.GetOneById(id); // Get the payment option PaymentOption paymentOption = PaymentOption.GetOneById(order.payment_option, currentDomain.back_end_language); // Create the error message string string error_message = ""; // Check for errors if (invoice_country_id == "0") { error_message += "• " + String.Format(tt.Get("error_select_value"), tt.Get("invoice_address") + ":" + tt.Get("country").ToLower()) + "<br/>"; } else { order.invoice_country_id = Convert.ToInt32(invoice_country_id); } if (delivery_country_id == "0") { error_message += "• " + String.Format(tt.Get("error_select_value"), tt.Get("delivery_address") + ":" + tt.Get("country").ToLower()) + "<br/>"; } else { order.delivery_country_id = Convert.ToInt32(delivery_country_id); } // Check if the payment status has been updated on the order if(order.document_type == 1 && order.payment_status != payment_status) { // Respond to the updated payment status error_message += UpdatePaymentStatus(order, payment_status); } // Check if the order status has been updated on the order if (order.document_type == 1 && order.order_status != order_status) { // Respond to the updated order status error_message += UpdateOrderStatus(order, paymentOption, order_status); } // Update values order.customer_email = AnnytabDataValidation.TruncateString(customer_email, 100); order.customer_org_number = AnnytabDataValidation.TruncateString(customer_org_number, 20); order.customer_vat_number = AnnytabDataValidation.TruncateString(customer_vat_number, 20); order.customer_phone = AnnytabDataValidation.TruncateString(customer_phone, 100); order.customer_mobile_phone = AnnytabDataValidation.TruncateString(customer_mobile_phone, 100); order.customer_name = AnnytabDataValidation.TruncateString(customer_name, 100); order.invoice_name = AnnytabDataValidation.TruncateString(invoice_name, 100); order.invoice_address_1 = AnnytabDataValidation.TruncateString(invoice_address_1, 100); order.invoice_address_2 = AnnytabDataValidation.TruncateString(invoice_address_2, 100); order.invoice_post_code = AnnytabDataValidation.TruncateString(invoice_post_code, 100); order.invoice_city = AnnytabDataValidation.TruncateString(invoice_city, 100); order.delivery_name = AnnytabDataValidation.TruncateString(delivery_name, 100); order.delivery_address_1 = AnnytabDataValidation.TruncateString(delivery_address_1, 100); order.delivery_address_2 = AnnytabDataValidation.TruncateString(delivery_address_2, 100); order.delivery_post_code = AnnytabDataValidation.TruncateString(delivery_post_code, 100); order.delivery_city = AnnytabDataValidation.TruncateString(delivery_city, 100); order.payment_status = payment_status; order.order_status = order_status; order.exported_to_erp = exported_to_erp; order.desired_date_of_delivery = AnnytabDataValidation.TruncateDateTime(desired_date_of_delivery); order.discount_code = AnnytabDataValidation.TruncateString(discount_code, 50); // Check if there is any errors if(error_message == "") { // Update the order Order.Update(order); // Redirect the user to the list return Redirect("/admin_orders" + returnUrl); } else { // Update the order Order.Update(order); // Add data to the view ViewBag.ErrorMessage = error_message; ViewBag.TranslatedTexts = tt; ViewBag.Order = order; ViewBag.ReturnUrl = returnUrl; // 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 id = Convert.ToInt32(collection["hiddenPaymentOptionId"]); 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 payment option PaymentOption translatedPaymentOption = new PaymentOption(); translatedPaymentOption.id = id; translatedPaymentOption.name = name; translatedPaymentOption.value_added_tax_id = value_added_tax_id; translatedPaymentOption.account_code = account_code; translatedPaymentOption.inactive = inactive; // Create a error message string errorMessage = string.Empty; // Check the translated country name if (translatedPaymentOption.name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>"; } if (translatedPaymentOption.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 payment option PaymentOption paymentOption = PaymentOption.GetOneById(id, translationLanguageId); if (paymentOption == null) { // Add a new translated payment option PaymentOption.AddLanguagePost(translatedPaymentOption, translationLanguageId); } else { // Update the translated payment option paymentOption.name = translatedPaymentOption.name; paymentOption.value_added_tax_id = translatedPaymentOption.value_added_tax_id; paymentOption.account_code = translatedPaymentOption.account_code; paymentOption.inactive = translatedPaymentOption.inactive; PaymentOption.UpdateLanguagePost(paymentOption, translationLanguageId); } // Redirect the user to the list return Redirect("/admin_payment_options" + returnUrl); } else { // Set form values ViewBag.LanguageId = translationLanguageId; ViewBag.Languages = Language.GetAll(adminLanguageId, "id", "ASC"); ViewBag.StandardPaymentOption = PaymentOption.GetOneById(id, adminLanguageId); ViewBag.TranslatedPaymentOption = translatedPaymentOption; 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"]; string payment_term_code = collection["txtPaymentTermCode"]; decimal fee = 0; decimal.TryParse(collection["txtFee"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out fee); Int32 unit_id = Convert.ToInt32(collection["selectUnit"]); Int32 connection = Convert.ToInt32(collection["selectConnection"]); 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 payment option PaymentOption paymentOption = PaymentOption.GetOneById(id, adminLanguageId); // Check if the payment option exists if (paymentOption == null) { // Create a empty payment option paymentOption = new PaymentOption(); } // Update values paymentOption.product_code = product_code; paymentOption.name = name; paymentOption.payment_term_code = payment_term_code; paymentOption.fee = fee; paymentOption.unit_id = unit_id; paymentOption.connection = connection; paymentOption.value_added_tax_id = value_added_tax_id; paymentOption.account_code = account_code; paymentOption.inactive = inactive; // Create a error message string errorMessage = string.Empty; // Check for errors in the payment option if (paymentOption.product_code.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("product_code"), "50") + "<br/>"; } if (paymentOption.name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>"; } if (paymentOption.payment_term_code.Length > 10) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("payment_term_code"), "10") + "<br/>"; } if (paymentOption.fee < 0 || paymentOption.fee > 9999999999.99M) { errorMessage += "• " + String.Format(tt.Get("error_field_range"), tt.Get("fee"), "9 999 999 999.99") + "<br/>"; } if (paymentOption.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 == "") { // Check if we should add or update the payment option if (paymentOption.id == 0) { // Add the payment option Int64 insertId = PaymentOption.AddMasterPost(paymentOption); paymentOption.id = Convert.ToInt32(insertId); PaymentOption.AddLanguagePost(paymentOption, adminLanguageId); } else { // Update the payment option PaymentOption.UpdateMasterPost(paymentOption); PaymentOption.UpdateLanguagePost(paymentOption, adminLanguageId); } // Redirect the user to the list return Redirect("/admin_payment_options" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.Units = Unit.GetAll(adminLanguageId, "name", "ASC"); ViewBag.PaymentOption = paymentOption; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method