public async Task Handle(DeleteNewRecentUserByUsernameCommand command) { var recentUser = await _context.RecentUsers .SingleOrDefaultAsync(x => x.Username == command.Username); if (recentUser == null) { throw new RecentUserNotFoundException(command.Username); } _context.Remove(recentUser); await _context.SaveChangesAsync(); }
public async Task DeleteRecentUsers() { await using var db = new TestApiDbContext(_dbContextOptions); var recentUsers = await db.RecentUsers .Where(x => x.Username == EmailData.RECENT_USER_USERNAME) .AsNoTracking() .ToListAsync(); foreach (var user in recentUsers) { db.Remove(user); await db.SaveChangesAsync(); } }
public async Task DeleteUsers() { await using var db = new TestApiDbContext(_dbContextOptions); var users = await db.Users .Where(x => x.Application == Application.TestApi.MapToContractEnum()) .AsNoTracking() .ToListAsync(); foreach (var user in users) { db.Remove(user); await db.SaveChangesAsync(); } }