Exemplo n.º 1
0
        void LogSessionAsync(string browser, string ip, User user, string sessionId)
        {
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    using (var db = new AlumniDbContext())
                    {
                        var session       = new Session();
                        session.Browser   = browser;
                        session.IPAddress = ip;
                        session.UserName  = user.FullName;
                        session.Start     = DateTime.UtcNow;
                        session.UserId    = user.UserId;
                        session.SessionId = sessionId;

                        var pastActSession = db.UserSessions.Where(s => s.UserId == user.UserId && s.End == null && s.IPAddress == ip);
                        foreach (var item in pastActSession)
                        {
                            item.End             = DateTime.UtcNow;
                            db.Entry(item).State = System.Data.EntityState.Modified;
                        }

                        db.UserSessions.Add(session);
                        db.SaveChanges();
                    }
                }
                catch { }
            })).Start();
        }
Exemplo n.º 2
0
 protected void UpdateUser(User user)
 {
     _db.Entry(user).State = System.Data.EntityState.Modified;
     _db.SaveChanges();
 }