Send SMS Method in a web service executes multiple times

I am consuming a method in a web service soap. It runs smoothly except the Send SMS Method. The message is being sent multiple times to the user.

case Resource.Id.btnLogin:

                hud = KK.Create(this.Activity)
                     .SetSize(75, 75);
                hud.Show();

                loginClick(); //Function for button click

                   break;


  private void loginClick(){
        hud.Dismiss();
        if (TextUtils.IsEmpty(txtID.Text.ToString()) || TextUtils.IsEmpty(txtPass.Text.ToString()))
        {
            AlertMessageView.showAlertDialog(this.Activity, "Error", GetString(Resource.String.Msg33), "OK", null, null, null);
        }
        else if (txtID.Text.ToString().Trim().Length < 12)
        {
            tilID.Error = GetString(Resource.String.Msg8);
        }
        else
        {

            service.VerifyLoginAsync("User", "password", txtID.Text.ToString(), txtPass.Text.ToString());
            service.VerifyLoginCompleted += Service_VerifyLoginCompleted;
        }
}

Consuming web service method Verify Login:

private void Service_VerifyLoginCompleted(object sender, IDWebService.VerifyLoginCompletedEventArgs e)
{
Console.WriteLine("IsValid" + e.Result.isValid);

if (e.Result.isValid == true)
{

    #region firstLogin
    if (e.Result.isfirstlogin == "1")
    {
        Console.WriteLine("Redirect Verification page");

        AlertMessageView.showAlertDialog(this.Activity, "Invalid login", "Is it your first time to login?", "YES", "NO", dialogFTL, null);

        //var intent = new Intent(this.Activity, typeof(OTPActivity));
        //StartActivity(intent);
        //Activity.Finish();


    }
    else
    {
        #region lockedout
        if (e.Result.islockedout == "1")
        {
            Console.WriteLine("Error Msg");
            AlertMessageView.showAlertDialog(this.Activity, "Account has been locked", "Kindly coordinate with employer", "OK", null, null, null);

        }

        else {

            #region forgotPass
            if (e.Result.isforgotpass == "1")
            {
                AlertMessageView.showAlertDialog(this.Activity, "Invalid Password", "Please change your password.", "YES", "CANCEL", dialogFTL, null);

            }
            else
            {
                #region enabled
                if (e.Result.isenabled == "1")
                {
                    #region validpass
                    if (e.Result.isValidPassword == true)
                    {
                        Console.WriteLine("Number:" + e.Result.number);
                        Console.WriteLine("First Name:" + e.Result.fname);

                        fname = e.Result.fname;
                        number = e.Result.number;
                        GenerateOTP();

                        var intent = new Intent(this.Activity, typeof(OTPLoginActivity));
                        StartActivity(intent);
                        Activity.Finish();
                    }
                    else
                    {
                        Console.WriteLine("Failed Date Login");
                        #region morethan24
                        if (e.Result.isMoreThan24Hrs == true)
                        {

                            loginCounter = 0;
                            MemberFailedLogin(loginCounter.ToString());
                        }
                        else
                        {
                            loginCounter = Convert.ToInt32(e.Result.failedattempt) + 1;

                            if (loginCounter < 3)
                            {
                                MemberFailedLogin(loginCounter.ToString());
                                Console.WriteLine("Invalid Login" + loginCounter);
                            }
                            else
                            {
                                Console.WriteLine("Account has been locked" + loginCounter);

                                MemberLockAccount();


                                AlertMessageView.showAlertDialog(this.Activity, "Account has been locked", "Kindly coordinate with employer.", "OK", null, null, null);
                            }


                        }
                        #endregion

                    }
                    #endregion 
                }
                else
                {

                    AlertMessageView.showAlertDialog(this.Activity, "Account disabled", "Please contact your employer.", "OK", null, null, null);

                }
                #endregion

            }
            #endregion
        }
        #endregion

    }
    #endregion
}
else
{
    Console.WriteLine("Invalid");

    AlertMessageView.showAlertDialog(this.Activity, null, "Invalid Credentials", "OK", null, null, null);

}

}

region GenerateOTP

        private void GenerateOTP()
    { 

        service.GenerateOTPAsync("user", "password");
        service.GenerateOTPCompleted += Service_GenerateOTPCompleted;
    }

    private void Service_GenerateOTPCompleted(object sender, HDMFWebService.GenerateOTPCompletedEventArgs e)
    {
        if (e.Result.isValid == true)
        {

                SendSMS(e.Result.OTPCode);              // Executes multiple times

        }
    }
    #endregion

    #region Send SMS
        private void SendSMS( string otpcode)
    {
        Console.WriteLine(fname);
        Console.WriteLine(number);
        var msg = "Hi " + fname + ", Your OTP is " + otpcode + ".";
        service.SendSMSAsync("user", "password", number, msg);              // Executes multiple times
        service.SendSMSCompleted += Service_SendSMSCompleted;
    }

    private void Service_SendSMSCompleted(object sender, WebService.SendSMSCompletedEventArgs e)
    {
        if (e.Result == true)
        {
            Console.WriteLine(e.Result + "Send SMS");

            //Direct to Verification Page
            var intent = new Intent(this.Activity, typeof(OTPLoginActivity));
            StartActivity(intent);
            Activity.Finish();
        }
    }
    #endregion
Sign In or Register to comment.