示例#1
0
 public static void SavePlatform(PlatformData platform)
 {
     //GetDataBase();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         context.Platform.InsertOnSubmit(platform);
         context.SubmitChanges();
     }
 }
示例#2
0
 public static void AddNewCollection(string collectionName, string icon)
 {
     //GetDataBase();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         Collection collection = new Collection();
         collection.Name = collectionName;
         collection.Icon = icon;
         context.Collection.InsertOnSubmit(collection);
         context.SubmitChanges();
     }
 }
示例#3
0
 public static void GetDataBase(Action<bool> callback)
 {
     bool createdDataBase = false;
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         if (!context.DatabaseExists())
         {
             context.CreateDatabase();
             PopulatePlatforms();
             createdDataBase = true;
         }
     }
     if (callback != null)
     {
         callback(createdDataBase);
     }
 }
示例#4
0
        public static void SaveGameData(GameViewModel update)
        {
            if (update == null)
                return;

            //GetDataBase();
            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<GameData> query = from g in context.Games
                                             where g.ID == update.ID
                                             select g;
                GameData game = query.FirstOrDefault();

                if (game != null)
                {
                    game.Description = update.Description;
                    game.Notes = update.Notes;
                    context.SubmitChanges();
                }

            }
        }
示例#5
0
        internal static void SaveImageToGame(int gameID, byte[] image)
        {
            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<GameData> query = from c in context.Games
                                                   where c.ID == gameID
                                                   select c;

                GameData game = query.FirstOrDefault();
                if (game != null)
                {
                    GameImage gameImage = new GameImage();
                    gameImage.Image = image;
                    gameImage.GameID = game.ID;

                    context.GameImages.InsertOnSubmit(gameImage);
                    context.SubmitChanges();

                    game.GameImages.Add(gameImage);

                    context.SubmitChanges();
                }
            }
        }
示例#6
0
        internal static ObservableCollection<GameData> GetGamesForCollection(int collectionID)
        {
            ObservableCollection<GameData> results = new ObservableCollection<GameData>();

            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<GameCollection> query = from c in context.CollectionManager
                                               where c.CollectionID == collectionID
                                               select c;

                foreach (GameCollection item in query)
                {
                    GameData game = GetGameData(item.GameID.ToString());
                    results.Add(game);
                }
            }
            
            return results;
        }
示例#7
0
        private static bool GameAlreadyInCollection(GameData game, int collectionID)
        {
            bool result = false;

            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<GameCollection> query = from c in context.CollectionManager
                                               where c.CollectionID == collectionID && c.GameID == game.ID
                                               select c;

                result = (query.FirstOrDefault() != null);
            }
            return result;
        }
示例#8
0
        public static void AddGameToCollection(GameData game, int collectionID)
        {
            if (GameAlreadyInCollection(game, collectionID))
            {
                return;
            }

            //GetDataBase();
            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<Collection> query = from c in context.Collection
                                               where c.ID == collectionID
                                               select c;


                Collection collection = query.FirstOrDefault();

                GameData foundGame = GetGameData(game.ID.ToString());

                GameCollection collectionManager = new GameCollection();
                
                collectionManager.GameID = foundGame.ID;
                collectionManager.CollectionID = collection.ID;

                game.GameCollections.Add(collectionManager);
                collection.GameCollections.Add(collectionManager);

                context.CollectionManager.InsertOnSubmit(collectionManager);
                context.SubmitChanges();
            }
        }
示例#9
0
 internal static ObservableCollection<GameData> SearchForGame(string query)
 {
     //GetDataBase();
     List<GameData> gameList = new List<GameData>();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<GameData> selection = from g in context.Games
                                          where g.UK_Name.Contains(query) || g.US_Name.Contains(query)
                                        select g;
         gameList = selection.ToList();
     }
     return new ObservableCollection<GameData>(gameList.OrderBy(x => x.UK_Name));
 }
示例#10
0
 public static Collection GetCollection(string id)
 {
     //GetDataBase();
     Collection collection = new Collection();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<Collection> query = from c in context.Collection
                                        where c.ID.ToString() == id
                                        select c;
         collection = query.FirstOrDefault();
     }
     return collection;
 }
示例#11
0
 public static GameData GetGameData(string gameData)
 {
     //GetDataBase();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<GameData> query = from g in context.Games
                                      where g.ID == int.Parse(gameData)
                                      select g;
         GameData game = query.FirstOrDefault();
         if (game != null)
         {
             List<GameImage> images = GetGameImages(game.ID);
             ProccessImages(game, images);
         }
         return game;
     }
 }
示例#12
0
        public static void UpdatePlatformData(PlatformData platformData)
        {
            //GetDataBase();
            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<PlatformData> query = from p in context.Platform
                                                 where p.ID == platformData.ID
                                                 select p;
                PlatformData platform = query.FirstOrDefault();

                if (platform == null)
                {
                    SavePlatform(platformData);
                    return;
                }

                platform.UK_Name = platformData.UK_Name;
                platform.US_Name = platformData.US_Name;

                context.SubmitChanges();
            }
        }
示例#13
0
 public static ObservableCollection<GameData> GetGamesForPlatform(string currentPlatform)
 {
     //GetDataBase();
     List<GameData> gamesList = new List<GameData>();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<GameData> query = from g in context.Games
                                      where g.Platform.ToLower() == currentPlatform.ToLower()
                                      select g;
         gamesList = query.ToList();
     }
     return new ObservableCollection<GameData>(gamesList);
 }
示例#14
0
 public static ObservableCollection<PlatformData> GetAllPlatforms()
 {
     //GetDataBase();
     List<PlatformData> platformList = new List<PlatformData>();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<PlatformData> query = from p in context.Platform
                                          select p;
         platformList = query.ToList();
     }
     return new ObservableCollection<PlatformData>(platformList);
 }
示例#15
0
 public static PlatformData GetSelectedPlatform(string platformName)
 {
     //GetDataBase();
     PlatformData platformData = new PlatformData();
     using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
     {
         IQueryable<PlatformData> query = from p in context.Platform
                                          where p.UK_Name == platformName || p.US_Name == platformName || p.Abreviation == platformName
                                          select p;
         platformData = query.FirstOrDefault();
     }
     return platformData;
 }
示例#16
0
        private static List<GameImage> GetGameImages(int gameId)
        {
            List<GameImage> result = new List<GameImage>();

            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {

                foreach (GameImage item in context.GameImages)
                {
                    Debug.WriteLine("Game Image game id is "+item.GameID);
                }

                IQueryable<GameImage> query = from g in context.GameImages
                                             where g.GameID == gameId
                                             select g;
                result = query.ToList();
                return result;
            }
        }
示例#17
0
        internal static ObservableCollection<Collection> GetAllCollections()
        {
            //GetDataBase();
            List<Collection> collectionList = new List<Collection>();
            using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
            {
                IQueryable<Collection> query = from c in context.Collection
                                                 select c;
                collectionList = query.ToList();

                foreach (Collection collection in collectionList)
                {
                    foreach (GameCollection gc in collection.GameCollections)
                    {
                        GameData game = GetGameData(gc.GameID.ToString());
                        collection.Games.Add(game);
                    }
                }
            }
            return new ObservableCollection<Collection>(collectionList);
        }
示例#18
0
 private static void SavePlatformData(PlatformList platformList, Exception exception)
 {
     if (exception != null)
     {
         // catch exception here
     }
     else
     {
         if (platformList.Platforms.Count > 0)
         {
             using (GameDataContext context = new GameDataContext(Constants.DBConnectionString))
             {
                 foreach (PlatformData item in platformList.Platforms)
                 {
                     context.Platform.InsertOnSubmit(item);
                 }
                 context.SubmitChanges();
             }
         }
         else
         {
             // have no data
         }
     }
 }
示例#19
0
        private void HandleGameData(GameList gamesList, Exception exception)
        {
            ObservableCollection<GameData> gameDataList = new ObservableCollection<GameData>();
            if (exception == null)
            {
                GameDataContext context = new GameDataContext(Constants.DBConnectionString);
                foreach (GameResponse g in gamesList.Games)
                {
                    GameData game = new GameData(g, this.SelectedPlatform);
                    gameDataList.Add(game);
                    Debug.WriteLine("Adding " + game.UK_Name);
                    context.Games.InsertOnSubmit(game);
                }
                context.SubmitChanges();
            }
#if DEBUG
            PrintOutGameData(gamesList);
#endif
            if (this.CallBack != null)
            {
                CallBack(gameDataList, exception);    
            }
        }