예제 #1
0
        public static async Task AddAccountItems(List <Item> items, string apiKey)
        {
            using (var db = new UserContextFactory().CreateDbContext()) {
                var user = await GetUser(apiKey);

                if (user == null)
                {
                    return;
                }

                var currentItems = await db.Item.Where(x => x.UserID == user.ID).ToListAsync();

                var newItems = GetDifference(items, currentItems);
                newItems.ForEach(x => x.UserID = user.ID);

                db.RemoveRange(currentItems);
                db.AddRange(newItems);

                await db.SaveChangesAsync();
            }
        }