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);
        }
Example #3
0
        public static async Task <SpaceshipModel> CreateModelFromDb(string name)
        {
            SpaceshipModel spaceShip = null;

            using (var context = new SpaceParkContext())
            {
                spaceShip = await context.Spaceship.FirstAsync(s => s.Person == null && s.Name == name);

                if (spaceShip.PersonID.HasValue)
                {
                    spaceShip.Person = PersonModel.CreateModelFromDb(spaceShip.PersonID.Value).Result;
                }
            }

            return(spaceShip);
        }
Example #4
0
        public static async Task <SpaceshipModel> CreateModelFromDb(int id)
        {
            SpaceshipModel spaceShip = null;

            using (var context = new SpaceParkContext())
            {
                spaceShip = await context.Spaceship.FindAsync(id);

                if (spaceShip.PersonID.HasValue)
                {
                    spaceShip.Person = PersonModel.CreateModelFromDb(spaceShip.PersonID.Value).Result;
                }
            }

            return(spaceShip);
        }