예제 #1
0
        public static List <SystemGridRow> GetLastNSystems(Expedition currentExpedition, int numberToReturn = 20)
        {
            List <StarSystem>    starSystems = null;
            List <SystemGridRow> result      = new List <SystemGridRow>();

            using (var db = new EelContext()) {
                starSystems = (from p in db.StarSystems.Include("Expeditions")
                               where p.Expedition.Id == currentExpedition.Id
                               orderby p.CreatedAt descending
                               select p).Take(numberToReturn).ToList();

                foreach (var system in starSystems)
                {
                    int count = (from q in db.SystemObjects
                                 where q.StarSystem.Id == system.Id
                                 select q).Count();

                    var row = new SystemGridRow();
                    row.Date             = system.CreatedAt;
                    row.Distance         = system.DistToNext;
                    row.Name             = system.Name;
                    row.HasSystemObjects = count > 0;
                    row.Id = system.Id;
                    result.Add(row);
                }
            }

            return(result);
        }
예제 #2
0
        public static List <EELData.System> GetAllSystems()
        {
            var systems = new List <EELData.System>();

            using (var db = new EelContext()) {
                systems = (from p in db.Systems
                           select p).ToList();
            }
            return(systems);
        }
예제 #3
0
        public static Settings GetSettings()
        {
            Settings settings = null;

            using (var db = new EelContext()) {
                settings = (from p in db.Settings
                            select p).FirstOrDefault();
            }
            return(settings);
        }
        public static List <Expedition> GetAll()
        {
            var exp = new List <Expedition>();

            using (var db = new EelContext()) {
                exp = (from p in db.Expeditions
                       select p).ToList();
            }
            return(exp);
        }
예제 #5
0
        public static StarSystem GetByStarSystemId(int id)
        {
            StarSystem starSystem = null;

            using (var db = new EelContext()) {
                starSystem = (from p in db.StarSystems.Include("Expedition")
                              where p.Id == id
                              select p).SingleOrDefault();
            }
            return(starSystem);
        }
예제 #6
0
        public static double GetTotalDistance(Expedition expedition)
        {
            double sum = 0;

            using (var db = new EelContext()) {
                sum = (from p in db.StarSystems.Include("Expeditions")
                       where p.Expedition.Id == expedition.Id
                       select p.DistToNext).Sum();
            }
            return(sum);
        }
예제 #7
0
 public static StarSystem InsertStarSystem(StarSystem system)
 {
     if (null == system)
     {
         throw new ArgumentNullException("expedition");
     }
     using (var db = new EelContext()) {
         db.StarSystems.Add(system);
         db.SaveChanges();
     }
     return(system);
 }
예제 #8
0
 public static Settings InsertSettings(Settings settings)
 {
     if (null == settings)
     {
         throw new ArgumentNullException("settings");
     }
     using (var db = new EelContext()) {
         db.Settings.Add(settings);
         db.SaveChanges();
     }
     return(settings);
 }
        public static List <SystemObject> GetByStarSystemId(int starSystemId)
        {
            List <SystemObject> systemObjects = null;

            using (var db = new EelContext()) {
                systemObjects = (from p in db.SystemObjects
                                 where p.StarSystem.Id == starSystemId
                                 select p
                                 ).ToList();
            }
            return(systemObjects);
        }
 public static Expedition InsertExpedition(Expedition expedition)
 {
     if (null == expedition)
     {
         throw new ArgumentNullException("expedition");
     }
     using (var db = new EelContext()) {
         db.Expeditions.Add(expedition);
         db.SaveChanges();
     }
     return(expedition);
 }
예제 #11
0
        private void PopulateObjectTypes()
        {
            using (var db = new EelContext()) {
                var objectTypes = (from p in db.ObjectTypes
                                   orderby p.Order
                                   select p).ToList();

                ObjectTypesList.DataSource    = objectTypes;
                ObjectTypesList.DisplayMember = "Name";
                ObjectTypesList.ValueMember   = "Id";
            }
        }
 public static SystemObject InsertSystemObject(SystemObject systemObject)
 {
     if (null == systemObject)
     {
         throw new ArgumentNullException("systemObject");
     }
     using (var db = new EelContext()) {
         db.SystemObjects.Add(systemObject);
         db.SaveChanges();
     }
     return(systemObject);
 }
예제 #13
0
 public static StarSystem UpdateStarSystem(StarSystem system)
 {
     if (null == system)
     {
         throw new ArgumentNullException("expedition");
     }
     using (var db = new EelContext()) {
         system.UpdatedAt = DateTime.Now;
         db.StarSystems.Attach(system);
         db.Entry(system).State = Microsoft.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(system);
 }
        public static void ClearExpeditionCurrentFlags()
        {
            using (var db = new EelContext()) {
                var exps = (from p in db.Expeditions
                            where p.Current
                            select p);

                foreach (var exp in exps)
                {
                    exp.Current = false;
                }

                db.SaveChanges();
            }
        }
예제 #15
0
        public static bool SystemPreviouslyVisited(string name)
        {
            bool       visited = false;
            StarSystem system  = null;

            using (var db = new EelContext()) {
                system = (from p in db.StarSystems
                          where p.Name.Trim() == name.Trim()
                          select p).FirstOrDefault();

                if (null != system)
                {
                    system.Visits += 1;
                    UpdateStarSystem(system);
                    visited = true;
                }
            }
            return(visited);
        }
예제 #16
0
        public static Settings UpdateSettings(Settings settings)
        {
            if (null == settings)
            {
                throw new ArgumentNullException("expedition");
            }
            using (var db = new EelContext()) {
                if (db.Settings.Count() > 0)
                {
                    db.Settings.Attach(settings);
                    db.Entry(settings).State = Microsoft.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.Settings.Add(settings);
                }

                db.SaveChanges();
            }
            return(settings);
        }
예제 #17
0
 /// <summary>
 /// Initialize the database and seed the ObjectType table
 /// </summary>
 private void InitializeDb()
 {
     using (var db = new EelContext()) {
         db.Database.EnsureCreated();
         var objectTypes = new List <ObjectType> {
             new ObjectType {
                 Order = 1, Name = "Star (F/G/K/M)", LowValue = 2400, HighValue = 6600, MedianValue = 4500
             },
             new ObjectType {
                 Order = 2, Name = "Star (Other)", LowValue = 2400, HighValue = 6600, MedianValue = 4500
             },
             new ObjectType {
                 Order = 3, Name = "Black Hole", LowValue = 38000, HighValue = 50000, MedianValue = 44000
             },
             new ObjectType {
                 Order = 4, Name = "Neutron Star", LowValue = 36000, HighValue = 38000, MedianValue = 37000
             },
             new ObjectType {
                 Order = 5, Name = "White Dwarf", LowValue = 26000, HighValue = 26000, MedianValue = 26000
             },
             new ObjectType {
                 Order = 6, Name = "Wolf-Rayet Star", LowValue = 3000, HighValue = 6600, MedianValue = 4800
             },
             new ObjectType {
                 Order = 7, Name = "Carbon Star", LowValue = 2400, HighValue = 2400, MedianValue = 2400
             },
             new ObjectType {
                 Order = 8, Name = "Proto Star (Ae/Be/T-Tauri)", LowValue = 2400, HighValue = 3000, MedianValue = 2700
             },
             new ObjectType {
                 Order = 9, Name = "Water World ", LowValue = 18000, HighValue = 36000, MedianValue = 27000
             },
             new ObjectType {
                 Order = 10, Name = "Water World Terraformable", LowValue = 27000, HighValue = 65000, MedianValue = 46000
             },
             new ObjectType {
                 Order = 11, Name = "Earth-like", LowValue = 54000, HighValue = 62000, MedianValue = 58000
             },
             new ObjectType {
                 Order = 12, Name = "Ammonia", LowValue = 33000, HighValue = 35000, MedianValue = 34000
             },
             new ObjectType {
                 Order = 13, Name = "Metal-Rich", LowValue = 9000, HighValue = 14000, MedianValue = 11500
             },
             new ObjectType {
                 Order = 14, Name = "High Metal Content", LowValue = 4100, HighValue = 8500, MedianValue = 6300
             },
             new ObjectType {
                 Order = 15, Name = "Terraformable High Metal", LowValue = 30000, HighValue = 45000, MedianValue = 37500
             },
             new ObjectType {
                 Order = 16, Name = "Gas Giant Class I", LowValue = 2200, HighValue = 3800, MedianValue = 3000
             },
             new ObjectType {
                 Order = 17, Name = "Gas Giant Class II", LowValue = 7500, HighValue = 12300, MedianValue = 9900
             },
             new ObjectType {
                 Order = 18, Name = "Gas Giant Class III", LowValue = 2200, HighValue = 3800, MedianValue = 3000
             },
             new ObjectType {
                 Order = 19, Name = "Gas Giant Class IV", LowValue = 2200, HighValue = 3800, MedianValue = 3000
             },
             new ObjectType {
                 Order = 20, Name = "Gas Giant Class V", LowValue = 2200, HighValue = 3800, MedianValue = 3000
             },
             new ObjectType {
                 Order = 21, Name = "Rocky/Icy Planet", LowValue = 600, HighValue = 1200, MedianValue = 900
             },
         };
         for (var i = 0; i < objectTypes.Count; i++)
         {
             db.ObjectTypes.Add(objectTypes[i]);
         }
         //objectTypes.ForEach(p => db.ObjectTypes.Add(p));
         db.SaveChanges();
     }
 }