Example #1
0
        public static SessionManager initSession(User user)
        {
            if (instance == null)
            {
                //verify lock of object of multiple threads
                lock (syncRoot)
                {
                    if (instance == null)
                    {
                        instance = new SessionManager();

                        BjaContext context = new BjaContext();

                        session = new Session();
                        session.Id = IdentifierGenerator.NewId();
                        session.IdUser = user.Id;
                        session.User = user;
                        session.UserName = user.UserName;
                        session.CompleteName = user.CompleteName;
                        session.InitDate = DateTime.Now;

                        context.Sessions.Add(session);

                        context.SaveChanges();
                    }
                }
            }

            return instance;
        }
Example #2
0
        public static void endSession()
        {
            BjaContext context = new BjaContext();

            session.EndDate = DateTime.Now;

            context.Sessions.Attach(session);

            context.Entry(session).State = System.Data.EntityState.Modified;

            context.SaveChanges();

            instance = null;
        }