private void SetReConnection(ConnectionInfo reConnectionInfo) { Guid ConnectionID = Guid.Parse(reConnectionInfo.ConnectionId); using (var db = new LicensingEntities()) { var users = db.User.Where(f => f.UserName == reConnectionInfo.UserName); if (users.Count() > 0) { var user = users.First(); user.LastActivity = reConnectionInfo.CurrentDateTime; } else { var user = new User { ID = Guid.NewGuid(), UserName = reConnectionInfo.UserName, Company = reConnectionInfo.Company, ProjectType = reConnectionInfo.ProjectType, Role = 1, LastActivity = reConnectionInfo.CurrentDateTime }; db.User.Add(user); } var _connections = db.Connection.Where(con => con.ConnectionID == ConnectionID); if (_connections.Count() > 0) { var _connection = _connections.First(); _connection.ReConnectedDateTime = reConnectionInfo.CurrentDateTime; _connection.LastActivity = reConnectionInfo.CurrentDateTime; _connection.Status = (int)ConnectionStatus.OnReConnected; } else { CreateConnection(reConnectionInfo); } db.SaveChanges(); } }
private void SetConnection(ConnectionInfo connectionInfo, LicenseUser licenseUser) { using (var db = new LicensingEntities()) { Guid ConnectionID = Guid.Parse(connectionInfo.ConnectionId); var users = db.User.Where(f => f.UserName == connectionInfo.UserName); if (users.Count() == 0) { int Isrole; if(!int.TryParse(connectionInfo.Role, out Isrole)) { Isrole = 1; } var user = new User { ID = Guid.NewGuid(), UserName = connectionInfo.UserName, Company = connectionInfo.Company, ProjectType = connectionInfo.ProjectType, Role = Isrole, LastActivity = connectionInfo.CurrentDateTime }; db.User.Add(user); } else { var user = users.First(); user.LastActivity = DateTime.UtcNow; } db.SaveChanges(); var _connections = db.Connection.Where(con => con.ConnectionID == ConnectionID); if (_connections.Count() == 0) { CreateConnection(connectionInfo); } Clients.Client(connectionInfo.ConnectionId).licenseExpired(licenseUser.EndDateTime); } }