Exemplo n.º 1
0
        public async Task CloseSession(int code)
        {
            if (DatabaseContext.Active.Sessions.ContainsKey(code))
            {
                AdminInstance admin = DatabaseContext.Active.Sessions[code];
                DatabaseContext.Active.Sessions.Remove(code);

                Session session = await _context.Sessions.FindAsync(admin.EventCode);

                if (session != null)
                {
                    session.Questions = admin.SaveSession();
                    if (session.Questions == null)
                    {
                        DatabaseContext.Active.Sessions.Add(code, admin);
                        HttpContext.Response.StatusCode = 500;
                        return;
                    }

                    session.LastOpen = DateTime.UtcNow.ToString("G", CultureInfo.CreateSpecificCulture("en-US"));
                    _context.Sessions.Update(session);
                }

                await _context.SaveChangesAsync();

                HttpContext.Response.StatusCode = 200;
            }
        }
Exemplo n.º 2
0
        private ActiveSessions()
        {
            Sessions = new Dictionary <int, AdminInstance>();
            AdminInstance instance = new AdminInstance {
                Owner = "*****@*****.**", SessionIdentity = 123123
            };

            Sessions.Add(instance.SessionIdentity, instance);
        }
Exemplo n.º 3
0
        public async void LoadSession(int code)
        {
            if (_context == null)
            {
                ActiveSessions active = ActiveSessions.Instance;
                if (active.Sessions.TryGetValue(code, out AdminInstance admin1))
                {
                    HttpContext.Response.StatusCode = 200;
                    return; //Session already active?
                }
                else
                {
                    HttpContext.Response.StatusCode = 404;
                    return; //Session doesn't exist!
                }
            }

            if (_context.Active.Sessions.TryGetValue(code, out AdminInstance admin))
            {
                HttpContext.Response.StatusCode = 200;
                return; //Session already active?
            }
            else
            {
                Session session = await _context.Sessions.FindAsync(code);

                if (session == null)
                {
                    HttpContext.Response.StatusCode = 404;
                    return; //Session doesn't exist!
                }

                AdminInstance model = new AdminInstance();
                model.LoadSession(session.Questions);

                _context.Active.Sessions.Add(code, model);
                HttpContext.Response.StatusCode = 201;
                return; //Loaded from database
            }
        }