Beispiel #1
0
 public async Task <IActionResult> LinkMobileNumber([FromBody] LinkMobile linkMobile)
 {
     try
     {
         return(Ok(this.Content(await _account.LinkMobileNumber(linkMobile), "application/json")));
     }
     catch (Exception ex)
     {
         //ExceptionLog exception = await _exceptionService.UpsertException(ex, "GetUserRoles", "", "");
         return(StatusCode((int)HttpStatusCode.InternalServerError, new CustomMesageError(ex.Message).Message));
     }
 }
Beispiel #2
0
        public async Task <string> GetOtpCode(LinkMobile linkMobile)
        {
            try
            {
                //generate otp
                linkMobile.OtpCode     = GenerateRandomOTP(5);
                linkMobile.ReferenceID = GenerateRandomOTP(5);

                DataSet dataResult = new DataSet();
                dbconn = new DatabaseConnection();
                dbconn.DatabaseConn("OtpCodeSave");

                if (dbconn.sqlConn.State == ConnectionState.Open)
                {
                    dbconn.sqlConn.Close();
                }
                dbconn.sqlConn.Open();
                dbconn.sqlComm.Parameters.Clear();
                dbconn.sqlComm.CommandTimeout = 0;
                dbconn.sqlComm.Parameters.AddWithValue("@mobilenumber", linkMobile.MobileNumber);
                dbconn.sqlComm.Parameters.AddWithValue("@otpcode", linkMobile.OtpCode);
                dbconn.sqlComm.Parameters.AddWithValue("@referenceNo", linkMobile.ReferenceID);
                dbconn.sqlComm.Parameters.AddWithValue("@userid", linkMobile.UserId);

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = dbconn.sqlComm;
                da.Fill(dataResult);
                dbconn.sqlConn.Close();

                if (dataResult.Tables.Count > 0)
                {
                    return(await Task.FromResult(dataResult.Tables[0].Rows[0]["ReferenceID"].ToString()));
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbconn.sqlConn.Close();
                dbconn.sqlConn.Dispose();
                SqlConnection.ClearPool(dbconn.sqlConn);
            }
        }
Beispiel #3
0
        public async Task <string> LinkMobileNumber(LinkMobile linkMobile)
        {
            try
            {
                if (linkMobile.Action == "OTPValidation")
                {
                    return(await _otpCode.ValidateOTPCode(linkMobile));
                }
                else
                {
                    var result = await _otpCode.GetOtpCode(linkMobile);

                    var resultMesage = "";

                    if (result != "")
                    {
                        resultMesage = "Success";
                    }

                    else
                    {
                        resultMesage = "Error during sending OTPCode.";
                    }

                    //var message = new StringBuilder();

                    //message.Append("Your OTP is " + linkMobile.OtpCode + ". ");
                    //message.Append("Valid for 5 mins. Do not disclose One-Time Password.");

                    ////sendotp
                    //Helper.Helper helper = new Helper.Helper(_configuration);
                    //var otpSendStatus = await helper.itexmo(linkMobile.MobileNumber, message.ToString());

                    //if (otpSendStatus.ToString() == "0")

                    return(resultMesage);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public async Task <string> ValidateOTPCode(LinkMobile linkMobile)
        {
            try
            {
                DataSet dataResult = new DataSet();
                dbconn = new DatabaseConnection();
                dbconn.DatabaseConn("ValidateOTPCode");

                if (dbconn.sqlConn.State == ConnectionState.Open)
                {
                    dbconn.sqlConn.Close();
                }
                dbconn.sqlConn.Open();
                dbconn.sqlComm.Parameters.Clear();
                dbconn.sqlComm.CommandTimeout = 0;
                dbconn.sqlComm.Parameters.AddWithValue("@mobilenumber", linkMobile.MobileNumber);
                dbconn.sqlComm.Parameters.AddWithValue("@otpcode", linkMobile.OtpCode);
                dbconn.sqlComm.Parameters.AddWithValue("@userid", linkMobile.UserId);

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = dbconn.sqlComm;
                da.Fill(dataResult);
                dbconn.sqlConn.Close();

                return(await Task.FromResult("LinkMobileNumber"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbconn.sqlConn.Close();
                dbconn.sqlConn.Dispose();
                SqlConnection.ClearPool(dbconn.sqlConn);
            }
        }