using Business.Authentication; using Business.KftcPasswordRule; using Business.Mobile; using Common; using Common.Helper; using Common.Language; using Common.Model; using Common.Model.Config; using Common.Model.RequestOTP; using JsonRx.AuthFilter; using JsonRx.Helper; using log4net; using Newtonsoft.Json; using PushNotification; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting.Messaging; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.ModelBinding; using System.Web.Routing; namespace JsonRx.Api { /// /// [RoutePrefix("api/v1")] //[EnableCors("*", "*", "*")] public class MobileController : ApiController { private readonly IMobileServices _requestServices; private readonly IAuthenticationBusiness _authenticationBusiness; private static readonly ILog Log = LogManager.GetLogger(typeof(MobileController)); /// /// public MobileController() { } /// /// /// /// public MobileController(IMobileServices requestServices, IAuthenticationBusiness authenticationBusiness) { _requestServices = requestServices; _authenticationBusiness = authenticationBusiness; } /// /// /// [HttpGet] //[TokenAuthentication] [Route("mobile/ping")] public IHttpActionResult Ping() { // var case1 = ms.ValidateMobile("8112345678901"); LogicalThreadContext.Properties["processId"] = "1"; Log.Debug("Test"); var jso = new JsonRxResponse() { ErrorCode = "0", Msg = "thisCalled" }; return Ok(jso); } [HttpPost] [TokenAuthentication] [Route("mobile/GetNotifyInfo")] public IHttpActionResult GetNotifyInfo(NotifiCationInfo info) { if (string.IsNullOrEmpty(info.customerId)) { return Ok("Error"); } LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetNotifyInfo"; Log.Debug("VerifyIdNumber | REQUEST : " + JsonConvert.SerializeObject(info)); var res = _requestServices.GetNotifyInfo(info); return Ok(res); } [HttpPost] [TokenAuthentication] [Route("mobile/GetNotifyDetailInfo")] public IHttpActionResult GetNotifyDetailInfo(NotifiCationDetailInfo info) { if (string.IsNullOrEmpty(info.rowId)) return Ok("Error"); var res = _requestServices.GetNotifyDetailInfo(info); return Ok(res); } /// /// Display an countries services details including currency and service available /// /// [HttpGet] [ApplicationLevelAuthentication] [Route("mobile/countriesServices")] public IHttpActionResult GetCountriesServices() { var lang = "en"; try { IEnumerable langs = null; Request.Headers.TryGetValues("lang", out langs); lang = langs.ElementAt(0); } catch { } CallContext.SetData("language", lang); LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetCountriesServices"; Log.Debug("GetCountriesServices | REQUEST : NO REQUEST DATA."); var exRateResponse = _requestServices.GetCountriesServices(); return Ok(exRateResponse); } /// /// /// /// [HttpGet] [TokenAuthentication] [Route("mobile/sendmoney/getcddi/{userId}")] public IHttpActionResult GetCDDI(string userId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetCDDI"; LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress(); Log.Debug("GetCDDI | REQUEST : " + userId); var payStatusResponse = _requestServices.GetCDDI(userId); return Ok(payStatusResponse); } /// /// /// /// [HttpPost] [ApplicationLevelAuthentication] [Route("mobile/requestOTP")] public IHttpActionResult RequestOTP(RequestOTPModel requestOTPModel) { var ProcessId = Guid.NewGuid().ToString(); LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = ProcessId; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "RequestOTP"; LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = requestOTPModel.userId; LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress(); requestOTPModel.DeviceType = Util.GetDeviceType(Request); requestOTPModel.ProcessId = ProcessId; Log.Debug("RequestOTP | REQUEST : " + JsonConvert.SerializeObject(requestOTPModel)); JsonRxResponse staticDataResponse = new JsonRxResponse(); //if (string.IsNullOrEmpty(requestOTPModel.userId)) //{ // staticDataResponse.SetResponse("100", "Email is required!"); // return Ok(staticDataResponse); //} staticDataResponse = _requestServices.RequestOTP(requestOTPModel); return Ok(staticDataResponse); } /// /// /// /// [HttpPost] [ApplicationLevelAuthentication] [Route("mobile/verifyIdNumber")] public IHttpActionResult VerifyIdNumber(IDValidateModel iDValidate) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "VerifyIdNumber"; Log.Debug("VerifyIdNumber | REQUEST : " + JsonConvert.SerializeObject(iDValidate)); LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress(); var staticDataResponse = _requestServices.VerifyIdNumber(iDValidate); return Ok(staticDataResponse); } /// /// /// /// [HttpPost] [ApplicationLevelAuthentication] [Route("mobile/submitOTP")] public IHttpActionResult SubmitOTP(RequestOTPModel requestOTPModel) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "SubmitOTP"; LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = requestOTPModel.userId; Log.Debug("SubmitOTP | REQUEST : " + JsonConvert.SerializeObject(requestOTPModel)); var staticDataResponse = _requestServices.SubmitOTP(requestOTPModel); return Ok(staticDataResponse); } /// /// /// /// [HttpPost] [ApplicationLevelAuthentication] [Route("mobile/calculateDefExRate")] public IHttpActionResult CalculateDefExRate(ExRateCalculateRequest model) { model.sCurrency = "GBP"; var pId = Guid.NewGuid(); model.processId = pId.ToString(); LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = pId; LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = model.userId ?? model.pCurrency; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "CalculateDefExRate"; LogicalThreadContext.Properties[LoggerProperty.IPADDRESS] = Request.GetClientIpAddress(); model.DeviceType = Util.GetDeviceType(Request); Log.Debug("CalculateDefExRate | REQUEST : " + JsonConvert.SerializeObject(model)); if (ModelState.IsValid) { var exRateResponse = _requestServices.CalculateExRate(model); return Ok(exRateResponse); } return ModelValidationError(ModelState); } /// /// /// /// [HttpGet] [ApplicationLevelAuthentication] [Route("mobile/loadForm/{type}")] public IHttpActionResult LoadFormStaticData(string type) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "LoadFormStaticData"; Log.Debug("LoadFormStaticData | REQUEST : " + type); var staticDataResponse = _requestServices.LoadFormStaticData(type); return Ok(staticDataResponse); } /// /// /// /// [HttpGet] [ApplicationLevelAuthentication] [Route("mobile/LoadKycStaticData/{type}")] public IHttpActionResult LoadKycStaticData(string type) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "LoadKycStaticData"; Log.Debug("LoadKycStaticData | REQUEST : " + type); var kycStaticDataResponse = _requestServices.LoadKycStaticData(type); return Ok(kycStaticDataResponse); } /// /// /// /// [HttpPost] [TokenAuthentication] [Route("mobile/receipt/{tranId=}/{notice=}")] public IHttpActionResult GenerateReceipt(string tranId, string notice) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GenerateReceipt"; Log.Debug("GenerateReceipt | REQUEST : " + tranId + " Notice : " + notice); var receiptResponse = _requestServices.GenerateReceipt(tranId, notice); return Ok(receiptResponse); } /// /// /// /// [HttpGet] [TokenAuthentication] [Route("mobile/GetNotificationList")] public IHttpActionResult GetNotificationList(string customerId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetNotificationList"; Log.Debug("GetNotificationList | REQUEST : " + customerId); var notificationResponse = _requestServices.GetNotificationList(customerId); return Ok(notificationResponse); } /// /// /// /// [HttpPost] [TokenAuthentication] [Route("mobile/UpdateNotification")] public IHttpActionResult UpdateNotification(string rowId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "UpdateNotification"; Log.Debug("UpdateNotification | REQUEST : " + rowId); var notificationResponse = _requestServices.UpdateNotification(rowId); return Ok(notificationResponse); } [HttpPost] [TokenAuthentication] [Route("mobile/tranhistory/{userId}")] public IHttpActionResult GetTransactionHistory(DateFilterParams search, string userId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetTransactionHistory"; Log.Debug("GetTransactionHistory | REQUEST : " + userId); var tranHistoryResponse = _requestServices.GetTransactionHistory(search, userId); return Ok(tranHistoryResponse); } /// /// /// /// /// [HttpPost] [TokenAuthentication] [Route("mobile/walletstatement/{userId}")] public IHttpActionResult GetWalletStatement(DateFilterParams search, string userId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "walletstatement"; Log.Debug("GetWalletStatement | REQUEST : " + userId + "|" + JsonConvert.SerializeObject(search)); JsonRxResponse walletStatement = new JsonRxResponse(); if (string.IsNullOrEmpty(userId)) { walletStatement.ErrorCode = "1"; walletStatement.Msg = "UserId is Missing"; return Ok(walletStatement); } walletStatement = _requestServices.GetWalletStatement(search, userId); return Ok(walletStatement); } /// /// /// /// /// [HttpGet] [Route("mobile/key")] public string GetKey() { //LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); //LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetKey"; //Log.Debug("user trying to generate key"); //return "sroj"; string rv = "false"; var regData = new ValidationModel { Dob = "", Email = "", Password = "0f984f876cd0381b8f3245aed644534e3ba056c46c7a13f1508f6176f5cb6958c11dccfb186ae641ddf4b97490c3f5de" }; List rules = new List(); rules.Add(new AtLeastOneLowerCaseRule()); rules.Add(new AtLeastOneNumberRule()); rules.Add(new AtLeastOneUpperCaseRule()); rules.Add(new AtLeastSpecialCharRule()); rules.Add(new DboValidationRule()); rules.Add(new PasswordAsEmailRule()); rules.Add(new PatternMatchRule()); foreach (PasswordRule rule in rules) { var isvalid = rule.Validate(regData); if (!isvalid.IsValid.Equals(true)) { rv = "true"; } } return rv; } /// /// /// /// protected IHttpActionResult ModelValidationError(ModelStateDictionary modelState) { var modelErrors = modelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .First()[0].ErrorMessage; JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "1", Msg = string.IsNullOrEmpty(modelErrors) ? "It seems like incorrect Json input(s)." : modelErrors, Data = "" }; return Ok(jsonRx); } /* 2019.09 @Dana */ /// /// /// /// /// [HttpPost] [TokenAuthentication] [Route("mobile/DomestricTranhistory/{userId}")] public IHttpActionResult GetDomesticTransactionHistory(DateFilterParams search, string userId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = userId; LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GetDomesticTransactionHistory"; Log.Debug("GetDomesticTransactionHistory | REQUEST : " + userId); var tranHistoryResponse = _requestServices.GetDomesticTransactionHistory(search, userId); return Ok(tranHistoryResponse); } /// /// /// /// [HttpPost] [TokenAuthentication] [Route("mobile/DomesticReceipt/{tranId}")] public IHttpActionResult GenerateDomesticReceipt(string tranId) { LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = Guid.NewGuid(); LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "GenerateDomesticReceipt"; Log.Debug("GenerateDomesticReceipt | REQUEST : " + tranId); var receiptResponse = _requestServices.GenerateDomesticReceipt(tranId); return Ok(receiptResponse); } } }