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.

336 lines
12 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using Business.MobileV2;
  2. using Common;
  3. using Common.Helper;
  4. using Common.KFTC;
  5. using Common.Model;
  6. using Common.Model.MobileV2;
  7. using log4net;
  8. using Newtonsoft.Json;
  9. using Repository;
  10. using Repository.Mobile;
  11. using Repository.MobileV2;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Web;
  20. namespace Business.Mobile
  21. {
  22. public class MobileV2Business : IMobileV2Business
  23. {
  24. private readonly IMobileV2Repo _requestServicesv2;
  25. private readonly IMobileServicesRepo _requestServices;
  26. private readonly Dao _dao = new Dao();
  27. private static readonly ILog Log = LogManager.GetLogger(typeof(MobileV2Business));
  28. public MobileV2Business(IMobileV2Repo requestServicesv2, IMobileServicesRepo requestServices)
  29. {
  30. _requestServicesv2 = requestServicesv2; ;
  31. _requestServices = requestServices;
  32. }
  33. public JsonRxResponse GetReceiverInformationV2(DateFilterParams search, string customerId, string countryId)
  34. {
  35. var jsonResult = _requestServicesv2.GetReceiverInformationV2(search, customerId, countryId);
  36. if (jsonResult.ErrorCode == "0")
  37. {
  38. Log.Debug("receiver ReceiverField success.");
  39. var reciver = jsonResult.Data;
  40. List<AccountDetails> lsAccount = null;//GetCustomerPaymentMethods(customerId);
  41. jsonResult.Data = new { Receivers = reciver, accounts = lsAccount };
  42. }
  43. else
  44. {
  45. Log.Debug("GetReceiverInformation | RESPONSE: " + JsonConvert.SerializeObject(jsonResult));
  46. }
  47. return jsonResult;
  48. }
  49. public JsonRxResponse RefreshDashboardInformationV2(UserModel model)
  50. {
  51. JsonRxResponse jsonResult = new JsonRxResponse();
  52. DashBoardV2 dashBoardV2 = new DashBoardV2();
  53. var customer = _requestServices.RefreshCustomerInformation(model);
  54. if (customer.ErrorCode == "0")
  55. {
  56. Log.Debug("RefreshDashboardInformationV2 success.");
  57. dashBoardV2.loginResponse = (LoginResponse)customer.Data;
  58. dashBoardV2.bannerImages = new List<BannerImages>();
  59. dashBoardV2.bannerImages.Add(new BannerImages()
  60. {
  61. fileName = "image-1.jpg",
  62. filePath = "https://uat.imelondon.co.uk:1081/images/banners/Imebanner.jpg",
  63. fileTitle = "file1",
  64. Redirect = true,
  65. RedirectURL = "https://imelondon.co.uk/"
  66. });
  67. dashBoardV2.bannerImages.Add(new BannerImages()
  68. {
  69. fileName = "lawson.jpg",
  70. filePath = "https://uat.imelondon.co.uk:1081/images/banners/demologoBanner.png",
  71. fileTitle = "file1",
  72. Redirect = false
  73. });
  74. //dashBoardV2.bannerImages.Add(new BannerImages()
  75. //{
  76. // fileName = "JME.png",
  77. // filePath = "https://staging.japanremit.com:1083/images/banners/jme.png",
  78. // fileTitle = "JME LOGO",
  79. // Redirect = true,
  80. // RedirectURL = "https://japanremit.com"
  81. //});
  82. //dashBoardV2.bannerImages.Add(new BannerImages()
  83. //{
  84. // fileName = "image-4.jpg",
  85. // filePath = "https://staging.japanremit.com:1083/images/banners/image-41.jpg",
  86. // fileTitle = "file4",
  87. // Redirect = false
  88. //});
  89. jsonResult.ErrorCode = "0";
  90. jsonResult.Msg = "Success";
  91. jsonResult.Data = dashBoardV2;
  92. }
  93. else
  94. {
  95. Log.Debug("GetReceiverInformation | RESPONSE: " + JsonConvert.SerializeObject(jsonResult));
  96. }
  97. return jsonResult;
  98. }
  99. public CustomerDetailV2 GetCustomerProfile(string userId)
  100. {
  101. CustomerDetailV2 v2 = new CustomerDetailV2();
  102. try
  103. {
  104. DataRow p = _requestServicesv2.GetProfileDetails(userId);
  105. v2.FullName = p["FullName"].ToString();
  106. v2.UserId = p["UserId"].ToString();
  107. v2.Username = p["email"].ToString();
  108. v2.PostalCode = p["zipCode"].ToString();
  109. v2.Gender = p["gender"].ToString();
  110. v2.DOB = p["dob"].ToString();
  111. v2.MobileNumber = p["mobile"].ToString();
  112. v2.Nationality = p["nativeCountry"].ToString();
  113. v2.City = p["city"].ToString();
  114. v2.Address1 = p["address"].ToString();
  115. v2.Address2 = p["ADDITIONALADDRESS"].ToString();
  116. }
  117. catch (Exception ex)
  118. {
  119. throw;
  120. }
  121. return v2;
  122. }
  123. public JsonRxResponse CustomerProfile(CustomerProfileV2 profileV2)
  124. {
  125. JsonRxResponse jsonRx = new JsonRxResponse();
  126. try
  127. {
  128. var httpRequest = HttpContext.Current.Request;
  129. var extension = "";
  130. var slipUrl = httpRequest.Files["CustomerProfile"];
  131. var fullPath = "";
  132. DataRow membership = _requestServicesv2.GetMembershipId(profileV2.UserId);
  133. string profileURL = "";
  134. string membershipId = membership["membershipId"].ToString();
  135. string rDate = membership["createdDate"].ToString();
  136. if (!IsValidImageASlipIdRequest(ref profileV2, slipUrl, rDate, membershipId))
  137. {
  138. Log.Debug("CustomerProfile.IsValidImageASlipIdRequest | Validate Image : Failed");
  139. jsonRx.SetResponse("1", "Invalid image file.");
  140. }
  141. if (membershipId != null)
  142. {
  143. extension = Path.GetExtension(slipUrl.FileName);
  144. profileURL = SaveCustomerProfile(slipUrl, profileV2.UserId, extension, membershipId, "profile", "");
  145. var a = profileURL.Split('/');
  146. var fileName = a[1];
  147. if (profileURL != null)
  148. {
  149. fullPath = $"{ HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/')}/images/profile/{profileURL.Replace("//", "\\")}";
  150. var jsonResult = _requestServicesv2.SaveProfile(profileV2.Username, fullPath, fileName, slipUrl.ContentType);
  151. if (jsonResult.ErrorCode.ToString() != "0")
  152. {
  153. Log.Debug("CustomerProfile.SaveProfile | Profile Upload : Failed");
  154. jsonRx.SetResponse("1", jsonResult.Msg.ToString());
  155. }
  156. }
  157. }
  158. JsonRxResponse rep = new JsonRxResponse() { ErrorCode = "0", Msg = "Customer profile updated successfully.", Extra = fullPath };
  159. Log.Debug("CustomerProfile | DB RESPONSE | " + JsonConvert.SerializeObject(rep));
  160. return rep;
  161. }
  162. catch (Exception ex)
  163. {
  164. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  165. jsonRx.SetResponse("1", "Couldnot upload customer profile!");
  166. return jsonRx;
  167. }
  168. }
  169. public JsonRxResponse GetKycSettings(KycRequest kycRequest)
  170. {
  171. JsonRxResponse jsonRx = new JsonRxResponse();
  172. try
  173. {
  174. var response = Utilities.GetKYCSettings(kycRequest);
  175. if (response != null)
  176. {
  177. jsonRx.SetResponse("0", "Success");
  178. jsonRx.Data = response;
  179. Log.Debug("GetKycSettings | RESPONSE : " + JsonConvert.SerializeObject(jsonRx));
  180. return jsonRx;
  181. }
  182. return jsonRx;
  183. }
  184. catch (Exception ex)
  185. {
  186. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  187. jsonRx.SetResponse("1", "Couldnot get GetKycSettings!");
  188. return jsonRx;
  189. }
  190. }
  191. public JsonRxResponse SaveKycSettings(KycOption kycRequest)
  192. {
  193. JsonRxResponse jsonRx = new JsonRxResponse();
  194. try
  195. {
  196. var response = _requestServicesv2.SaveKycSettings(kycRequest);
  197. return response;
  198. }
  199. catch (Exception ex)
  200. {
  201. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  202. jsonRx.SetResponse("1", "Couldnot save SaveKycSettings!");
  203. return jsonRx;
  204. }
  205. }
  206. private bool IsValidImageASlipIdRequest(ref CustomerProfileV2 profileV2, HttpPostedFile slipUrl, string rDate, string membershipId)
  207. {
  208. bool isValidated = true;
  209. string fileName = "";
  210. var extension = "";
  211. if (slipUrl != null)
  212. {
  213. extension = Path.GetExtension(slipUrl.FileName);
  214. if (!(extension == ".jpg" || extension == ".jpeg" || extension == ".png") && slipUrl.ContentLength > Convert.ToInt32(ApplicationConfig.GetMaximumFileSize()))
  215. {
  216. isValidated = false;
  217. }
  218. else
  219. {
  220. fileName = SaveIdFileToPath(slipUrl, profileV2.UserId, rDate, membershipId, extension, "profile", "deposit");
  221. profileV2.fileName = fileName;
  222. }
  223. }
  224. if (!isValidated)
  225. {
  226. return isValidated;
  227. }
  228. return isValidated;
  229. }
  230. private static string SaveIdFileToPath(HttpPostedFile file, string user, string rDate, string membershipId, string extension, string img, string type = null)
  231. {
  232. string fileName = "";
  233. string docUploadPath = ApplicationConfig.GetDocumentUploadPath();
  234. // Get the file size
  235. int fileSize = file.ContentLength;
  236. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  237. string registrationDate = Convert.ToString(rDate);
  238. // docUploadPath = docUploadPath + "/CustomerDocument/Profile/";
  239. docUploadPath = docUploadPath + "CustomerDocument\\" + registrationDate.Replace("-", "\\") + "\\" + membershipId;
  240. Log.Debug("Preparing file to save in dir " + docUploadPath);
  241. if (!Directory.Exists(docUploadPath))
  242. Directory.CreateDirectory(docUploadPath);
  243. string fileToSave = Path.Combine(docUploadPath, fileName);
  244. Log.Debug("Saving file as " + fileToSave);
  245. file.SaveAs(fileToSave);
  246. Log.Debug("Done with Saving ");
  247. return fileName;
  248. }
  249. private static string SaveCustomerProfile(HttpPostedFile file, string user, string extension, string membershipId, string img, string type = null)
  250. {
  251. string fileName = "";
  252. string profileUploadPath = ApplicationConfig.ReadWebConfig("profilePicUploadURL");
  253. int fileSize = file.ContentLength;
  254. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  255. profileUploadPath = profileUploadPath + membershipId;
  256. Log.Debug("Preparing file to save in dir " + profileUploadPath);
  257. if (!Directory.Exists(profileUploadPath))
  258. Directory.CreateDirectory(profileUploadPath);
  259. string fileToSave = Path.Combine(profileUploadPath, fileName);
  260. Log.Debug("Saving file as " + fileToSave);
  261. file.SaveAs(fileToSave);
  262. Log.Debug("Done with Saving ");
  263. return $"{membershipId}/{fileName}";
  264. }
  265. public JsonRxResponse DownLoadStatement(DateFilterParams search, string userId)
  266. {
  267. JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "0", Msg = "Success" };
  268. jsonRx.Data = "http://77.68.15.91:1082/download/sample.pdf";
  269. return jsonRx;
  270. }
  271. public JsonRxResponse UpdateCustomerProfile(CustomerDetailV2 profileV2)
  272. {
  273. JsonRxResponse jsonRx = _requestServicesv2.UpdateCustomerProfile(profileV2);
  274. return jsonRx;
  275. }
  276. }
  277. }