public static async Task <List <Spaceship> > GetSpaceShipsAsync()
        {
            SpaceParkContext context    = new SpaceParkContext();
            List <Spaceship> spaceships = new List <Spaceship>();
            var ids = context.Spaceship.Select(s => s.SpaceshipID).ToList();

            for (int i = 0; i < ids.Count; i++)
            {
                SpaceshipModel model = await SpaceshipModel.CreateModelFromDb(ids[i]);

                Spaceship spaceship = model.CreateObjectFromModel();
                spaceships.Add(spaceship);
            }
            return(spaceships);
        }
Example #2
0
        //Methods
        public static async Task <ParkingSpaceModel> CreateModelFromDb(int id)
        {
            ParkingSpaceModel parkingSpace = null;

            using (var context = new SpaceParkContext())
            {
                parkingSpace = await context.Parkingspace.FindAsync(id);

                if (parkingSpace.SpaceshipID.HasValue)
                {
                    parkingSpace.Spaceship = SpaceshipModel.CreateModelFromDb(parkingSpace.SpaceshipID.Value).Result;
                }
            }

            return(parkingSpace);
        }