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.

334 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 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 = "one.jpg",
  62. // filePath = "https://mobile.imelondon.co.uk:2086/images/banners/1.png",
  63. // fileTitle = "file1",
  64. // Redirect = true,
  65. // RedirectURL = "https://imelondon.co.uk/"
  66. //});
  67. dashBoardV2.bannerImages.Add(new BannerImages()
  68. {
  69. fileName = "two.jpg",
  70. filePath = "https://mobile.imelondon.co.uk:2086/images/banners/2.png",
  71. fileTitle = "file1",
  72. Redirect = false
  73. });
  74. dashBoardV2.bannerImages.Add(new BannerImages()
  75. {
  76. fileName = "four.jpg",
  77. filePath = "https://mobile.imelondon.co.uk:2086/images/banners/4.png",
  78. fileTitle = "file1",
  79. Redirect = false
  80. });
  81. dashBoardV2.bannerImages.Add(new BannerImages()
  82. {
  83. fileName = "five.jpg",
  84. filePath = "https://mobile.imelondon.co.uk:2086/images/banners/5.png",
  85. fileTitle = "file1",
  86. Redirect = false
  87. });
  88. jsonResult.ErrorCode = "0";
  89. jsonResult.Msg = "Success";
  90. jsonResult.Data = dashBoardV2;
  91. }
  92. else
  93. {
  94. Log.Debug("GetReceiverInformation | RESPONSE: " + JsonConvert.SerializeObject(jsonResult));
  95. }
  96. return jsonResult;
  97. }
  98. public CustomerDetailV2 GetCustomerProfile(string userId)
  99. {
  100. CustomerDetailV2 v2 = new CustomerDetailV2();
  101. try
  102. {
  103. DataRow p = _requestServicesv2.GetProfileDetails(userId);
  104. v2.FullName = p["FullName"].ToString();
  105. v2.UserId = p["UserId"].ToString();
  106. v2.Username = p["email"].ToString();
  107. v2.PostalCode = p["zipCode"].ToString();
  108. v2.Gender = p["gender"].ToString();
  109. v2.DOB = p["dob"].ToString();
  110. v2.MobileNumber = p["mobile"].ToString();
  111. v2.Nationality = p["nativeCountry"].ToString();
  112. v2.City = p["city"].ToString();
  113. v2.Address1 = p["address"].ToString();
  114. v2.Address2 = p["ADDITIONALADDRESS"].ToString();
  115. }
  116. catch (Exception ex)
  117. {
  118. throw;
  119. }
  120. return v2;
  121. }
  122. public JsonRxResponse CustomerProfile(CustomerProfileV2 profileV2)
  123. {
  124. JsonRxResponse jsonRx = new JsonRxResponse();
  125. try
  126. {
  127. var httpRequest = HttpContext.Current.Request;
  128. var extension = "";
  129. var slipUrl = httpRequest.Files["CustomerProfile"];
  130. var fullPath = "";
  131. DataRow membership = _requestServicesv2.GetMembershipId(profileV2.UserId);
  132. string profileURL = "";
  133. string membershipId = membership["membershipId"].ToString();
  134. string rDate = membership["createdDate"].ToString();
  135. if (!IsValidImageASlipIdRequest(ref profileV2, slipUrl, rDate, membershipId))
  136. {
  137. Log.Debug("CustomerProfile.IsValidImageASlipIdRequest | Validate Image : Failed");
  138. jsonRx.SetResponse("1", "Invalid image file.");
  139. }
  140. if (membershipId != null)
  141. {
  142. extension = Path.GetExtension(slipUrl.FileName);
  143. profileURL = SaveCustomerProfile(slipUrl, profileV2.UserId, extension, membershipId, "profile", "");
  144. var a = profileURL.Split('/');
  145. var fileName = a[1];
  146. if (profileURL != null)
  147. {
  148. fullPath = $"{ HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/')}/images/profile/{profileURL.Replace("//", "\\")}";
  149. var jsonResult = _requestServicesv2.SaveProfile(profileV2.Username, fullPath, fileName, slipUrl.ContentType);
  150. if (jsonResult.ErrorCode.ToString() != "0")
  151. {
  152. Log.Debug("CustomerProfile.SaveProfile | Profile Upload : Failed");
  153. jsonRx.SetResponse("1", jsonResult.Msg.ToString());
  154. }
  155. }
  156. }
  157. JsonRxResponse rep = new JsonRxResponse() { ErrorCode = "0", Msg = "Customer profile updated successfully.", Extra = fullPath };
  158. Log.Debug("CustomerProfile | DB RESPONSE | " + JsonConvert.SerializeObject(rep));
  159. return rep;
  160. }
  161. catch (Exception ex)
  162. {
  163. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  164. jsonRx.SetResponse("1", "Couldnot upload customer profile!");
  165. return jsonRx;
  166. }
  167. }
  168. public JsonRxResponse GetKycSettings(KycRequest kycRequest)
  169. {
  170. JsonRxResponse jsonRx = new JsonRxResponse();
  171. try
  172. {
  173. var response = Utilities.GetKYCSettings(kycRequest);
  174. if (response != null)
  175. {
  176. jsonRx.SetResponse("0", "Success");
  177. jsonRx.Data = response;
  178. Log.Debug("GetKycSettings | RESPONSE : " + JsonConvert.SerializeObject(jsonRx));
  179. return jsonRx;
  180. }
  181. return jsonRx;
  182. }
  183. catch (Exception ex)
  184. {
  185. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  186. jsonRx.SetResponse("1", "Couldnot get GetKycSettings!");
  187. return jsonRx;
  188. }
  189. }
  190. public JsonRxResponse SaveKycSettings(KycOption kycRequest)
  191. {
  192. JsonRxResponse jsonRx = new JsonRxResponse();
  193. try
  194. {
  195. var response = _requestServicesv2.SaveKycSettings(kycRequest);
  196. return response;
  197. }
  198. catch (Exception ex)
  199. {
  200. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  201. jsonRx.SetResponse("1", "Couldnot save SaveKycSettings!");
  202. return jsonRx;
  203. }
  204. }
  205. private bool IsValidImageASlipIdRequest(ref CustomerProfileV2 profileV2, HttpPostedFile slipUrl, string rDate, string membershipId)
  206. {
  207. bool isValidated = true;
  208. string fileName = "";
  209. var extension = "";
  210. if (slipUrl != null)
  211. {
  212. extension = Path.GetExtension(slipUrl.FileName);
  213. if (!(extension == ".jpg" || extension == ".jpeg" || extension == ".png") && slipUrl.ContentLength > Convert.ToInt32(ApplicationConfig.GetMaximumFileSize()))
  214. {
  215. isValidated = false;
  216. }
  217. else
  218. {
  219. fileName = SaveIdFileToPath(slipUrl, profileV2.UserId, rDate, membershipId, extension, "profile", "deposit");
  220. profileV2.fileName = fileName;
  221. }
  222. }
  223. if (!isValidated)
  224. {
  225. return isValidated;
  226. }
  227. return isValidated;
  228. }
  229. private static string SaveIdFileToPath(HttpPostedFile file, string user, string rDate, string membershipId, string extension, string img, string type = null)
  230. {
  231. string fileName = "";
  232. string docUploadPath = ApplicationConfig.GetDocumentUploadPath();
  233. // Get the file size
  234. int fileSize = file.ContentLength;
  235. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  236. string registrationDate = Convert.ToString(rDate);
  237. // docUploadPath = docUploadPath + "/CustomerDocument/Profile/";
  238. docUploadPath = docUploadPath + "CustomerDocument\\" + registrationDate.Replace("-", "\\") + "\\" + membershipId;
  239. Log.Debug("Preparing file to save in dir " + docUploadPath);
  240. if (!Directory.Exists(docUploadPath))
  241. Directory.CreateDirectory(docUploadPath);
  242. string fileToSave = Path.Combine(docUploadPath, fileName);
  243. Log.Debug("Saving file as " + fileToSave);
  244. file.SaveAs(fileToSave);
  245. Log.Debug("Done with Saving ");
  246. return fileName;
  247. }
  248. private static string SaveCustomerProfile(HttpPostedFile file, string user, string extension, string membershipId, string img, string type = null)
  249. {
  250. string fileName = "";
  251. string profileUploadPath = ApplicationConfig.ReadWebConfig("profilePicUploadURL");
  252. int fileSize = file.ContentLength;
  253. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  254. profileUploadPath = profileUploadPath + membershipId;
  255. Log.Debug("Preparing file to save in dir " + profileUploadPath);
  256. if (!Directory.Exists(profileUploadPath))
  257. Directory.CreateDirectory(profileUploadPath);
  258. string fileToSave = Path.Combine(profileUploadPath, fileName);
  259. Log.Debug("Saving file as " + fileToSave);
  260. file.SaveAs(fileToSave);
  261. Log.Debug("Done with Saving ");
  262. return $"{membershipId}/{fileName}";
  263. }
  264. public JsonRxResponse DownLoadStatement(DateFilterParams search, string userId)
  265. {
  266. JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "0", Msg = "Success" };
  267. jsonRx.Data = "http://77.68.15.91:1082/download/sample.pdf";
  268. return jsonRx;
  269. }
  270. public JsonRxResponse UpdateCustomerProfile(CustomerDetailV2 profileV2)
  271. {
  272. JsonRxResponse jsonRx = _requestServicesv2.UpdateCustomerProfile(profileV2);
  273. return jsonRx;
  274. }
  275. }
  276. }