protected void Page_Load(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Convert.ToString(Context.Items["SessionID"])))
        {
            qPtl_Sessions session = new qPtl_Sessions(Convert.ToInt32(Context.Items["SessionID"]));
            if (session.SessionID > 0)
            {
                session.StopTime = DateTime.Now;
                session.Update();
            }

            qPtl_User user = new qPtl_User(Convert.ToInt32(Context.Items["UserID"]));
            if (user.UserID > 0)
            {
                DateTime last_time = new DateTime();
                last_time = Convert.ToDateTime(user.LastTimeSeen);
                if (!String.IsNullOrEmpty(Convert.ToString(user.LastTimeSeen)))
                    user.LastTimeSeen = last_time.AddMinutes(-16);
                user.Update();
            }
        }

        Session.Abandon();
        FormsAuthentication.SignOut();
        Response.Redirect("~/default.aspx", true);
    }
        public static void UpdateMobileSession(int user_id)
        {
            int curr_session_id = 0;

            curr_session_id = GetCurrentSessionID(user_id);

            if (curr_session_id > 0)
            {
                qPtl_Sessions session = new qPtl_Sessions(curr_session_id);
                session.LastTimeSeen = DateTime.Now;
                session.StopTime     = null;
                session.Update();
            }
        }
        public static int UserLogoff(int user_id, int session_id)
        {
            qPtl_Sessions session = new qPtl_Sessions(session_id);

            session.StopTime = DateTime.Now;
            session.Update();

            qPtl_User user      = new qPtl_User(Convert.ToInt32(user_id));
            DateTime  last_time = new DateTime();

            last_time         = Convert.ToDateTime(user.LastTimeSeen);
            user.LastTimeSeen = last_time.AddMinutes(-16);
            user.Update();

            return(user_id);
        }
        public static void UpdateMobileSession(int user_id)
        {
            int curr_session_id = 0;

            curr_session_id = GetCurrentSessionID(user_id);

            if (curr_session_id > 0)
            {
                qPtl_Sessions session = new qPtl_Sessions(curr_session_id);
                session.LastTimeSeen = DateTime.Now;
                session.StopTime = null;
                session.Update();
            }
        }
        public static int UserLogoff(int user_id, int session_id)
        {
            qPtl_Sessions session = new qPtl_Sessions(session_id);
            session.StopTime = DateTime.Now;
            session.Update();

            qPtl_User user = new qPtl_User(Convert.ToInt32(user_id));
            DateTime last_time = new DateTime();
            last_time = Convert.ToDateTime(user.LastTimeSeen);
            user.LastTimeSeen = last_time.AddMinutes(-16);
            user.Update();

            return user_id;
        }