/// <inheritdoc/> public async Task DeleteUserSessionsAsync(UserSessionsFilter filter) { filter.Validate(); var query = _sessionDbContext.UserSessions.AsQueryable(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { query = query.Where(x => x.SubjectId == filter.SubjectId); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { query = query.Where(x => x.SessionId == filter.SessionId); } var items = await query.ToArrayAsync(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { items = items.Where(x => x.SubjectId == filter.SubjectId).ToArray(); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { items = items.Where(x => x.SessionId == filter.SessionId).ToArray(); } _sessionDbContext.RemoveRange(items); await _sessionDbContext.SaveChangesAsync(); }
/// <inheritdoc/> public async Task <IEnumerable <UserSession> > GetUserSessionsAsync(UserSessionsFilter filter) { filter.Validate(); var query = _sessionDbContext.UserSessions.AsQueryable(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { query = query.Where(x => x.SubjectId == filter.SubjectId); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { query = query.Where(x => x.SessionId == filter.SessionId); } var items = await query.ToArrayAsync(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { items = items.Where(x => x.SubjectId == filter.SubjectId).ToArray(); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { items = items.Where(x => x.SessionId == filter.SessionId).ToArray(); } return(items.Select(x => { var item = new UserSession(); x.CopyTo(item); return item; }).ToArray()); }
public async Task <IReadOnlyCollection <UserSession> > GetUserSessionsAsync(UserSessionsFilter filter, CancellationToken cancellationToken) { filter.Validate(); var query = _sessionDbContext.UserSessions.Where(x => x.ApplicationName == _applicationDiscriminator).AsQueryable(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { query = query.Where(x => x.SubjectId == filter.SubjectId); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { query = query.Where(x => x.SessionId == filter.SessionId); } var items = await query.Where(x => x.ApplicationName == _applicationDiscriminator).ToArrayAsync(cancellationToken); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { items = items.Where(x => x.SubjectId == filter.SubjectId).ToArray(); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { items = items.Where(x => x.SessionId == filter.SessionId).ToArray(); } return(items.Select(x => { var item = new UserSession(); x.CopyTo(item); return item; }).ToArray()); }
public async Task DeleteUserSessionsAsync(UserSessionsFilter filter, CancellationToken cancellationToken) { filter.Validate(); var query = _sessionDbContext.UserSessions.Where(x => x.ApplicationName == _applicationDiscriminator).AsQueryable(); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { query = query.Where(x => x.SubjectId == filter.SubjectId); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { query = query.Where(x => x.SessionId == filter.SessionId); } var items = await query.Where(x => x.ApplicationName == _applicationDiscriminator).ToArrayAsync(cancellationToken); if (!String.IsNullOrWhiteSpace(filter.SubjectId)) { items = items.Where(x => x.SubjectId == filter.SubjectId).ToArray(); } if (!String.IsNullOrWhiteSpace(filter.SessionId)) { items = items.Where(x => x.SessionId == filter.SessionId).ToArray(); } _sessionDbContext.RemoveRange(items); try { await _sessionDbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException ex) { // suppressing exception for concurrent deletes // https://github.com/DuendeSoftware/BFF/issues/63 _logger.LogDebug("DbUpdateConcurrencyException: {error}", ex.Message); foreach (var entry in ex.Entries) { // mark detatched so another call to SaveChangesAsync won't throw again entry.State = EntityState.Detached; } } }