i am developing a project (using 3-tier approach) in which i am using LINQ TO SQL... i want to update user...
but i am facing some problem. it does not give me any error but also do not update the user detail
here is the program sequence;
in UpdateProfile.aspx
String currentUser = Session["BMUser"].ToString();
String displayName = txtDisplayName.Text;
String username = currentUser;
String emailAddress = txtEmailAddress.Text;
String secretQuestion = txtSecretQuestion.Text;
String secretAnswer = txtSecretAnswer.Text;
if (UserManager.UpdateProfile(username, displayName, emailAddress, secretQuestion, secretAnswer))
{
lblStatus.Text = "Profile Updated";
}
else
lblStatus.Text = "Unable to Update Profile";
the UserManager is BLL class
public class UserManager
{
public static bool UpdateProfile(String username, String displayName, String emailAddress, String secretQuestion, String secretAnswer)
{
// This method will return BM_User (BM_User in entity class generated by LINQ TO SQL)
BM_User user = UserCatalog.GetUserByName(username);
if (user != null)
{
user.DisplayName = displayName;
user.EmailAddress = emailAddress;
user.SecretQuestion = secretQuestion;
user.SecretAnswer = secretAnswer;
if (UserManagerDAO.UpdateUser(user, false))
{
//HttpContext.Current.Session["BMUser"] = userToUpdate;
return true;
}
else
return false;
}
else
return false;
}
}
and finally UserManagerDAO
public class UserManagerDAO
{
public static bool UpdateUser(BM_User user, bool changeLoginDateTime)
{
BugManDataContext db = new BugManDataContext();
if (changeLoginDateTime == true)
user.LastLoginDate = DateTime.Now;
db.SubmitChanges();
return true;
}
}
after this when i get the detail of this updated user. it shows me previous detail. mean it is not updating the user's detail with new one...
kindly solve this problem
In your UpdateUser method you are declaring a new DataContext, so the BM_User paramter is not attached to it and that's why the SubmitChanges method does nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With