Exemple #1
0
        private static void InsertRom(Game rom)
        {
            using (var iR = new MyDbContext())
            {
                // add game to database and save changes
                iR.Game.Add(rom);
                iR.SaveChanges();
                iR.Dispose();
            }
            List <Game> games = new List <Game>();

            games.Add(rom);
            GamesLibraryVisualHandler.DoGameAdd(games);
        }
Exemple #2
0
        public static void SaveToDatabase(List <Game> games, bool init)
        {
            using (var db = new MyDbContext())
            {
                // get current database context
                var current = db.Game.AsNoTracking().ToList();

                List <Game> toAdd    = new List <Game>();
                List <Game> toUpdate = new List <Game>();

                // iterate through the games list and separete out games to be added and games to be updated
                foreach (var g in games)
                {
                    Game t = (from a in current
                              where a.gameId == g.gameId
                              select a).SingleOrDefault();
                    if (t == null)
                    {
                        toAdd.Add(g);
                    }
                    else
                    {
                        toUpdate.Add(g);
                    }
                }
                db.Game.UpdateRange(toUpdate);
                db.Game.AddRange(toAdd);
                db.SaveChanges();

                App _App = (App)Application.Current;
                if (_App.GamesLibrary == null)
                {
                    return;
                }

                if (toAdd.Count > 0)
                {
                    GamesLibraryVisualHandler.DoGameAdd(toAdd);
                }
                if (toUpdate.Count > 0)
                {
                    GamesLibraryVisualHandler.DoGameUpdate(toUpdate);
                }
            }
        }