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); }
private void PopulateSystemGrid() { if (_currentExpedition == null) { return; } var data = StarSystemServices.GetLastNSystems(_currentExpedition); static_grid.DataSource = data; static_grid.Columns[1].Width = 150; static_grid.Columns[2].Width = 330; static_grid.Columns[3].Width = 68; static_grid.Columns[0].Visible = false; SystemGridRow row = null; if (data.Count < 1) { return; } row = (SystemGridRow)static_grid.Rows[0].DataBoundItem; //_currentStarSystem = StarSystemServices.GetByStarSystemId(row.Id); //RefreshStarSystemControls(); }