Ejemplo n.º 1
0
        public static async Task AddItemSellable(List <Item> items, List <ItemListingAggregated> listings)
        {
            using (var db = new DataContextFactory().CreateDbContext()) {
                var existingItems = await db.ItemSellable.Where(x => items.Select(y => y.ID).Contains(x.ItemID)).ToListAsync();

                foreach (var item in items)
                {
                    var isSellable = listings.Any(x => x.ItemID == item.ID);
                    if (existingItems.Any(x => x.ItemID == item.ID))
                    {
                        var existingItem = existingItems.FirstOrDefault(x => x.ItemID == item.ID);
                        db.Attach(existingItem);
                        existingItem.Sellable = isSellable;
                    }
                    else
                    {
                        db.ItemSellable.Add(new ItemSellable {
                            ItemID   = item.ID,
                            Sellable = isSellable
                        });
                    }
                }
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public static async Task RemoveItems(List <Item> items)
        {
            using (var db = new DataContextFactory().CreateDbContext()) {
                var dbItems = await db.Item.Where(x => items.Select(y => y.ID).Contains(x.ID)).ToListAsync();

                db.Item.RemoveRange(dbItems);
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 3
0
        public static async Task AddItems(List <Item> items)
        {
            using (var db = new DataContextFactory().CreateDbContext()) {
                var existingItems = await db.Item.Where(x => items.Select(y => y.ID).Contains(x.ID)).ToListAsync();

                foreach (var item in items)
                {
                    if (db.Item.Any(x => x.ID == item.ID))
                    {
                        db.Item.Remove(existingItems.FirstOrDefault(x => x.ID == item.ID));
                    }

                    db.Item.Add(item);
                }
                await db.SaveChangesAsync();
            }
        }