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.

144 lines
4.8 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar.Base;
  4. using System;
  5. namespace EasyBL.WEBAPP.SYS
  6. {
  7. public class Holidays_SetService : ServiceBase
  8. {
  9. #region 假日設定(單筆查詢)
  10. /// <summary>
  11. /// 假日設定(單筆查詢)
  12. /// </summary>
  13. /// <param name="i_crm"></param>
  14. /// <returns></returns>
  15. public ResponseMessage QueryOne(RequestMessage i_crm)
  16. {
  17. ResponseMessage rm = null;
  18. string sMsg = null;
  19. var db = SugarBase.GetIntance();
  20. try
  21. {
  22. do
  23. {
  24. var sYear = _fetchString(i_crm, @"Year");
  25. var oEntity = db.Queryable<OTB_SYS_Holidays>()
  26. .Single(x => x.OrgID == i_crm.ORIGID && x.Year == sYear);
  27. rm = new SuccessResponseMessage(null, i_crm);
  28. rm.DATA.Add(BLWording.REL, oEntity);
  29. } while (false);
  30. }
  31. catch (Exception ex)
  32. {
  33. sMsg = Util.GetLastExceptionMsg(ex);
  34. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Holidays_SetService), "", "QueryOne(假日設定(單筆查詢))", "", "", "");
  35. }
  36. finally
  37. {
  38. if (null != sMsg)
  39. {
  40. rm = new ErrorResponseMessage(sMsg, i_crm);
  41. }
  42. }
  43. return rm;
  44. }
  45. #endregion 假日設定(單筆查詢)
  46. #region 假日設定(新增)
  47. /// <summary>
  48. /// 假日設定(新增)
  49. /// </summary>
  50. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  51. /// <returns></returns>
  52. public ResponseMessage Insert(RequestMessage i_crm)
  53. {
  54. ResponseMessage rm = null;
  55. string sMsg = null;
  56. try
  57. {
  58. rm = SugarBase.ExecTran(db =>
  59. {
  60. do
  61. {
  62. var oEntity = _fetchEntity<OTB_SYS_Holidays>(i_crm);
  63. _setEntityBase(oEntity, i_crm);
  64. var iRel = db.Insertable(oEntity).ExecuteCommand();
  65. rm = new SuccessResponseMessage(null, i_crm);
  66. rm.DATA.Add(BLWording.REL, iRel);
  67. } while (false);
  68. return rm;
  69. });
  70. }
  71. catch (Exception ex)
  72. {
  73. sMsg = Util.GetLastExceptionMsg(ex);
  74. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Holidays_SetService), @"假日設定", @"Add(假日設定(新增))", @"", @"", @"");
  75. }
  76. finally
  77. {
  78. if (null != sMsg)
  79. {
  80. rm = new ErrorResponseMessage(sMsg, i_crm);
  81. }
  82. }
  83. return rm;
  84. }
  85. #endregion 假日設定(新增)
  86. #region 假日設定(修改)
  87. /// <summary>
  88. /// 假日設定(修改)
  89. /// </summary>
  90. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  91. /// <returns></returns>
  92. public ResponseMessage Update(RequestMessage i_crm)
  93. {
  94. ResponseMessage rm = null;
  95. string sMsg = null;
  96. try
  97. {
  98. rm = SugarBase.ExecTran(db =>
  99. {
  100. do
  101. {
  102. var oNewEntity = _fetchEntity<OTB_SYS_Holidays>(i_crm);
  103. _setEntityBase(oNewEntity, i_crm);
  104. var iRel = db.Updateable(oNewEntity)
  105. .IgnoreColumns(x => new
  106. {
  107. x.CreateUser,
  108. x.CreateDate
  109. }).ExecuteCommand();
  110. rm = new SuccessResponseMessage(null, i_crm);
  111. rm.DATA.Add(BLWording.REL, iRel);
  112. } while (false);
  113. return rm;
  114. });
  115. }
  116. catch (Exception ex)
  117. {
  118. sMsg = Util.GetLastExceptionMsg(ex);
  119. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Holidays_SetService), @"假日設定", @"Update(假日設定(修改))", @"", @"", @"");
  120. }
  121. finally
  122. {
  123. if (null != sMsg)
  124. {
  125. rm = new ErrorResponseMessage(sMsg, i_crm);
  126. }
  127. }
  128. return rm;
  129. }
  130. #endregion 假日設定(修改)
  131. }
  132. }