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); }
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 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(); }
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 <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 <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 AddAsync(RiftEventLog log) { await using var context = new RiftContext(); await context.EventLogs.AddAsync(log); await context.SaveChangesAsync(); }
public async Task AddAsync(RiftProfileBackground background) { await using var context = new RiftContext(); await context.Backgrounds.AddAsync(background); await context.SaveChangesAsync(); }
public async Task AddAsync(RiftReward reward) { await using var context = new RiftContext(); await context.Rewards.AddAsync(reward); await context.SaveChangesAsync(); }
public async Task AddAsync(RiftActiveGiveaway giveaway) { await using var context = new RiftContext(); await context.ActiveGiveaways.AddAsync(giveaway); await context.SaveChangesAsync(); }
public async Task AddAsync(RiftLeagueData data) { await DB.Users.EnsureExistsAsync(data.UserId); await using var context = new RiftContext(); await context.LeagueData.AddAsync(data); await context.SaveChangesAsync(); }
public async Task AddAsync(RiftPendingUser pendingUser) { await DB.Users.EnsureExistsAsync(pendingUser.UserId); await using var context = new RiftContext(); await context.PendingUsers.AddAsync(pendingUser); await context.SaveChangesAsync(); }
public async Task AddRangeAsync(IEnumerable <RiftScheduledEvent> eventList) { await using var context = new RiftContext(); await context.EventSchedule.AddRangeAsync(eventList); var affectedRows = await context.SaveChangesAsync(); RiftBot.Log.Information($"Added {affectedRows.ToString()} event(s) to schedule."); }
public async Task AddAsync(RiftTempRole role) { await DB.Users.EnsureExistsAsync(role.UserId); await using var context = new RiftContext(); await context.TempRoles.AddAsync(role); await context.SaveChangesAsync(); }
public async Task UpdateAsync(RiftRole role) { await using var context = new RiftContext(); var entry = context.Entry(role); entry.Property(x => x.Name).IsModified = true; entry.Property(x => x.RoleId).IsModified = true; await context.SaveChangesAsync(); }
public async Task RemoveAsync(ulong userId) { var lolData = new RiftLeagueData { UserId = userId, }; await using var context = new RiftContext(); context.LeagueData.Remove(lolData); await context.SaveChangesAsync(); }
public async Task RemoveAsync(ulong userId) { await using var context = new RiftContext(); var dbUser = new RiftUser { UserId = userId, }; context.Users.Remove(dbUser); await context.SaveChangesAsync(); }
public async Task RemoveAsync(int id) { var giveaway = new RiftActiveGiveaway { Id = id }; await using var context = new RiftContext(); context.ActiveGiveaways.Remove(giveaway); await context.SaveChangesAsync(); }
public async Task RemoveAsync(int id) { var activeEvent = new RiftActiveEvent { Id = id }; await using var context = new RiftContext(); context.ActiveEvents.Remove(activeEvent); await context.SaveChangesAsync(); }
public async Task DeleteAsync(RiftBackgroundInventory backInv) { await using var context = new RiftContext(); if (await context.BackgroundInventories .AsQueryable() .AnyAsync(x => x.Equals(backInv))) { context.BackgroundInventories.Remove(backInv); await context.SaveChangesAsync(); } }
public async Task RemoveAsync(ulong userId) { await using var context = new RiftContext(); var pendingUser = new RiftPendingUser { UserId = userId }; context.PendingUsers.Remove(pendingUser); await context.SaveChangesAsync(); }
public async Task RemoveAsync(ulong userId, ulong roleId) { var rtr = new RiftTempRole { UserId = userId, RoleId = roleId, }; await using var context = new RiftContext(); context.TempRoles.Remove(rtr); await context.SaveChangesAsync(); }
public async Task SetBackgroundAsync(ulong userId, int backgroundId) { var dbUser = new RiftUser { UserId = userId, ProfileBackground = backgroundId }; await using var context = new RiftContext(); context.Entry(dbUser).Property(x => x.ProfileBackground).IsModified = true; await context.SaveChangesAsync(); }
public async Task AddAsync(IRole role) { await using var context = new RiftContext(); var dbRole = new RiftRole { Name = role.Name, RoleId = role.Id }; await context.Roles.AddAsync(dbRole); await context.SaveChangesAsync(); }
public async Task UpdateAsync(string name, DateTime lastUpdated) { var timer = await GetAsync(name); if (timer is null) { RiftBot.Log.Error($"Timer \"{name}\" does not exist!"); return; } await using var context = new RiftContext(); timer.LastInvoked = lastUpdated; context.Entry(timer).Property(x => x.LastInvoked).IsModified = true; await context.SaveChangesAsync(); }
public async Task AddAsync(ulong userId, int roleId, string source) { var invRole = new RiftRoleInventory { UserId = userId, RoleId = roleId, ObtainedAt = DateTime.UtcNow, ObtainedFrom = source }; await using var context = new RiftContext(); await context.RoleInventories.AddAsync(invRole); await context.SaveChangesAsync(); }
public async Task AddOrUpdateAsync(RiftGiveaway giveaway) { await using var context = new RiftContext(); var dbGiveaway = await GetAsync(giveaway.Name); if (dbGiveaway is null) { await context.Giveaways.AddAsync(giveaway); } else { var entry = context.Entry(giveaway); if (!dbGiveaway.Description.Equals(giveaway.Description)) { entry.Property(x => x.Description).IsModified = true; } if (!dbGiveaway.WinnersAmount.Equals(giveaway.WinnersAmount)) { entry.Property(x => x.WinnersAmount).IsModified = true; } if (!dbGiveaway.RewardId.Equals(giveaway.RewardId)) { entry.Property(x => x.RewardId).IsModified = true; } if (!dbGiveaway.Duration.Equals(giveaway.Duration)) { entry.Property(x => x.Duration).IsModified = true; } if (!dbGiveaway.CreatedAt.Equals(giveaway.CreatedAt)) { entry.Property(x => x.CreatedAt).IsModified = true; } if (!dbGiveaway.CreatedBy.Equals(giveaway.CreatedBy)) { entry.Property(x => x.CreatedBy).IsModified = true; } } await context.SaveChangesAsync(); }
public async Task SetLastRoleStoreTimeAsync(ulong userId, DateTime time) { if (!await EnsureExistsAsync(userId)) { throw new DatabaseException(nameof(SetLastRoleStoreTimeAsync)); } var cd = new RiftCooldowns { UserId = userId, LastRoleStoreTime = time, }; await using var context = new RiftContext(); context.Attach(cd).Property(x => x.LastRoleStoreTime).IsModified = true; await context.SaveChangesAsync(); }
public async Task AddAsync(ulong userId, int backgroundId) { if (!await DB.Users.EnsureExistsAsync(userId)) { throw new DatabaseException(nameof(BackgroundInventory) + nameof(AddAsync)); } var backInv = new RiftBackgroundInventory { UserId = userId, BackgroundId = backgroundId }; await using var context = new RiftContext(); await context.BackgroundInventories.AddAsync(backInv); await context.SaveChangesAsync(); }
public async Task AddAsync(ulong targetId, ulong moderatorId, string action, string reason, DateTime createdAt, TimeSpan duration) { var log = new RiftModerationLog { TargetId = targetId, ModeratorId = moderatorId, Action = action, Reason = reason, CreatedAt = createdAt, Duration = duration }; await using var context = new RiftContext(); await context.AddAsync(log); await context.SaveChangesAsync(); }