public async Task <bool> RevokeAccess(int id, ClaimsPrincipal user) { try { var u = await _userManager.GetUserAsync(user); var access = _db.ApplicationFeatures.Where(f => f.ApplicationUserId == u.Id && f.Id == id).FirstOrDefault(); if (access != null) { access.RevokeDate = DateTimeOffset.Now; access.IsRevoked = true; } _db.ApplicationFeatures.Update(access); await _db.SaveChangesAsync(); return(true); } catch (System.Exception ex) { _logger.LogError(ex, $"Unable to revoke access. Detail:{ex.Message}"); } return(false); }
public override async Task OnConnectedAsync() { var name = Context.User.Identity.Name; if (string.IsNullOrEmpty(name)) { lock (_syncLock) { var userId = _random.Next(0, 10); name = $"WebUser{userId.ToString()}"; } } else { name = _configuration["HostUser:Name"]; await Clients.All.SendAsync("SayHello", "I'm online"); } string connectionId = Context.ConnectionId ?? Guid.NewGuid().ToString(); var user = _db.Users.Where(u => u.UserName == name).FirstOrDefault(); bool isNew = false; if (user == null) { isNew = true; user = new User() { UserName = name }; } user.Connections = new List <Connection>(); user.Connections.Add(new Connection() { ConnectionID = connectionId, Connected = true, ConnectionDate = DateTime.Now }); if (isNew) { _db.Users.Add(user); } else { _db.Users.Update(user); } await _db.SaveChangesAsync(); await Clients.Caller.SendAsync("GiveName", name); await base.OnConnectedAsync(); }