TestMt.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Common;
  2. using Common.Logic;
  3. using Common.Singleton;
  4. using Database.Database;
  5. namespace MyKungKangWorker.Utils
  6. {
  7. public class TestMt
  8. {
  9. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  10. public static async Task<bool> TestMtHandler(
  11. IConfiguration configuration,
  12. ModelContext dbContext
  13. )
  14. {
  15. log.Debug("START WEEKLY term drawer");
  16. try
  17. {
  18. // get all mts
  19. // get message
  20. string contentLuckyCode = "";
  21. string contentTurn = "";
  22. string langGet = "";
  23. //List<Config> configs = dbContext.Configs.Where(x =>
  24. // // x.ParamName == "ADD_RENEW_LUCKYCODE" ||
  25. // x.ParamName == "ADD_WEEKLY_OVER_PRIZE_LUCKYCODE" ||
  26. // x.ParamName == "ADD_WEEKLY_OVER_PRIZE_TURN" ||
  27. // x.ParamName == "SMS_LANG"
  28. // ).ToList();
  29. CommonConfig commonConfig = CommonConfig.Instance;
  30. List<Config>? configs = commonConfig.GetConfig(
  31. new List<string>
  32. {
  33. "ADD_RENEW_LUCKYCODE",
  34. "ADD_WEEKLY_OVER_PRIZE_LUCKYCODE",
  35. "ADD_WEEKLY_OVER_PRIZE_TURN",
  36. "SMS_LANG"
  37. }
  38. );
  39. if (configs != null && configs.Count > 0)
  40. {
  41. var lang = configs.Find(x => x.ParamName == "SMS_LANG");
  42. var luckyCodeMessage = configs.Find(
  43. x => x.ParamName == "ADD_WEEKLY_OVER_PRIZE_LUCKYCODE"
  44. );
  45. var turnMessage = configs.Find(
  46. x => x.ParamName == "ADD_WEEKLY_OVER_PRIZE_TURN"
  47. );
  48. if (lang != null && lang.ParamValue == "MY")
  49. {
  50. langGet = "MY";
  51. if (luckyCodeMessage != null)
  52. {
  53. contentLuckyCode = luckyCodeMessage.ParamValueFr!;
  54. }
  55. if (turnMessage != null)
  56. {
  57. contentTurn = turnMessage.ParamValueFr!;
  58. }
  59. }
  60. else
  61. {
  62. langGet = "EN";
  63. if (luckyCodeMessage != null)
  64. {
  65. contentLuckyCode = luckyCodeMessage.ParamValue!;
  66. }
  67. if (turnMessage != null)
  68. {
  69. contentTurn = turnMessage.ParamValue!;
  70. }
  71. }
  72. }
  73. // for one lucky code user prize lately
  74. string code = CommonLogic.GenerateUniqueNumber();
  75. string content = contentLuckyCode.Replace("%code%", code).Replace("%number%", "1");
  76. log.Debug("Send mt adding 1 lucky code for 2 person more to test");
  77. _ = Connector.SentMtAsync(dbContext, "", content);
  78. string codes =
  79. CommonLogic.GenerateUniqueNumber()
  80. + (langGet == "EN" ? ", " : " နှင့် ")
  81. + CommonLogic.GenerateUniqueNumber();
  82. content = contentLuckyCode.Replace("%code%", codes).Replace("%number%", "2");
  83. log.Debug("Send mt adding 2 lucky code for 2 person more to test");
  84. _ = Connector.SentMtAsync(dbContext, "", content);
  85. }
  86. catch (Exception ex)
  87. {
  88. log.Error("Exception: ", ex);
  89. }
  90. return false;
  91. }
  92. }
  93. }