I want to update the field in my table, and insert some information about the user that login success in my web site in another table.
This is my code :
public class CustomerModels:ItemEntityDataContext
{
public bool ValidateCustomer(string username, string password)
{
var user = this.DataContext.Customers
.Where(s => s.ActiveInWebLogin == 1 &&
s.WebAccount == username &&
s.Password == password)
.SingleOrDefault();
if (user != null)
{
this.UpdateCustomerLastUpdateStatus(user);
return true;
}
return false;
}
public void UpdateCustomerLastUpdateStatus(Customer c)
{
c.LastWebLogIn = DateTime.Now;
String ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
WebsiteTracking web_track = new WebsiteTracking();
web_track.IDUser = c.ID;
web_track.ActiveLoginDate = DateTime.Now;
web_track.IPAddress = ipAddress;
this.DataContext.SaveChanges();
}
}
When I wrote this, It is only modify the field LastWebLogIn in Customer table, but not insert to the field in table WebsiteTracking.
Anyone can solve this? Thanks.
You might want to add created
WebsiteTrackingto collectionthis.DataContext.WebsiteTracking. Other way is usingWebsiteTrackingproperty of yourUserobject. Until you use one of them DataContext doesn’t know anything aboutweb_trackobject.