public static async Task DeleteWaifu(ulong userId, Waifu waifu, ulong guildId) { using var DbContext = new NamikoDbContext(); var userWaifu = DbContext.UserInventories.Where(x => x.UserId == userId && x.Waifu.Equals(waifu) && x.GuildId == guildId).FirstOrDefault(); if (userWaifu != null) { DbContext.UserInventories.Remove(userWaifu); await DbContext.SaveChangesAsync(); } }
public static async Task SetFeaturedWaifu(ulong userId, Waifu waifu, ulong guildId) { using var dbContext = new NamikoDbContext(); var entry = new FeaturedWaifu { UserId = userId, Waifu = waifu, GuildId = guildId }; dbContext.FeaturedWaifus.RemoveRange(dbContext.FeaturedWaifus.Where(x => x.UserId == userId & x.GuildId == guildId)); dbContext.FeaturedWaifus.Update(entry); await dbContext.SaveChangesAsync(); }
public static async Task CompletelyDeleteWaifu(Waifu waifu) { using var DbContext = new NamikoDbContext(); var userWaifu = DbContext.UserInventories.Where(x => x.Waifu.Equals(waifu)); if (userWaifu == null) { return; } DbContext.UserInventories.RemoveRange(userWaifu); await DbContext.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 <int> DeleteWaifu(string name) { using var DbContext = new NamikoDbContext(); Waifu waifu = DbContext.Waifus.Where(x => x.Name == name).FirstOrDefault(); if (waifu == null) { return(0); } await UserInventoryDb.CompletelyDeleteWaifu(waifu); await WaifuShopDb.CompletelyDeleteWaifu(waifu); DbContext.Waifus.Remove(waifu); return(await DbContext.SaveChangesAsync()); }
public static async Task <List <Waifu> > SearchWaifus(string query, bool primaryName = false, IEnumerable <Waifu> from = null, bool includeMAL = false, int perPage = 0, int page = 0) { using var DbContext = new NamikoDbContext(); List <Waifu> waifus = new List <Waifu>(); var waifuQuery = from == null ? DbContext.Waifus : from.AsQueryable(); if (includeMAL) { waifuQuery.Include(x => x.Mal); } if (primaryName) { Waifu waifu = waifuQuery.Where(x => x.Name.ToUpper().Equals(query.ToUpper())).FirstOrDefault(); if (waifu != null) { waifus.Add(waifu); return(waifus); } } var words = query.Split(' '); foreach (var word in words) { waifuQuery = waifuQuery.Where(x => x.Name.ToUpper().Contains(word.ToUpper()) || (x.LongName == null ? false : x.LongName.ToUpper().Contains(word.ToUpper())) || (x.Source == null ? false : x.Source.ToUpper().Contains(word.ToUpper()))); } if (perPage > 0) { waifuQuery = waifuQuery.Skip(perPage * page).Take(perPage); } waifus = from == null ? await waifuQuery.ToListAsync() : waifuQuery.ToList(); return(waifus); }
public static async Task AddWaifuWish(ulong userId, Waifu waifu, ulong guildId) { using var db = new NamikoDbContext(); var entry = new WaifuWish { UserId = userId, Waifu = waifu, GuildId = guildId }; int cap = 5; if (PremiumDb.IsPremium(userId, ProType.ProPlus)) { cap = 12; } db.WaifuWishlist.Update(entry); if (db.WaifuWishlist.Where(x => x.UserId == userId && x.GuildId == guildId).Count() >= cap) { db.WaifuWishlist.Remove(db.WaifuWishlist.Where(x => x.UserId == userId && x.GuildId == guildId).First()); } await db.SaveChangesAsync(); }
public static async Task <int> UpdateWaifu(Waifu waifu) { using var DbContext = new NamikoDbContext(); DbContext.Update(waifu); return(await DbContext.SaveChangesAsync()); }
public static bool OwnsWaifu(ulong userId, Waifu waifu, ulong guildId) { using var db = new NamikoDbContext(); return(db.UserInventories.Any(x => x.Waifu == waifu && x.UserId == userId && x.GuildId == guildId)); }
public static List <ulong> GetOwners(Waifu waifu, ulong guildId) { using var db = new NamikoDbContext(); return(db.UserInventories.Where(x => x.Waifu.Equals(waifu) && x.GuildId == guildId).Select(x => x.UserId).ToList()); }