using Business.MobileV2; using Common; using Common.Helper; using Common.KFTC; using Common.Model; using Common.Model.MobileV2; using log4net; using Newtonsoft.Json; using Repository; using Repository.Mobile; using Repository.MobileV2; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; namespace Business.Mobile { public class MobileV2Business : IMobileV2Business { private readonly IMobileV2Repo _requestServicesv2; private readonly IMobileServicesRepo _requestServices; private readonly Dao _dao = new Dao(); private static readonly ILog Log = LogManager.GetLogger(typeof(MobileV2Business)); public MobileV2Business(IMobileV2Repo requestServicesv2, IMobileServicesRepo requestServices) { _requestServicesv2 = requestServicesv2; ; _requestServices = requestServices; } public JsonRxResponse GetReceiverInformationV2(DateFilterParams search, string customerId, string countryId) { var jsonResult = _requestServicesv2.GetReceiverInformationV2(search, customerId, countryId); if (jsonResult.ErrorCode == "0") { Log.Debug("receiver ReceiverField success."); var reciver = jsonResult.Data; List lsAccount = null;//GetCustomerPaymentMethods(customerId); jsonResult.Data = new { Receivers = reciver, accounts = lsAccount }; } else { Log.Debug("GetReceiverInformation | RESPONSE: " + JsonConvert.SerializeObject(jsonResult)); } return jsonResult; } public JsonRxResponse RefreshDashboardInformationV2(UserModel model) { JsonRxResponse jsonResult = new JsonRxResponse(); DashBoardV2 dashBoardV2 = new DashBoardV2(); var customer = _requestServices.RefreshCustomerInformation(model); if (customer.ErrorCode == "0") { Log.Debug("RefreshDashboardInformationV2 success."); dashBoardV2.loginResponse = (LoginResponse)customer.Data; dashBoardV2.bannerImages = new List(); dashBoardV2.bannerImages.Add(new BannerImages() { fileName = "image-1.jpg", filePath = "https://uat.imelondon.co.uk:1081/images/banners/Imebanner.jpg", fileTitle = "file1", Redirect = true, RedirectURL = "https://imelondon.co.uk/" }); dashBoardV2.bannerImages.Add(new BannerImages() { fileName = "lawson.jpg", filePath = "https://uat.imelondon.co.uk:1081/images/banners/demologoBanner.png", fileTitle = "file1", Redirect = false }); //dashBoardV2.bannerImages.Add(new BannerImages() //{ // fileName = "JME.png", // filePath = "https://staging.japanremit.com:1083/images/banners/jme.png", // fileTitle = "JME LOGO", // Redirect = true, // RedirectURL = "https://japanremit.com" //}); //dashBoardV2.bannerImages.Add(new BannerImages() //{ // fileName = "image-4.jpg", // filePath = "https://staging.japanremit.com:1083/images/banners/image-41.jpg", // fileTitle = "file4", // Redirect = false //}); jsonResult.ErrorCode = "0"; jsonResult.Msg = "Success"; jsonResult.Data = dashBoardV2; } else { Log.Debug("GetReceiverInformation | RESPONSE: " + JsonConvert.SerializeObject(jsonResult)); } return jsonResult; } public CustomerDetailV2 GetCustomerProfile(string userId) { CustomerDetailV2 v2 = new CustomerDetailV2(); try { DataRow p = _requestServicesv2.GetProfileDetails(userId); v2.FullName = p["FullName"].ToString(); v2.UserId = p["UserId"].ToString(); v2.Username = p["email"].ToString(); v2.PostalCode = p["zipCode"].ToString(); v2.Gender = p["gender"].ToString(); v2.DOB = p["dob"].ToString(); v2.MobileNumber = p["mobile"].ToString(); v2.Nationality = p["nativeCountry"].ToString(); v2.City = p["city"].ToString(); v2.Address1 = p["address"].ToString(); v2.Address2 = p["ADDITIONALADDRESS"].ToString(); } catch (Exception ex) { throw; } return v2; } public JsonRxResponse CustomerProfile(CustomerProfileV2 profileV2) { JsonRxResponse jsonRx = new JsonRxResponse(); try { var httpRequest = HttpContext.Current.Request; var extension = ""; var slipUrl = httpRequest.Files["CustomerProfile"]; var fullPath = ""; DataRow membership = _requestServicesv2.GetMembershipId(profileV2.UserId); string profileURL = ""; string membershipId = membership["membershipId"].ToString(); string rDate = membership["createdDate"].ToString(); if (!IsValidImageASlipIdRequest(ref profileV2, slipUrl, rDate, membershipId)) { Log.Debug("CustomerProfile.IsValidImageASlipIdRequest | Validate Image : Failed"); jsonRx.SetResponse("1", "Invalid image file."); } if (membershipId != null) { extension = Path.GetExtension(slipUrl.FileName); profileURL = SaveCustomerProfile(slipUrl, profileV2.UserId, extension, membershipId, "profile", ""); var a = profileURL.Split('/'); var fileName = a[1]; if (profileURL != null) { fullPath = $"{ HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/')}/images/profile/{profileURL.Replace("//", "\\")}"; var jsonResult = _requestServicesv2.SaveProfile(profileV2.Username, fullPath, fileName, slipUrl.ContentType); if (jsonResult.ErrorCode.ToString() != "0") { Log.Debug("CustomerProfile.SaveProfile | Profile Upload : Failed"); jsonRx.SetResponse("1", jsonResult.Msg.ToString()); } } } JsonRxResponse rep = new JsonRxResponse() { ErrorCode = "0", Msg = "Customer profile updated successfully.", Extra = fullPath }; Log.Debug("CustomerProfile | DB RESPONSE | " + JsonConvert.SerializeObject(rep)); return rep; } catch (Exception ex) { Log.Error("Something Went Wrong, Please Try Again!!", ex); jsonRx.SetResponse("1", "Couldnot upload customer profile!"); return jsonRx; } } public JsonRxResponse GetKycSettings(KycRequest kycRequest) { JsonRxResponse jsonRx = new JsonRxResponse(); try { var response = Utilities.GetKYCSettings(kycRequest); if (response != null) { jsonRx.SetResponse("0", "Success"); jsonRx.Data = response; Log.Debug("GetKycSettings | RESPONSE : " + JsonConvert.SerializeObject(jsonRx)); return jsonRx; } return jsonRx; } catch (Exception ex) { Log.Error("Something Went Wrong, Please Try Again!!", ex); jsonRx.SetResponse("1", "Couldnot get GetKycSettings!"); return jsonRx; } } public JsonRxResponse SaveKycSettings(KycOption kycRequest) { JsonRxResponse jsonRx = new JsonRxResponse(); try { var response = _requestServicesv2.SaveKycSettings(kycRequest); return response; } catch (Exception ex) { Log.Error("Something Went Wrong, Please Try Again!!", ex); jsonRx.SetResponse("1", "Couldnot save SaveKycSettings!"); return jsonRx; } } private bool IsValidImageASlipIdRequest(ref CustomerProfileV2 profileV2, HttpPostedFile slipUrl, string rDate, string membershipId) { bool isValidated = true; string fileName = ""; var extension = ""; if (slipUrl != null) { extension = Path.GetExtension(slipUrl.FileName); if (!(extension == ".jpg" || extension == ".jpeg" || extension == ".png") && slipUrl.ContentLength > Convert.ToInt32(ApplicationConfig.GetMaximumFileSize())) { isValidated = false; } else { fileName = SaveIdFileToPath(slipUrl, profileV2.UserId, rDate, membershipId, extension, "profile", "deposit"); profileV2.fileName = fileName; } } if (!isValidated) { return isValidated; } return isValidated; } private static string SaveIdFileToPath(HttpPostedFile file, string user, string rDate, string membershipId, string extension, string img, string type = null) { string fileName = ""; string docUploadPath = ApplicationConfig.GetDocumentUploadPath(); // Get the file size int fileSize = file.ContentLength; fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension; string registrationDate = Convert.ToString(rDate); // docUploadPath = docUploadPath + "/CustomerDocument/Profile/"; docUploadPath = docUploadPath + "CustomerDocument\\" + registrationDate.Replace("-", "\\") + "\\" + membershipId; Log.Debug("Preparing file to save in dir " + docUploadPath); if (!Directory.Exists(docUploadPath)) Directory.CreateDirectory(docUploadPath); string fileToSave = Path.Combine(docUploadPath, fileName); Log.Debug("Saving file as " + fileToSave); file.SaveAs(fileToSave); Log.Debug("Done with Saving "); return fileName; } private static string SaveCustomerProfile(HttpPostedFile file, string user, string extension, string membershipId, string img, string type = null) { string fileName = ""; string profileUploadPath = ApplicationConfig.ReadWebConfig("profilePicUploadURL"); int fileSize = file.ContentLength; fileName = "upload-" + img + "-" + user + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + extension; profileUploadPath = profileUploadPath + membershipId; Log.Debug("Preparing file to save in dir " + profileUploadPath); if (!Directory.Exists(profileUploadPath)) Directory.CreateDirectory(profileUploadPath); string fileToSave = Path.Combine(profileUploadPath, fileName); Log.Debug("Saving file as " + fileToSave); file.SaveAs(fileToSave); Log.Debug("Done with Saving "); return $"{membershipId}/{fileName}"; } public JsonRxResponse DownLoadStatement(DateFilterParams search, string userId) { JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "0", Msg = "Success" }; jsonRx.Data = "http://77.68.15.91:1082/download/sample.pdf"; return jsonRx; } public JsonRxResponse UpdateCustomerProfile(CustomerDetailV2 profileV2) { JsonRxResponse jsonRx = _requestServicesv2.UpdateCustomerProfile(profileV2); return jsonRx; } } }