Reputation: 478
There is no error and newUser object is found on database but database is not modified. Whats the problem. As new learner, elaborate answer is much appreciated. thanks.
TBL_LogIn newUser = new TBL_LogIn();
newUser = hrmsDb.TBL_LogIn.Where(x => x.EmployeeID == inputEmployeeID).FirstOrDefault();
try
{
if (newUser != null)
{
AddLogInInfo(newUser);
hrmsDb.Entry(newUser).State = EntityState.Modified;
hrmsDb.SaveChanges();
}
else
{ }
}
catch (Exception ex)
{
throw;
}
/*-----Functions to Update New Employee Information in Three tables-------*/
private void AddLogInInfo(TBL_LogIn newUser)
{
string UserName = TextBoxUsername.Text;
string Password = TextBoxPassword.Text;
string UserType = TextBoxUserType.Text;
newUser.UserName = UserName;
newUser.PassWord = Password;
newUser.UserType = UserType;
}
Upvotes: 3
Views: 1125
Reputation: 18165
I don't know if either of these is causing the problem but you shouldn't be creating a new object when you're just going to retrieve into the variable on the next line and it should not be necessary to set the state of the object, EF should take care of that for you.
TBL_LogIn newUser = hrmsDb.TBL_LogIn.Where(x => x.EmployeeID == inputEmployeeID).FirstOrDefault();
if (newUser != null)
{
AddLogInInfo(newUser);
hrmsDb.SaveChanges();
}
else
{ }
P.S. If all you're going to do in the catch block is rethrow the exception don't bother putting in a try/catch because that's what will happen anyway.
Upvotes: 1