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.

72 lines
3.2 KiB

1 year ago
  1. using Common;
  2. using Common.Helper;
  3. using Common.KFTC;
  4. using Common.Model;
  5. using Common.Model.Config;
  6. using log4net;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Runtime.Remoting.Messaging;
  12. namespace Repository.TrustDoc
  13. {
  14. public class TrustDocRepository : ITrustDocRepository
  15. {
  16. private readonly Dao _dao = null;
  17. private static readonly ILog Log = LogManager.GetLogger(typeof(TrustDocRepository));
  18. public TrustDocRepository()
  19. {
  20. _dao = new Dao();
  21. }
  22. public JsonRxResponse Webhook(TrustDocModel doc)
  23. {
  24. var lang = Convert.ToString(CallContext.GetData(Constants.Language));
  25. JsonRxResponse jsonRx = new JsonRxResponse();
  26. try
  27. {
  28. var sql = "EXEC PROC_TRUSTDOC_CUSTOMER";
  29. sql += " @flag =" + _dao.FilterString("i");
  30. sql += " ,@id =" +"'"+ doc.Data.Id + "'";
  31. sql += " ,@publicId=" + "'" + doc.Data.PublicId + "'";
  32. sql += " ,@verificationType =" + _dao.FilterString(doc.Type);
  33. sql += " ,@state =" + _dao.FilterString(doc.Data.State.ToString());
  34. sql += " ,@result =" + _dao.FilterString( !string.IsNullOrEmpty(doc.Data.Result)? doc.Data.Result:"");
  35. sql += " ,@acceptedDate =" + _dao.FilterString( doc.Data.AcceptedAt.HasValue? doc.Data.AcceptedAt.ToString():"");
  36. sql += " ,@planSelectedDate =" + _dao.FilterString(doc.Data.PlansSelectedAt.HasValue? doc.Data.PlansSelectedAt.ToString():"");
  37. sql += " ,@documentSubmittedDate =" + _dao.FilterString(doc.Data.DocumentSubmittedAt.HasValue? doc.Data.DocumentSubmittedAt.ToString():"");
  38. sql += " ,@trustDocRequest =" + _dao.FilterString(JsonConvert.SerializeObject(doc));
  39. if (doc.Data.Records != null)
  40. {
  41. sql += " ,@planId1=" + "'" + doc.Data.Records[0].Plan.Id.ToString() + "'";
  42. sql += " ,@planName1= " + "N'" + doc.Data.Records[0].Plan.Name + "'";
  43. if (doc.Data.Records.Length > 1)
  44. {
  45. sql += " ,@planId2 = " +_dao.FilterString( doc.Data.Records[1].Plan.Id.ToString());
  46. sql += " ,@planName2= " + "N'" + doc.Data.Records[1].Plan.Name + "'";
  47. }
  48. }
  49. Log.DebugFormat("SaveTrustDoc | SQL : {0}", sql);
  50. var dataSet = _dao.ParseDbResult(sql);
  51. string enumString = string.Empty;
  52. jsonRx.ErrorCode = dataSet.ResponseCode;
  53. jsonRx.Id = dataSet.Id;
  54. //return jsonRx;
  55. var map = Utilities.GetLanguageMapping(enumString, lang);
  56. return new JsonRxResponse { ErrorCode = dataSet.ResponseCode.Equals("0") ? "0" : "1", Msg = map.Message, Id = dataSet.Id };
  57. }
  58. catch (Exception e)
  59. {
  60. Log.DebugFormat($"Exception : {e.StackTrace.ToString()}");
  61. jsonRx.ErrorCode = "1";
  62. jsonRx.Msg = e.Message.ToString();
  63. return jsonRx;
  64. }
  65. }
  66. }
  67. }