public static async Task SetHex(Color color, ulong UserId) { using var DbContext = new NamikoDbContext(); var profile = DbContext.Profiles.Where(x => x.UserId == UserId).FirstOrDefault(); //checking hex validity (makes sure hex colour.len ALWAYS = 6) string colour = color.Name; int boundary = colour.Length; if (boundary < 6) { colour = new string('0', 6 - boundary) + colour; } //if this user has not set a custom colour if (profile == null) { DbContext.Add(new Profile { UserId = UserId, ColorHex = colour }); await DbContext.SaveChangesAsync(); return; } //setting profile values + updating stack profile.PriorColorHexStack = PushStackManagement(profile.ColorHex, profile.PriorColorHexStack); profile.ColorHex = colour; DbContext.Update(profile); await DbContext.SaveChangesAsync(); }
public static async Task EndBanroulette(int banrouletteId) { using var db = new NamikoDbContext(); var br = db.Banroulettes.FirstOrDefault(x => x.Id == banrouletteId); if (br == null) { return; } br.Active = false; db.Update(br); await db.SaveChangesAsync(); }
public static async Task <int> AddWaifu(ulong userId, Waifu waifu, ulong guildId) { using var DbContext = new NamikoDbContext(); var inv = new UserInventory { UserId = userId, Waifu = waifu, GuildId = guildId, DateBought = DateTime.Now }; DbContext.Update(inv); int res = await DbContext.SaveChangesAsync(); await WaifuWishlistDb.DeleteWaifuWish(userId, waifu, guildId); return(res); }
public static async Task UpdateServer(Server server) { using var db = new NamikoDbContext(); if (!db.Servers.Any(x => x.GuildId == server.GuildId)) { db.Add(server); } else { db.Update(server); } await db.SaveChangesAsync(); }
public static async Task UpdateBlacklistedChannel(BlacklistedChannel ch) { using NamikoDbContext db = new NamikoDbContext(); var res = db.BlacklistedChannels.Where(x => x.ChannelId == ch.ChannelId).FirstOrDefault(); if (res == null) { db.Add(ch); } else { db.Update(ch); } BlacklistedChannelIds.Add(ch.ChannelId); await db.SaveChangesAsync(); }
public static async Task SetToasties(ulong UserId, int Amount, ulong GuildId) { using var DbContext = new NamikoDbContext(); var toasties = DbContext.Toasties.FirstOrDefault(x => x.UserId == UserId && x.GuildId == GuildId); if (toasties == null) { DbContext.Add(new Balance { UserId = UserId, Amount = Amount, GuildId = GuildId }); } else { toasties.Amount = Amount; DbContext.Update(toasties); } await DbContext.SaveChangesAsync(); }
public static async Task <bool> AddParticipant(ulong userId, Banroulette banroulette) { using var db = new NamikoDbContext(); if (db.BanrouletteParticipants.Count(x => x.UserId == userId && x.Banroulette.Id == banroulette.Id) > 0) { return(false); } db.Update(new BanrouletteParticipant { Banroulette = banroulette, UserId = userId }); if (await db.SaveChangesAsync() > 0) { return(true); } return(false); }
public static async Task AddPost(string permalink, int upvotes) { using var db = new NamikoDbContext(); var post = db.RedditPosts.FirstOrDefault(x => x.PermaLink == permalink); if (post == null) { db.RedditPosts.Add(new RedditPost() { PermaLink = permalink, Upvotes = upvotes }); } else { post.Upvotes = upvotes; db.Update(post); } await db.SaveChangesAsync(); }
public static async Task HexDefault(ulong UserId) { using var DbContext = new NamikoDbContext(); var profile = DbContext.Profiles.Where(x => x.UserId == UserId).FirstOrDefault(); //if this user is not in the database if (profile == null) { DbContext.Add(new Profile { UserId = UserId }); await DbContext.SaveChangesAsync(); return; } //updating profile + stack change profile.PriorColorHexStack = PushStackManagement(profile.ColorHex, profile.PriorColorHexStack); profile.ColorHex = ""; DbContext.Update(profile); await DbContext.SaveChangesAsync(); }
public static async Task SetDaily(Daily Daily) { using var DbContext = new NamikoDbContext(); DbContext.Update(Daily); await DbContext.SaveChangesAsync(); }
public static async Task <int> UpdateWaifu(Waifu waifu) { using var DbContext = new NamikoDbContext(); DbContext.Update(waifu); return(await DbContext.SaveChangesAsync()); }
public static async Task UpdateBanroulette(Banroulette banroulette) { using var db = new NamikoDbContext(); db.Update(banroulette); await db.SaveChangesAsync(); }
public static async Task SetWeekly(Weekly weekly) { using var db = new NamikoDbContext(); db.Update(weekly); await db.SaveChangesAsync(); }