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.

455 lines
18 KiB

1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
  1. using Business.Authentication;
  2. using Business.KftcPasswordRule;
  3. using Business.Mobile;
  4. using Common;
  5. using Common.Helper;
  6. using Common.Language;
  7. using Common.Model;
  8. using Common.Model.Config;
  9. using Common.Model.RequestOTP;
  10. using JsonRx.AuthFilter;
  11. using JsonRx.Helper;
  12. using log4net;
  13. using Newtonsoft.Json;
  14. using PushNotification;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Runtime.Remoting.Messaging;
  19. using System.Threading.Tasks;
  20. using System.Web.Http;
  21. using System.Web.Http.ModelBinding;
  22. using System.Web.Routing;
  23. namespace JsonRx.Api
  24. {
  25. /// <summary>
  26. /// </summary>
  27. [RoutePrefix("api/v1")]
  28. //[EnableCors("*", "*", "*")]
  29. public class MobileController : ApiController
  30. {
  31. private readonly IMobileServices _requestServices;
  32. private readonly IAuthenticationBusiness _authenticationBusiness;
  33. private static readonly ILog Log = LogManager.GetLogger(typeof(MobileController));
  34. /// <summary>
  35. /// </summary>
  36. public MobileController() { }
  37. /// <summary>
  38. /// </summary>
  39. /// <param name="requestServices"></param>
  40. /// <param name="authenticationBusiness"></param>
  41. public MobileController(IMobileServices requestServices, IAuthenticationBusiness authenticationBusiness)
  42. {
  43. _requestServices = requestServices;
  44. _authenticationBusiness = authenticationBusiness;
  45. }
  46. /// <summary>
  47. /// </summary>
  48. /// <returns></returns>
  49. [HttpGet]
  50. //[TokenAuthentication]
  51. [Route("mobile/ping")]
  52. public IHttpActionResult Ping()
  53. {
  54. // var case1 = ms.ValidateMobile("8112345678901");
  55. LogicalThreadContext.Properties["processId"] = "1";
  56. Log.Debug("Test");
  57. var jso = new JsonRxResponse() { ErrorCode = "0", Msg = "thisCalled" };
  58. return Ok(jso);
  59. }
  60. [HttpPost]
  61. [TokenAuthentication]
  62. [Route("mobile/GetNotifyInfo")]
  63. public IHttpActionResult GetNotifyInfo(NotifiCationInfo info)
  64. {
  65. if (string.IsNullOrEmpty(info.customerId))
  66. {
  67. return Ok("Error");
  68. }
  69. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  70. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetNotifyInfo";
  71. Log.Debug("VerifyIdNumber | REQUEST : " + JsonConvert.SerializeObject(info));
  72. var res = _requestServices.GetNotifyInfo(info);
  73. return Ok(res);
  74. }
  75. [HttpPost]
  76. [TokenAuthentication]
  77. [Route("mobile/GetNotifyDetailInfo")]
  78. public IHttpActionResult GetNotifyDetailInfo(NotifiCationDetailInfo info)
  79. {
  80. if (string.IsNullOrEmpty(info.rowId))
  81. return Ok("Error");
  82. var res = _requestServices.GetNotifyDetailInfo(info);
  83. return Ok(res);
  84. }
  85. /// <summary>
  86. /// Display an countries services details including currency and service available
  87. /// </summary>
  88. /// <returns></returns>
  89. [HttpGet]
  90. [ApplicationLevelAuthentication]
  91. [Route("mobile/countriesServices")]
  92. public IHttpActionResult GetCountriesServices()
  93. {
  94. var lang = "en";
  95. try
  96. {
  97. IEnumerable<string> langs = null;
  98. Request.Headers.TryGetValues("lang", out langs);
  99. lang = langs.ElementAt(0);
  100. }
  101. catch
  102. {
  103. }
  104. CallContext.SetData("language", lang);
  105. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  106. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetCountriesServices";
  107. Log.Debug("GetCountriesServices | REQUEST : NO REQUEST DATA.");
  108. var exRateResponse = _requestServices.GetCountriesServices();
  109. return Ok(exRateResponse);
  110. }
  111. /// <summary>
  112. /// </summary>
  113. /// <param name="param"></param>
  114. /// <returns></returns>
  115. [HttpGet]
  116. [TokenAuthentication]
  117. [Route("mobile/sendmoney/getcddi/{userId}")]
  118. public IHttpActionResult GetCDDI(string userId)
  119. {
  120. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  121. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId;
  122. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetCDDI";
  123. LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress();
  124. Log.Debug("GetCDDI | REQUEST : " + userId);
  125. var payStatusResponse = _requestServices.GetCDDI(userId);
  126. return Ok(payStatusResponse);
  127. }
  128. /// <summary>
  129. /// </summary>
  130. /// <param name="type"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. [ApplicationLevelAuthentication]
  134. [Route("mobile/requestOTP")]
  135. public IHttpActionResult RequestOTP(RequestOTPModel requestOTPModel)
  136. {
  137. var ProcessId = Guid.NewGuid().ToString();
  138. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = ProcessId;
  139. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "RequestOTP";
  140. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = requestOTPModel.userId;
  141. LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress();
  142. requestOTPModel.DeviceType = Util.GetDeviceType(Request);
  143. requestOTPModel.ProcessId = ProcessId;
  144. Log.Debug("RequestOTP | REQUEST : " + JsonConvert.SerializeObject(requestOTPModel));
  145. JsonRxResponse staticDataResponse = new JsonRxResponse();
  146. //if (string.IsNullOrEmpty(requestOTPModel.userId))
  147. //{
  148. // staticDataResponse.SetResponse("100", "Email is required!");
  149. // return Ok(staticDataResponse);
  150. //}
  151. staticDataResponse = _requestServices.RequestOTP(requestOTPModel);
  152. return Ok(staticDataResponse);
  153. }
  154. /// <summary>
  155. /// </summary>
  156. /// <param name="type"></param>
  157. /// <returns></returns>
  158. [HttpPost]
  159. [ApplicationLevelAuthentication]
  160. [Route("mobile/verifyIdNumber")]
  161. public IHttpActionResult VerifyIdNumber(IDValidateModel iDValidate)
  162. {
  163. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  164. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "VerifyIdNumber";
  165. Log.Debug("VerifyIdNumber | REQUEST : " + JsonConvert.SerializeObject(iDValidate));
  166. LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress();
  167. var staticDataResponse = _requestServices.VerifyIdNumber(iDValidate);
  168. return Ok(staticDataResponse);
  169. }
  170. /// <summary>
  171. /// </summary>
  172. /// <param name="type"></param>
  173. /// <returns></returns>
  174. [HttpPost]
  175. [ApplicationLevelAuthentication]
  176. [Route("mobile/submitOTP")]
  177. public IHttpActionResult SubmitOTP(RequestOTPModel requestOTPModel)
  178. {
  179. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  180. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "SubmitOTP";
  181. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = requestOTPModel.userId;
  182. Log.Debug("SubmitOTP | REQUEST : " + JsonConvert.SerializeObject(requestOTPModel));
  183. var staticDataResponse = _requestServices.SubmitOTP(requestOTPModel);
  184. return Ok(staticDataResponse);
  185. }
  186. /// <summary>
  187. /// </summary>
  188. /// <param name="model"></param>
  189. /// <returns></returns>
  190. [HttpPost]
  191. [ApplicationLevelAuthentication]
  192. [Route("mobile/calculateDefExRate")]
  193. public IHttpActionResult CalculateDefExRate(ExRateCalculateRequest model)
  194. {
  195. model.sCurrency = "GBP";
  196. var pId = Guid.NewGuid();
  197. model.processId = pId.ToString();
  198. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = pId;
  199. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = model.userId ?? model.pCurrency;
  200. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "CalculateDefExRate";
  201. LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress();
  202. model.DeviceType = Util.GetDeviceType(Request);
  203. Log.Debug("CalculateDefExRate | REQUEST : " + JsonConvert.SerializeObject(model));
  204. if (ModelState.IsValid)
  205. {
  206. var exRateResponse = _requestServices.CalculateExRate(model);
  207. return Ok(exRateResponse);
  208. }
  209. return ModelValidationError(ModelState);
  210. }
  211. /// <summary>
  212. /// </summary>
  213. /// <param name="type"></param>
  214. /// <returns></returns>
  215. [HttpGet]
  216. [ApplicationLevelAuthentication]
  217. [Route("mobile/loadForm/{type}")]
  218. public IHttpActionResult LoadFormStaticData(string type)
  219. {
  220. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  221. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "LoadFormStaticData";
  222. Log.Debug("LoadFormStaticData | REQUEST : " + type);
  223. var staticDataResponse = _requestServices.LoadFormStaticData(type);
  224. return Ok(staticDataResponse);
  225. }
  226. /// <summary>
  227. /// </summary>
  228. /// <param name="type"></param>
  229. /// <returns></returns>
  230. [HttpGet]
  231. [ApplicationLevelAuthentication]
  232. [Route("mobile/LoadKycStaticData/{type}")]
  233. public IHttpActionResult LoadKycStaticData(string type)
  234. {
  235. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  236. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "LoadKycStaticData";
  237. Log.Debug("LoadKycStaticData | REQUEST : " + type);
  238. var kycStaticDataResponse = _requestServices.LoadKycStaticData(type);
  239. return Ok(kycStaticDataResponse);
  240. }
  241. /// <summary>
  242. /// </summary>
  243. /// <param name="tranId"></param>
  244. /// <returns></returns>
  245. [HttpPost]
  246. [TokenAuthentication]
  247. [Route("mobile/receipt/{tranId=}/{notice=}")]
  248. public IHttpActionResult GenerateReceipt(string tranId, string notice)
  249. {
  250. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  251. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GenerateReceipt";
  252. Log.Debug("GenerateReceipt | REQUEST : " + tranId + " Notice : " + notice);
  253. var receiptResponse = _requestServices.GenerateReceipt(tranId, notice);
  254. return Ok(receiptResponse);
  255. }
  256. /// <summary>
  257. /// </summary>
  258. /// <param name="customerId"></param>
  259. /// <returns></returns>
  260. [HttpGet]
  261. [TokenAuthentication]
  262. [Route("mobile/GetNotificationList")]
  263. public IHttpActionResult GetNotificationList(string customerId)
  264. {
  265. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  266. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetNotificationList";
  267. Log.Debug("GetNotificationList | REQUEST : " + customerId);
  268. var notificationResponse = _requestServices.GetNotificationList(customerId);
  269. return Ok(notificationResponse);
  270. }
  271. /// <summary>
  272. /// </summary>
  273. /// <param name="rowId"></param>
  274. /// <returns></returns>
  275. [HttpPost]
  276. [TokenAuthentication]
  277. [Route("mobile/UpdateNotification")]
  278. public IHttpActionResult UpdateNotification(string rowId)
  279. {
  280. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  281. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "UpdateNotification";
  282. Log.Debug("UpdateNotification | REQUEST : " + rowId);
  283. var notificationResponse = _requestServices.UpdateNotification(rowId);
  284. return Ok(notificationResponse);
  285. }
  286. [HttpPost]
  287. [TokenAuthentication]
  288. [Route("mobile/tranhistory/{userId}")]
  289. public IHttpActionResult GetTransactionHistory(DateFilterParams search, string userId)
  290. {
  291. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  292. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId;
  293. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetTransactionHistory";
  294. Log.Debug("GetTransactionHistory | REQUEST : " + userId);
  295. var tranHistoryResponse = _requestServices.GetTransactionHistory(search, userId);
  296. return Ok(tranHistoryResponse);
  297. }
  298. /// <summary>
  299. /// </summary>
  300. /// <param name="search"></param>
  301. /// <param name="userId"></param>
  302. /// <returns></returns>
  303. [HttpPost]
  304. [TokenAuthentication]
  305. [Route("mobile/walletstatement/{userId}")]
  306. public IHttpActionResult GetWalletStatement(DateFilterParams search, string userId)
  307. {
  308. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  309. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId;
  310. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "walletstatement";
  311. Log.Debug("GetWalletStatement | REQUEST : " + userId + "|" + JsonConvert.SerializeObject(search));
  312. JsonRxResponse walletStatement = new JsonRxResponse();
  313. if (string.IsNullOrEmpty(userId))
  314. {
  315. walletStatement.ErrorCode = "1";
  316. walletStatement.Msg = "UserId is Missing";
  317. return Ok(walletStatement);
  318. }
  319. walletStatement = _requestServices.GetWalletStatement(search, userId);
  320. return Ok(walletStatement);
  321. }
  322. /// <summary>
  323. /// </summary>
  324. /// <param name="search"></param>
  325. /// <param name="userId"></param>
  326. /// <returns></returns>
  327. [HttpGet]
  328. [Route("mobile/key")]
  329. public string GetKey()
  330. {
  331. //LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  332. //LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetKey";
  333. //Log.Debug("user trying to generate key");
  334. //return "sroj";
  335. string rv = "false";
  336. var regData = new ValidationModel { Dob = "", Email = "", Password = "0f984f876cd0381b8f3245aed644534e3ba056c46c7a13f1508f6176f5cb6958c11dccfb186ae641ddf4b97490c3f5de" };
  337. List<PasswordRule> rules = new List<PasswordRule>();
  338. rules.Add(new AtLeastOneLowerCaseRule());
  339. rules.Add(new AtLeastOneNumberRule());
  340. rules.Add(new AtLeastOneUpperCaseRule());
  341. rules.Add(new AtLeastSpecialCharRule());
  342. rules.Add(new DboValidationRule());
  343. rules.Add(new PasswordAsEmailRule());
  344. rules.Add(new PatternMatchRule());
  345. foreach (PasswordRule rule in rules)
  346. {
  347. var isvalid = rule.Validate(regData);
  348. if (!isvalid.IsValid.Equals(true))
  349. {
  350. rv = "true";
  351. }
  352. }
  353. return rv;
  354. }
  355. /// <summary>
  356. /// </summary>
  357. /// <param name="modelState"></param>
  358. /// <returns></returns>
  359. protected IHttpActionResult ModelValidationError(ModelStateDictionary modelState)
  360. {
  361. var modelErrors = modelState.Select(x => x.Value.Errors)
  362. .Where(y => y.Count > 0)
  363. .First()[0].ErrorMessage;
  364. JsonRxResponse jsonRx = new JsonRxResponse()
  365. {
  366. ErrorCode = "1",
  367. Msg = string.IsNullOrEmpty(modelErrors) ? "It seems like incorrect Json input(s)." : modelErrors,
  368. Data = ""
  369. };
  370. return Ok(jsonRx);
  371. }
  372. /* 2019.09 @Dana */
  373. /// <summary>
  374. /// </summary>
  375. /// <param name="search"></param>
  376. /// <param name="userId"></param>
  377. /// <returns></returns>
  378. [HttpPost]
  379. [TokenAuthentication]
  380. [Route("mobile/DomestricTranhistory/{userId}")]
  381. public IHttpActionResult GetDomesticTransactionHistory(DateFilterParams search, string userId)
  382. {
  383. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  384. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId;
  385. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetDomesticTransactionHistory";
  386. Log.Debug("GetDomesticTransactionHistory | REQUEST : " + userId);
  387. var tranHistoryResponse = _requestServices.GetDomesticTransactionHistory(search, userId);
  388. return Ok(tranHistoryResponse);
  389. }
  390. /// <summary>
  391. /// </summary>
  392. /// <param name="tranId"></param>
  393. /// <returns></returns>
  394. [HttpPost]
  395. [TokenAuthentication]
  396. [Route("mobile/DomesticReceipt/{tranId}")]
  397. public IHttpActionResult GenerateDomesticReceipt(string tranId)
  398. {
  399. LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid();
  400. LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GenerateDomesticReceipt";
  401. Log.Debug("GenerateDomesticReceipt | REQUEST : " + tranId);
  402. var receiptResponse = _requestServices.GenerateDomesticReceipt(tranId);
  403. return Ok(receiptResponse);
  404. }
  405. }
  406. }