public void DeleteSession() { using (JolTudomEEntities ent = new JolTudomEEntities()) { ent.Attach(_Session); ent.Sessions.DeleteObject(_Session); ent.SaveChanges(); } }
public void UpdateSessionLastAction() { using (JolTudomEEntities ent = new JolTudomEEntities()) { ent.Attach(_Session); _Session.LastAction = DateTime.UtcNow; ent.SaveChanges(); } }
public static SessionManager NewSession(PersonDetails loggedinuser) { // generate a token // this could be more secure ... byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = Guid.NewGuid().ToByteArray(); string token = Convert.ToBase64String(time.Concat(key).ToArray()); using (JolTudomEEntities ent = new JolTudomEEntities()) { // delete those sessions, which are dead - over of the given timeout ent.usp_SessionsCleanup(Settings.Default.SessionTimeoutMinute); // delete those tests, which are not completed ent.usp_CleanupTests(Settings.Default.MaxTestExecutionHour); // this must be saved to the database with the timestamp ent.Sessions.AddObject(new Session { Token = token, PersonID = loggedinuser.PersonID, RoleID = loggedinuser.RoleID, LastAction = DateTime.UtcNow }); ent.SaveChanges(); } SessionManager sm = new SessionManager(token); return sm; }