コード例 #1
0
        public void Login(string emailAddress, string Password)
        {
            if (LogEvent != null)
            {
                LogEvent(emailAddress + " Is Logging in");
            }
            // Does the User Exist in the Database?
            using (var db = new DamoclesEntities())
            {
                AddClient(emailAddress);   // Add the User's Client for this logon
                var uid  = User.GetUserID(emailAddress);
                var user = db.Users.First(u => u.UserId == uid);
                user.IsOnline = true;   // Set the User to Online

                int rows = db.SaveChanges();
                UpdateLoginHistory(emailAddress); // Add the User's Logon History

                if (rows == 1)
                {
                    LogEvent(emailAddress + " is Logged In");
                    LoginResultEvent(true);
                }
                else
                {
                    LogEvent(emailAddress + " Failed to Log In");
                    LoginResultEvent(false);
                }
            }
        }
コード例 #2
0
        private void UpdateLogOffHistory(string emailAddress)
        {
            if (LogEvent != null)
            {
                LogEvent("Updating Users LogOff History");
            }
            using (var db = new DamoclesEntities())
            {
                var uid = User.GetUserID(emailAddress);
                var loh = db.LogonHistories.First(lh => lh.LoggedOffDate == null && lh.UserId == uid);
                loh.LoggedOffDate = DateTime.UtcNow;
                db.SaveChanges();


                var us = db.Users.First(u => u.UserId == uid);
                us.IsOnline        = false;
                us.CurrentClientID = null;
                db.SaveChanges();
            }
        }