Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Web / PUSG.Web / Services / SessionService.cs
blob: d26e6247aaf4dd088d495a57b2081a13c896e992 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Generic;
using System.Linq;

namespace PUSG.Web.Services
{
    public class SessionService : ISessionService
    {
        private Dictionary<string, string> users;

        public SessionService()
        {
            this.users = new Dictionary<string, string>();
            this.LiveConnections = new List<string>();
        }

        public Dictionary<string, string> Users => this.users;

        public List<string> LiveConnections { get; }

        public void AddUser(string connectionId, string username)
        {
            this.users[connectionId] = username;
        }

        public KeyValuePair<string, string> GetUser(string connectionId)
        {
            return this.users.SingleOrDefault(user => user.Key == connectionId);
        }

        public bool IsLogged(string credential)
        {
            return this.users.ContainsKey(credential) || this.users.ContainsValue(credential);
        }

        public void RemoveUser(string connectionId)
        {
            this.users.Remove(connectionId);
        }
    }
}