Esempio n. 1
0
 public static void UpdateRoms(List <DAT_Rom> roms)
 {
     using (var db = new AsniDATAdminDbContext())
     {
         db.DAT_Rom.UpdateRange(roms);
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public static void UpdateGame(DAT_Game game)
 {
     using (var uG = new AsniDATAdminDbContext())
     {
         uG.DAT_Game.Update(game);
         uG.SaveChanges();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Add a single game (without checking for existing)
 /// </summary>
 /// <param name="game"></param>
 public static void AddGame(DAT_Game game)
 {
     using (var db = new AsniDATAdminDbContext())
     {
         db.DAT_Game.Add(game);
         db.SaveChanges();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// return a list with all gamesdb.net platforms
 /// </summary>
 /// <returns></returns>
 public static List <DAT_System> GetSystems()
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_System
                      select g);
         return(cData.ToList());
     }
 }
Esempio n. 5
0
 /// <summary>
 /// return list of all roms
 /// </summary>
 /// <returns></returns>
 public static List <DAT_Rom> GetRoms()
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_Rom
                      select g).AsNoTracking();
         return(cData.ToList());
     }
 }
Esempio n. 6
0
 // <summary>
 /// return a list with all providers
 /// </summary>
 /// <returns></returns>
 public static List <DAT_Provider> GetProviders()
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_Provider
                      select g);
         return(cData.ToList());
     }
 }
Esempio n. 7
0
        public static int[] SaveToDatabase(List <DAT_Rom> roms)
        {
            // get current rom list
            List <DAT_Rom> current = DAT_Rom.GetRoms();

            int added   = 0;
            int updated = 0;

            // create temp objects pre-database actions
            List <DAT_Rom> toAdd    = new List <DAT_Rom>();
            List <DAT_Rom> toUpdate = new List <DAT_Rom>();

            // iterate through each incoming rom
            foreach (var r in roms)
            {
                // attempt rom lookup in current
                DAT_Rom l = (from a in current
                             where a.md5 == r.md5 && a.pid == r.pid
                             select a).ToList().FirstOrDefault();

                if (l == null)
                {
                    // no entry found
                    toAdd.Add(r);
                }
                else
                {
                    // entry found - update required fields
                    DAT_Rom dr = r;
                    dr.gid = l.gid;
                    dr.rid = l.rid;

                    toUpdate.Add(dr);
                }
            }


            using (var db = new AsniDATAdminDbContext())
            {
                // check for duplicate keys
                var distinctToAdd    = toAdd.GroupBy(x => x.rid).Select(g => g.OrderByDescending(x => x.rid).First());
                var distinctToUpdate = toUpdate.GroupBy(x => x.rid).Select(g => g.OrderByDescending(x => x.rid).First());

                // update existing entries
                db.DAT_Rom.UpdateRange(distinctToUpdate);
                // add new entries
                db.DAT_Rom.AddRange(distinctToAdd);

                db.SaveChanges();

                added   = distinctToAdd.Count();
                updated = distinctToUpdate.Count();

                return(new int[] { added, updated });
            }
        }
Esempio n. 8
0
 /// <summary>
 /// return list of all roms based on platform
 /// </summary>
 /// <returns></returns>
 public static List <DAT_Rom> GetRoms(int pid)
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_Rom
                      where g.pid == pid
                      select g);
         return(cData.ToList());
     }
 }
Esempio n. 9
0
 /// <summary>
 /// return rom based on md5 hash
 /// </summary>
 /// <returns></returns>
 public static DAT_Rom GetRom(string md5)
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_Rom
                      where g.md5.ToUpper() == md5.ToUpper()
                      select g);
         return(cData.FirstOrDefault());
     }
 }
Esempio n. 10
0
 /// <summary>
 /// return dat_game based on gid
 /// </summary>
 /// <returns></returns>
 public static DAT_Game GetGame(int gid)
 {
     using (var context = new AsniDATAdminDbContext())
     {
         var cData = (from g in context.DAT_Game
                      where g.gid == gid
                      select g).FirstOrDefault();
         return(cData);
     }
 }
Esempio n. 11
0
        public static int[] SaveToDatabase(List <DAT_Game> games)
        {
            // get current rom list
            List <DAT_Game> current = DAT_Game.GetGames();

            int added   = 0;
            int updated = 0;

            // create temp objects pre-database actions
            List <DAT_Game> toAdd    = new List <DAT_Game>();
            List <DAT_Game> toUpdate = new List <DAT_Game>();

            // iterate through each incoming rom
            foreach (var g in games)
            {
                // attempt rom lookup in current
                DAT_Game l = (from a in current
                              where a.gid == g.gid
                              select a).SingleOrDefault();

                if (l == null)
                {
                    // no entry found
                    toAdd.Add(g);
                }
                else
                {
                    // entry found
                    toUpdate.Add(g);
                }
            }

            using (var db = new AsniDATAdminDbContext())
            {
                // add new entries
                db.DAT_Game.AddRange(toAdd);

                // update existing entries
                db.DAT_Game.UpdateRange(toUpdate);


                db.SaveChanges();

                added   = toAdd.Count();
                updated = toUpdate.Count();

                return(new int[] { added, updated });
            }
        }
Esempio n. 12
0
        /// <summary>
        /// returns the next free GID
        /// </summary>
        /// <returns></returns>
        public static int GetFirstFreeGID()
        {
            using (var db = new AsniDATAdminDbContext())
            {
                int search = (from a in db.DAT_Game
                              select a.gid).ToList().Last();

                if (search == 0)
                {
                    return(0);
                }

                int result = search + 1;
                return(result);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// return dat_game based on gid
        /// </summary>
        /// <returns></returns>
        public static DAT_Game GetGameByMD5(string md5)
        {
            DAT_Rom dr = DAT_Rom.GetRom(md5);

            if (dr == null)
            {
                return(null);
            }

            using (var context = new AsniDATAdminDbContext())
            {
                var cData = (from g in context.DAT_Game
                             where g.gid == dr.gid
                             select g).FirstOrDefault();
                return(cData);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Add a single game (without checking for existing) and return the gid
        /// </summary>
        /// <param name="game"></param>
        public static int AddGameReturnGID(DAT_Game game)
        {
            using (var db = new AsniDATAdminDbContext())
            {
                db.DAT_Game.Add(game);
                db.SaveChanges();
            }

            // get the last entry added
            var uGame = (from a in DAT_Game.GetGames()
                         where a.pid == game.pid
                         select a).LastOrDefault();

            if (uGame == null)
            {
                return(0);
            }

            return(uGame.gid);
        }