Link to home
Start Free TrialLog in
Avatar of brendanlefavre
brendanlefavreFlag for United States of America

asked on

Nested IF statement help

Under my button click event, I have several if statements. I'm having trouble with the evaluation of the passwordLastSet. Even if it has been more than 24 hours, it goes directly to the else statement that the password has been set less than 24 hours ago.

Cheers,
Brendan
protected void btnSubmit_Click(object sender, EventArgs e)
        {
            System.Guid guid = Guid.NewGuid();
            logInfo.IPaddress = "need to add IP address method";
            if (txtUser.Text != string.Empty)
            {
                string username = txtUser.Text.ToString();

                if (DateTime.Now.Subtract(passwordLastSet).TotalHours < 24)
                {
                    if (UserExists(FindName(username)))
                    {
                        logInfo.userName = txtUser.Text.ToString();
                        logInfo.TrackingID = guid;
                        logInfo.requestType = "Request Password";
                        logInfo.email = eMailAddress.ToString();
                        logInfo.InsertRequest();


                        lblStatus.Text = "all is good";

                    }
                    else
                    {
                        lblStatus.Text = "The user does not exists";
                        logInfo.errorType = lblError.Text.ToString();
                        logInfo.userName = txtUser.Text.ToString();
                        logInfo.TrackingID = guid;
                        logInfo.InsertRequestError();
                    }
                    // return a message that the time since last reset has been less than 24 hours
                }
                else
                {
                    lblStatus.Text = "the time has been less than 24 hours";
                }
                    
                
            }
        }

Open in new window

Avatar of shrikantss
shrikantss
Flag of India image

in your code sheck what this line will return

DateTime.Now.Subtract(passwordLastSet).TotalHours
then try to convert that value to integer
by using
 convert.toint16(DateTime.Now.Subtract(passwordLastSet).TotalHours)
then check it
ASKER CERTIFIED SOLUTION
Avatar of jdavistx
jdavistx

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brendanlefavre

ASKER

your sample worked, and helped me achieve the result I was looking for. Also I was able to adapt this to a few other areas of my project.