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.

110 lines
3.3 KiB

  1. using Business.api.addressy;
  2. using Common;
  3. using Common.Model;
  4. using Common.Model.Addressy;
  5. using log4net;
  6. using Repository;
  7. using Repository.Mobile;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace Business.Addressy
  15. {
  16. public class LocateBusiness
  17. {
  18. private static readonly ILog Log = LogManager.GetLogger(typeof(LocateBusiness));
  19. ServiceApi serviceApi { get; set; }
  20. public LocateBusiness()
  21. {
  22. serviceApi = new ServiceApi();
  23. }
  24. public JsonRxResponse QueryAddress(string postCode)
  25. {
  26. JsonRxResponse rxResponse = new JsonRxResponse() { ErrorCode = "1", Msg = "No Data found" };
  27. var results = serviceApi.Find_v1_10(postCode);
  28. Log.Debug(Newtonsoft.Json.JsonConvert.SerializeObject(results));
  29. if (results != null && results.Any())
  30. {
  31. var single = results.FirstOrDefault();
  32. if (single != null && single.Type.Equals("Postcode"))
  33. {
  34. rxResponse.ErrorCode = "0";
  35. rxResponse.Msg = "Post code found";
  36. var result2 = serviceApi.Find_v1_10(postCode, single.Id);
  37. QueryResponse queryResponsse = new QueryResponse();
  38. queryResponsse.Addresses = new List<Address>();
  39. foreach (Capture_Interactive_Find_v1_10_Results item in result2)
  40. {
  41. queryResponsse.Addresses.Add(new Address()
  42. {
  43. Id = item.Id,
  44. Type = item.Type,
  45. Address1 = item.Text,
  46. City = item.Description.Substring(0, item.Description.LastIndexOf(","))
  47. });
  48. }
  49. rxResponse.Data = queryResponsse;
  50. }
  51. }
  52. else
  53. {
  54. rxResponse.Msg = "No result!";
  55. }
  56. return rxResponse;
  57. }
  58. public QueryResponse LoadKycStaticData()
  59. {
  60. QueryResponse queryResponse = new QueryResponse();
  61. var sql = "EXEC proc_mobile_StaticData @flag='Query-Address'";
  62. Dao _dao = new Dao();
  63. var ds = _dao.ExecuteDataset(sql);
  64. if (ds.Tables.Count == 2)
  65. {
  66. var nativeCountry = ds.Tables[0];
  67. var ncr = from nc in nativeCountry.AsEnumerable()
  68. select new NativeCountry
  69. {
  70. id = nc.Field<int>("id").ToString(),
  71. text = nc.Field<string>("text"),
  72. code = nc.Field<string>("Code")
  73. };
  74. queryResponse.NativeCountry = ncr.ToList();
  75. var gender = ds.Tables[1];
  76. var g = from gd in gender.AsEnumerable()
  77. select new Gender
  78. {
  79. id = gd.Field<int>("id").ToString(),
  80. text = gd.Field<string>("text"),
  81. };
  82. queryResponse.Gender = g.ToList();
  83. }
  84. return queryResponse;
  85. }
  86. }
  87. }