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.

291 lines
11 KiB

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 JsonRxResponse CustomerProfile(CustomerProfileV2 profileV2)
  100. {
  101. JsonRxResponse jsonRx = new JsonRxResponse();
  102. try
  103. {
  104. var httpRequest = HttpContext.Current.Request;
  105. var extension = "";
  106. var slipUrl = httpRequest.Files["CustomerProfile"];
  107. var fullPath = "";
  108. DataRow membership = _requestServicesv2.GetMembershipId(profileV2.UserId);
  109. string profileURL = "";
  110. string membershipId = membership["membershipId"].ToString();
  111. string rDate = membership["createdDate"].ToString();
  112. if (!IsValidImageASlipIdRequest(ref profileV2, slipUrl, rDate, membershipId))
  113. {
  114. Log.Debug("CustomerProfile.IsValidImageASlipIdRequest | Validate Image : Failed");
  115. jsonRx.SetResponse("1", "Invalid image file.");
  116. }
  117. if (membershipId != null)
  118. {
  119. extension = Path.GetExtension(slipUrl.FileName);
  120. profileURL = SaveCustomerProfile(slipUrl, profileV2.UserId, extension, membershipId, "profile", "");
  121. var a = profileURL.Split('/');
  122. var fileName = a[1];
  123. if (profileURL != null)
  124. {
  125. fullPath = $"{ HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/')}/images/profile/{profileURL.Replace("//", "\\")}";
  126. var jsonResult = _requestServicesv2.SaveProfile(profileV2.Username, fullPath, fileName, slipUrl.ContentType);
  127. if (jsonResult.ErrorCode.ToString() != "0")
  128. {
  129. Log.Debug("CustomerProfile.SaveProfile | Profile Upload : Failed");
  130. jsonRx.SetResponse("1", jsonResult.Msg.ToString());
  131. }
  132. }
  133. }
  134. JsonRxResponse rep = new JsonRxResponse() { ErrorCode = "0", Msg = "Customer profile updated successfully.", Extra = fullPath };
  135. Log.Debug("CustomerProfile | DB RESPONSE | " + JsonConvert.SerializeObject(rep));
  136. return rep;
  137. }
  138. catch (Exception ex)
  139. {
  140. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  141. jsonRx.SetResponse("1", "Couldnot upload customer profile!");
  142. return jsonRx;
  143. }
  144. }
  145. public JsonRxResponse GetKycSettings(KycRequest kycRequest)
  146. {
  147. JsonRxResponse jsonRx = new JsonRxResponse();
  148. try
  149. {
  150. var response = Utilities.GetKYCSettings(kycRequest);
  151. if (response != null)
  152. {
  153. jsonRx.SetResponse("0", "Success");
  154. jsonRx.Data = response;
  155. Log.Debug("GetKycSettings | RESPONSE : " + JsonConvert.SerializeObject(jsonRx));
  156. return jsonRx;
  157. }
  158. return jsonRx;
  159. }
  160. catch (Exception ex)
  161. {
  162. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  163. jsonRx.SetResponse("1", "Couldnot get GetKycSettings!");
  164. return jsonRx;
  165. }
  166. }
  167. public JsonRxResponse SaveKycSettings(KycOption kycRequest)
  168. {
  169. JsonRxResponse jsonRx = new JsonRxResponse();
  170. try
  171. {
  172. var response = _requestServicesv2.SaveKycSettings(kycRequest);
  173. return response;
  174. }
  175. catch (Exception ex)
  176. {
  177. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  178. jsonRx.SetResponse("1", "Couldnot save SaveKycSettings!");
  179. return jsonRx;
  180. }
  181. }
  182. private bool IsValidImageASlipIdRequest(ref CustomerProfileV2 profileV2, HttpPostedFile slipUrl, string rDate, string membershipId)
  183. {
  184. bool isValidated = true;
  185. string fileName = "";
  186. var extension = "";
  187. if (slipUrl != null)
  188. {
  189. extension = Path.GetExtension(slipUrl.FileName);
  190. if (!(extension == ".jpg" || extension == ".jpeg" || extension == ".png") && slipUrl.ContentLength > Convert.ToInt32(ApplicationConfig.GetMaximumFileSize()))
  191. {
  192. isValidated = false;
  193. }
  194. else
  195. {
  196. fileName = SaveIdFileToPath(slipUrl, profileV2.UserId, rDate, membershipId, extension, "profile", "deposit");
  197. profileV2.fileName = fileName;
  198. }
  199. }
  200. if (!isValidated)
  201. {
  202. return isValidated;
  203. }
  204. return isValidated;
  205. }
  206. private static string SaveIdFileToPath(HttpPostedFile file, string user, string rDate, string membershipId, string extension, string img, string type = null)
  207. {
  208. string fileName = "";
  209. string docUploadPath = ApplicationConfig.GetDocumentUploadPath();
  210. // Get the file size
  211. int fileSize = file.ContentLength;
  212. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  213. string registrationDate = Convert.ToString(rDate);
  214. // docUploadPath = docUploadPath + "/CustomerDocument/Profile/";
  215. docUploadPath = docUploadPath + "CustomerDocument\\" + registrationDate.Replace("-", "\\") + "\\" + membershipId;
  216. Log.Debug("Preparing file to save in dir " + docUploadPath);
  217. if (!Directory.Exists(docUploadPath))
  218. Directory.CreateDirectory(docUploadPath);
  219. string fileToSave = Path.Combine(docUploadPath, fileName);
  220. Log.Debug("Saving file as " + fileToSave);
  221. file.SaveAs(fileToSave);
  222. Log.Debug("Done with Saving ");
  223. return fileName;
  224. }
  225. private static string SaveCustomerProfile(HttpPostedFile file, string user, string extension, string membershipId, string img, string type = null)
  226. {
  227. string fileName = "";
  228. string profileUploadPath = ApplicationConfig.ReadWebConfig("profilePicUploadURL");
  229. int fileSize = file.ContentLength;
  230. fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension;
  231. profileUploadPath = profileUploadPath + membershipId;
  232. Log.Debug("Preparing file to save in dir " + profileUploadPath);
  233. if (!Directory.Exists(profileUploadPath))
  234. Directory.CreateDirectory(profileUploadPath);
  235. string fileToSave = Path.Combine(profileUploadPath, fileName);
  236. Log.Debug("Saving file as " + fileToSave);
  237. file.SaveAs(fileToSave);
  238. Log.Debug("Done with Saving ");
  239. return $"{membershipId}/{fileName}";
  240. }
  241. }
  242. }