public static async Task AddItemToUser(long userId, WheelUserItem item, DiscordContext context = null) { bool dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } if (await context.WheelUserItem.AnyAsync(cItem => cItem.UserId == userId && cItem.ItemId == item.Id)) { return; } var userItem = new WheelUserItem() { UserId = userId, ItemId = item.Id }; context.WheelUserItem.Add(userItem); if (dispose) { context.Dispose(); } await context.SaveChangesAsync(); }
public static async Task <WheelOutcome> GetLastOutcome(UserSetting.Outcome type, long userId, bool?isUserReport = null, DiscordContext context = null) { var dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } WheelOutcome outcome; if (isUserReport != null) { outcome = await context.WheelOutcome.OrderByDescending(outcome => outcome.Time) .FirstOrDefaultAsync(outcome => outcome.UserId == userId && outcome.IsUserReport == (isUserReport.Value == false ? 0 : 1) && type.HasFlag((UserSetting.Outcome)outcome.Type)); } else { outcome = await context.WheelOutcome.OrderByDescending(outcome => outcome.Time) .FirstOrDefaultAsync(outcome => outcome.UserId == userId && type.HasFlag((UserSetting.Outcome)outcome.Type)); } if (dispose) { context.Dispose(); } return(outcome); }
public static async Task <IEnumerable <WheelOutcome> > GetLastOutcomesUntil(WheelOutcome lastOutcome, DiscordContext context = null) { if (context == null) { context = new DiscordContext(); } return(await context.WheelOutcome.Where(outcome => outcome.UserId == lastOutcome.UserId && outcome.Id > lastOutcome.Id).ToListAsync()); }
public static async Task <IEnumerable <WheelUserItem> > GetUserItemsAsync(long userId, DiscordContext context = null) { if (context == null) { context = new DiscordContext(); } var items = context.WheelUserItem.Where(item => item.UserId == userId); return(await items.ToListAsync()); }
public static async Task <Users> GetUser(long userId, DiscordContext context = null) { if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } var user = await context.Users.FirstOrDefaultAsync(u => u.UserId == userId); if (user == null) { lock (__lockObj) { lock (context) { if (!context.Users.Any(u => u.UserId == userId)) { user = new Users() { DenialTime = DateTime.Now, BanTime = DateTime.Now, LockTime = DateTime.Now, MuteTime = DateTime.Now, SpecialTime = DateTime.Now, UserId = userId }; context.Users.Add(user); context.SaveChangesAsync().GetAwaiter().GetResult(); } else { user = context.Users.FindAsync(userId).GetAwaiter().GetResult(); } } } } return(user); }
public static async Task <IEnumerable <WheelOutcome> > GetLastOutcomesUntil(WheelOutcome lastOutcome, DiscordContext context = null) { var dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } var outcomes = await context.WheelOutcome.Where(outcome => outcome.UserId == lastOutcome.UserId && outcome.Id > lastOutcome.Id).ToListAsync(); if (dispose) { context.Dispose(); } return(outcomes); }
public static async Task <WheelMode> GetMode(long guildId, DiscordContext context = null) { var dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } WheelSetting wheelSetting = await context.WheelSetting.FindAsync(guildId); if (dispose) { context.Dispose(); } return(wheelSetting == null ? WheelMode.Default : (WheelMode)wheelSetting.Mode); }
public static async Task <IEnumerable <WheelUserItem> > GetUserItemsAsync(long userId, DiscordContext context = null) { var dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } var items = await context.WheelUserItem.Where(item => item.UserId == userId).ToListAsync(); if (dispose) { context.Dispose(); } return(items); }
public static async Task <WheelOutcome> GetLastOutcome(WheelExtension.Outcome type, long userId, bool?isUserReport = null, DiscordContext context = null) { if (context == null) { context = new DiscordContext(); } if (isUserReport != null) { return(context.WheelOutcome.OrderByDescending(outcome => outcome.Time) .First(outcome => outcome.UserId == userId && outcome.IsUserReport == (isUserReport.Value == false ? 0 : 1) && type.HasFlag((WheelExtension.Outcome)outcome.Type))); } else { return(await context.WheelOutcome.OrderByDescending(outcome => outcome.Time) .FirstOrDefaultAsync(outcome => outcome.UserId == userId && type.HasFlag((WheelExtension.Outcome)outcome.Type))); } }
public static async Task <Users> GetUser(long userId, DiscordContext context = null) { if (context == null) { context = new DiscordContext(); } var user = await context.Users.FirstOrDefaultAsync(u => u.UserId == userId); if (user == null) { lock (__lockObj) { lock (context) { if (!context.Users.Any(u => u.UserId == userId)) { user = new Users() { DenialTime = DateTime.Now, BanTime = DateTime.Now, LockTime = DateTime.Now, MuteTime = DateTime.Now, SpecialTime = DateTime.Now, UserId = userId }; context.Users.Add(user); context.SaveChangesAsync().GetAwaiter().GetResult(); } else { user = context.Users.FindAsync(userId).GetAwaiter().GetResult(); } } } } return(user); }
public static async Task AddItemToUser(long userId, WheelUserItem item, DiscordContext context = null) { if (context == null) { context = new DiscordContext(); } if (await context.WheelUserItem.AnyAsync(cItem => cItem.UserId == userId && cItem.ItemId == item.Id)) { return; } var userItem = new WheelUserItem() { UserId = userId, ItemId = item.Id }; context.WheelUserItem.Add(userItem); await context.SaveChangesAsync(); }
public static async Task SetMode(WheelMode newMode, long guildId, DiscordContext context = null, bool save = true) { var dispose = context == null; if (context == null) { #pragma warning disable IDE0068 // Use recommended dispose pattern context = new DiscordContext(); #pragma warning restore IDE0068 // Use recommended dispose pattern } WheelSetting wheelSetting = await context.WheelSetting.FindAsync(guildId); if (wheelSetting == null) { wheelSetting = new WheelSetting() { GuildId = guildId, Mode = (int)newMode }; context.WheelSetting.Add(wheelSetting); } else { wheelSetting.Mode = (int)newMode; } if (save) { await context.SaveChangesAsync(); } if (dispose) { context.Dispose(); } }
public static IQueryable <UserSetting> GetAllSettings(ulong userId, DiscordContext context) { return(GetAllSettings(Convert.ToInt64(userId), context)); }
public static Task SetMode(WheelMode newMode, ulong guildId, DiscordContext context = null, bool save = true) { return(SetMode(newMode, Convert.ToInt64(guildId), context, save)); }
public static Task <WheelMode> GetMode(ulong guildId, DiscordContext context = null) { return(GetMode(Convert.ToInt64(guildId), context)); }
public static async Task RemoveItemFromUser(ulong userId, WheelUserItem item, DiscordContext context = null) { await RemoveItemFromUserAsync(Convert.ToInt64(userId), item, context); }
public static async Task <WheelOutcome> GetLastOutcome(long userId, bool isUserReport, DiscordContext context = null) { return(await GetLastOutcome(UserSetting.Outcome.All, userId, isUserReport, context)); }
public static async Task RemoveItemFromUserAsync(long userId, WheelUserItem item, DiscordContext context = null) { if (!await context.WheelUserItem.AnyAsync(cItem => cItem.UserId == userId && cItem.ItemId == item.Id)) { return; } context.WheelUserItem.Remove(await context.WheelUserItem.SingleAsync(uItem => uItem.ItemId == item.Id && uItem.UserId == userId)); await context.SaveChangesAsync(); }
public static async Task AddItemToUser(ulong userId, WheelUserItem item, DiscordContext context = null) { await AddItemToUser(Convert.ToInt64(userId), item, context); }
public static async Task <IEnumerable <WheelUserItem> > GetUserItemsAsync(ulong userId, DiscordContext context = null) { return(await GetUserItemsAsync(Convert.ToInt64(userId), context)); }
public static async Task <Users> GetUser(ulong userId, DiscordContext context = null) { return(await GetUser(Convert.ToInt64(userId), context)); }
public static IQueryable <UserSetting> GetAllSettings(long userId, DiscordContext context) { return(context.UserSetting.Where(setting => setting.UserId == userId)); }