public async Task <List <RiftUser> > GetAsync(Expression <Func <RiftUser, bool> > predicate) { await using var context = new RiftContext(); return(await context.Users .Where(predicate) .ToListAsync()); }
public async Task AddAsync(RiftActiveEvent activeEvent, CancellationToken ct = default) { await using var context = new RiftContext(); await context.ActiveEvents.AddAsync(activeEvent, ct); await context.SaveChangesAsync(ct); }
public async Task <bool> EnsureExistsAsync(ulong userId) { await using var context = new RiftContext(); if (await context.Users .AsQueryable() .AnyAsync(x => x.UserId == userId)) { return(true); } try { var entry = new RiftUser { UserId = userId, }; await context.Users.AddAsync(entry); await context.SaveChangesAsync(); OnUserCreated?.Invoke(null, new UserCreatedEventArgs(userId)); return(true); } catch { RiftBot.Log.Error($"Failed to check {nameof(EnsureExistsAsync)} for user {userId.ToString()}."); return(false); } }
public async Task <int> GetCountAsync() { await using var context = new RiftContext(); return(await context.Users .AsQueryable() .CountAsync()); }
public async Task <List <RiftInventory> > GetAllAsync() { await using var context = new RiftContext(); return(await context.Inventory .AsQueryable() .ToListAsync()); }
public async Task <RiftStreamer> GetAsync(ulong userId) { await using var context = new RiftContext(); return(await context.Streamers .AsQueryable() .FirstOrDefaultAsync(x => x.UserId == userId)); }
public async Task AddAsync(RiftReward reward) { await using var context = new RiftContext(); await context.Rewards.AddAsync(reward); await context.SaveChangesAsync(); }
public async Task <bool> TryUpdateAsync(RiftReward reward) { await using var context = new RiftContext(); var data = await GetAsync(reward.Id); if (data is null) { return(false); // nothing to update } var entry = context.Entry(data); if (!reward.Description.Equals(data.Description)) { entry.Property(x => x.Description).IsModified = true; } if (!reward.ItemsData.Equals(data.ItemsData)) { entry.Property(x => x.ItemsData).IsModified = true; } if (!reward.RoleData.Equals(data.RoleData)) { entry.Property(x => x.RoleData).IsModified = true; } await context.SaveChangesAsync(); return(true); }
public async Task <bool> AnyAsync() { await using var context = new RiftContext(); return(await context.EventSchedule .AsQueryable() .AnyAsync()); }
public async Task <RiftEvent> GetAsync(string name) { await using var context = new RiftContext(); return(await context.Events .AsQueryable() .FirstOrDefaultAsync(x => x.Name.Equals(name, StringComparison.InvariantCulture))); }
public async Task <RiftProfileBackground> GetAsync(int id) { await using var context = new RiftContext(); return(await context.Backgrounds .AsQueryable() .FirstOrDefaultAsync(x => x.Id == id)); }
public async Task AddAsync(RiftProfileBackground background) { await using var context = new RiftContext(); await context.Backgrounds.AddAsync(background); await context.SaveChangesAsync(); }
public async Task <bool> HasAsync(ulong userId, ulong roleId) { await using var context = new RiftContext(); return(await context.TempRoles .AsQueryable() .AnyAsync(x => x.UserId == userId && x.RoleId == roleId)); }
public async Task UpdatePercentAsync(ulong userId, uint percent) { await EnsureExistsAsync(userId); var oldToxicity = await GetAsync(userId); await using var context = new RiftContext(); var toxicity = new RiftToxicity { UserId = userId, Percent = percent }; context.Entry(toxicity).Property(x => x.Percent).IsModified = true; if (percent > oldToxicity.Percent) { toxicity.LastIncreased = DateTime.UtcNow; context.Entry(toxicity).Property(x => x.LastIncreased).IsModified = true; } else if (percent < oldToxicity.Percent) { toxicity.LastDecreased = DateTime.UtcNow; context.Entry(toxicity).Property(x => x.LastDecreased).IsModified = true; } await context.SaveChangesAsync(); }
public async Task AddAsync(RiftActiveGiveaway giveaway) { await using var context = new RiftContext(); await context.ActiveGiveaways.AddAsync(giveaway); await context.SaveChangesAsync(); }
static async Task <bool> EnsureExistsAsync(ulong userId) { if (!await DB.Users.EnsureExistsAsync(userId)) { throw new DatabaseException(nameof(EnsureExistsAsync)); } await using var context = new RiftContext(); if (await context.Toxicity .AsQueryable() .AnyAsync(x => x.UserId == userId)) { return(true); } try { var entry = new RiftToxicity { UserId = userId, LastIncreased = DateTime.MinValue, }; await context.Toxicity.AddAsync(entry); await context.SaveChangesAsync(); return(true); } catch (Exception ex) { RiftBot.Log.Error(ex, $"Failed to check {nameof(EnsureExistsAsync)} for user {userId.ToString()}."); return(false); } }
public async Task <int> CountAsync(ulong userId) { await using var context = new RiftContext(); return(await context.RoleInventories .AsQueryable() .CountAsync(x => x.UserId == userId)); }
public async Task <List <RiftPendingUser> > GetAllAsync() { await using var context = new RiftContext(); return(await context.PendingUsers .AsQueryable() .ToListAsync()); }
public async Task <bool> IsPendingAsync(ulong userId) { await using var context = new RiftContext(); return(await context.PendingUsers .AsQueryable() .AnyAsync(x => x.UserId == userId)); }
public async Task <List <RiftEventLog> > GetStartedAsync(Expression <Func <RiftEventLog, bool> > predicate) { await using var context = new RiftContext(); return(await context.EventLogs .Where(predicate) .ToListAsync()); }
static async Task <bool> EnsureExistsAsync(ulong userId) { if (!await DB.Users.EnsureExistsAsync(userId)) { return(false); } await using var context = new RiftContext(); if (await context.Cooldowns .AsQueryable() .AnyAsync(x => x.UserId == userId)) { return(true); } try { var entry = new RiftCooldowns { UserId = userId, }; await context.Cooldowns.AddAsync(entry); await context.SaveChangesAsync(); return(true); } catch (Exception ex) { RiftBot.Log.Error(ex, $"Failed to check {nameof(EnsureExistsAsync)} for user {userId.ToString()}."); return(false); } }
public async Task <RiftEventLog> GetAsync(int id) { await using var context = new RiftContext(); return(await context.EventLogs .AsQueryable() .FirstOrDefaultAsync(x => x.Id == id)); }
public async Task AddAsync(RiftEventLog log) { await using var context = new RiftContext(); await context.EventLogs.AddAsync(log); await context.SaveChangesAsync(); }
public async Task <List <RiftActiveGiveaway> > GetAllAsync() { await using var context = new RiftContext(); return(await context.ActiveGiveaways .AsQueryable() .ToListAsync()); }
public async Task <RiftActiveGiveaway> GetAsync(int id) { await using var context = new RiftContext(); return(await context.ActiveGiveaways .AsQueryable() .FirstOrDefaultAsync(x => x.Id == id)); }
public async Task <bool> HasAsync(ulong userId, int backgroundId) { await using var context = new RiftContext(); return(await context.BackgroundInventories .AsQueryable() .Where(x => x.UserId == userId && x.BackgroundId == backgroundId) .AnyAsync()); }
public async Task <bool> HasAllAsync(ulong userId, params int[] roleIds) { await using var context = new RiftContext(); return(await context.RoleInventories .AsQueryable() .AllAsync(x => x.UserId == userId && roleIds.Contains(x.RoleId))); }
public async Task <List <RiftRoleInventory> > GetAsync(ulong userId) { await using var context = new RiftContext(); return(await context.RoleInventories .AsQueryable() .Where(x => x.UserId == userId) .ToListAsync()); }
public async Task <List <RiftPendingUser> > GetExpiredAsync() { await using var context = new RiftContext(); return(await context.PendingUsers .AsQueryable() .Where(x => x.ExpirationTime > DateTime.UtcNow) .ToListAsync()); }
public async Task <List <RiftActiveGiveaway> > GetLinkedAsync(string giveawayName) { await using var context = new RiftContext(); return(await context.ActiveGiveaways .AsQueryable() .Where(x => x.GiveawayName.Equals(giveawayName)) .ToListAsync()); }