You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.4 KiB

  1. using CustomerOnlineRemit.Common.Configuration;
  2. using CustomerOnlineRemit.Common.Model.Customer;
  3. using Newtonsoft.Json;
  4. using System.Data;
  5. using System.Text.Json.Serialization;
  6. namespace CustomerOnlineRemit.Common.Helper
  7. {
  8. public static class Utilities
  9. {
  10. public static string GetRowCellValue(object v)
  11. {
  12. try
  13. {
  14. if (v == DBNull.Value)
  15. return "";
  16. else
  17. return v.ToString();
  18. }
  19. catch (Exception)
  20. {
  21. return "";
  22. }
  23. }
  24. public static decimal TryParseDecimal(string amount)
  25. {
  26. decimal output;
  27. decimal.TryParse(amount, out output);
  28. return output;
  29. }
  30. public static dynamic ParseTableData(string flag, DataTable dt)
  31. {
  32. dynamic list = null;
  33. if (flag.ToLower().Equals("customertxn"))
  34. {
  35. List<CustomerTransaction> obj = new List<CustomerTransaction>();
  36. foreach (DataRow item in dt.Rows)
  37. {
  38. obj.Add(new CustomerTransaction
  39. {
  40. Id = Convert.ToString(item["Id"]),
  41. Amount = Convert.ToString(item["Amount"]),
  42. Status = Convert.ToString(item["Status"])
  43. });
  44. }
  45. list = obj;
  46. }
  47. else if (flag.ToLower().Equals("customerreceiver"))
  48. {
  49. List<CustomerModel> obj = new List<CustomerModel>();
  50. foreach (DataRow item in dt.Rows)
  51. {
  52. obj.Add(new CustomerModel
  53. {
  54. Id = Convert.ToString(item["Id"]),
  55. Name = Convert.ToString(item["Name"]),
  56. Country = Convert.ToString(item["Country"]),
  57. TransactionType = Convert.ToString(item["TransactionType"])
  58. });
  59. }
  60. list = obj;
  61. }
  62. return list;
  63. }
  64. public static string ReadFromAppSettings(string key, string defValue = "")
  65. {
  66. return ConfigurationManager.AppSettings[key] ?? defValue;
  67. }
  68. public static string SerializeObject(object obj)
  69. {
  70. return JsonConvert.SerializeObject(obj);
  71. }
  72. }
  73. }