Ejemplo n.º 1
0
        public static void SaveToDatabase(ConfigServerSettings Config)
        {
            using (var db = new MyDbContext())
            {
                // get current database context
                var current = db.ConfigServerSettings.AsNoTracking().ToList();

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

                // iterate through the games list and separete out games to be added and games to be updated

                ConfigServerSettings t = (from a in current
                                          where a.ConfigServerId == Config.ConfigServerId
                                          select a).SingleOrDefault();
                if (t == null)
                {
                    toAdd.Add(Config);
                }
                else
                {
                    toUpdate.Add(Config);
                }

                db.ConfigServerSettings.UpdateRange(toUpdate);
                db.ConfigServerSettings.AddRange(toAdd);
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 private static void SetCustomServer(ConfigServerSettings srv)
 {
     using (var context = new MyDbContext())
     {
         context.ConfigServerSettings.Attach(srv);
         var entry = context.Entry(srv);
         entry.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public static void DeleteServer(int id)
        {
            using (var cont = new MyDbContext())
            {
                // get the record
                ConfigServerSettings c = (from a in cont.ConfigServerSettings
                                          where a.ConfigServerId == id
                                          select a).FirstOrDefault();

                if (c == null)
                {
                    return;
                }

                cont.ConfigServerSettings.Remove(c);
                cont.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public static void SaveCustomServerSettings(TextBox tbServerDesc, TextBox tbHostname, Slider slServerPort, TextBox tbPassword, TextBox tbGameKey)
        {
            ConfigServerSettings sSet = new ConfigServerSettings();
            var servers = GetServers();

            sSet = (from s in servers
                    where s.ConfigServerId == 100
                    select s).SingleOrDefault();

            sSet.ConfigServerId    = 100;
            sSet.ConfigServerDesc  = tbServerDesc.Text;
            sSet.netplay__host     = tbHostname.Text;
            sSet.netplay__password = tbPassword.Text;
            sSet.netplay__gamekey  = tbGameKey.Text;
            sSet.netplay__port     = Convert.ToInt32(slServerPort.Value);

            SetCustomServer(sSet);
        }