Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
 public static async Task <int> UpdateWaifu(Waifu waifu)
 {
     using var DbContext = new NamikoDbContext();
     DbContext.Update(waifu);
     return(await DbContext.SaveChangesAsync());
 }
Esempio n. 9
0
 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));
 }
Esempio n. 10
0
 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());
 }