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.

84 lines
2.4 KiB

  1. using CustomerOnlineV2.Common.Configs;
  2. using Microsoft.AspNetCore.Http;
  3. using System.Text.RegularExpressions;
  4. namespace CustomerOnlineV2.Common.Helper
  5. {
  6. public static class Utilities
  7. {
  8. public static string GetIpAddressv2(HttpContext httpContext)
  9. {
  10. var ipDetails = httpContext.Connection.RemoteIpAddress;
  11. return ipDetails.ToString();
  12. }
  13. public static string ReadAppSettings(string key)
  14. {
  15. return ConfigurationManager.AppSettings[key];
  16. }
  17. public static string ReadFromAppSettings(string key, string defValue = "")
  18. {
  19. return ConfigurationManager.AppSettings[key] ?? defValue;
  20. }
  21. public static decimal TryParseDecimal(string amount)
  22. {
  23. decimal output;
  24. decimal.TryParse(amount, out output);
  25. return output;
  26. }
  27. public static string GetRowCellValue(object v)
  28. {
  29. try
  30. {
  31. if (v == DBNull.Value)
  32. return "";
  33. else
  34. return v.ToString();
  35. }
  36. catch (Exception)
  37. {
  38. return "";
  39. }
  40. }
  41. public static int GetRowCellValueInt(object v)
  42. {
  43. try
  44. {
  45. if (v == DBNull.Value)
  46. return 101;
  47. else
  48. return Convert.ToInt32(v);
  49. }
  50. catch (Exception)
  51. {
  52. return 101;
  53. }
  54. }
  55. public static string ShowDecimal(string strVal)
  56. {
  57. if (strVal != "")
  58. return string.Format("{0:0,0.00}", double.Parse(strVal));
  59. else
  60. return strVal;
  61. }
  62. public static string GenerateOTP()
  63. {
  64. string[] strChar = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  65. Random random = new Random();
  66. string otpChar = strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] +
  67. strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] +
  68. strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)];
  69. return otpChar;
  70. }
  71. public static bool IsValidEmail(this string email)
  72. {
  73. return Regex.IsMatch(email ?? "", ApplicationConfig.ReadWebConfig("regex"), RegexOptions.IgnoreCase);
  74. }
  75. }
  76. }