public ParkingService(int parkingSpaces)
 {
     this.apiDataFetch  = new ApiDataFetch();
     this.parkingSpaces = ParkingSpace.GetParkingSpaceAsync(parkingSpaces).Result.ToArray();
     if (ParkingSpace.GetParkingSpaceAsync(parkingSpaces).Result.ToArray().Count() < 1)
     {
         for (int i = 0; i < this.parkingSpaces.Length; i++)
         {
             this.parkingSpaces[i] = new ParkingSpace();
         }
     }
 }
Пример #2
0
        public ParkingSpace CreateObjectFromModel()
        {
            ParkingSpace temp = new ParkingSpace();

            temp.SetID(this.ParkingSpaceID);

            if (this.Spaceship != null)
            {
                temp.OccupyingSpaceship = this.Spaceship.CreateObjectFromModel();
            }

            return(temp);
        }
        public static async Task <List <ParkingSpace> > GetParkingSpaceAsync()
        {
            SpaceParkContext    context       = new SpaceParkContext();
            List <ParkingSpace> parkingSpaces = new List <ParkingSpace>();
            var ids = context.Person.Select(s => s.PersonID).ToList();

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

                ParkingSpace parkingspace = model.CreateObjectFromModel();
                parkingSpaces.Add(parkingspace);
            }
            return(parkingSpaces);
        }
        public static async Task <ParkingSpace[]> GetParkingSpaceAsync(int count)
        {
            SpaceParkContext context = new SpaceParkContext();

            ParkingSpace[] parkingSpaces = new ParkingSpace[count];
            var            ids           = context.Parkingspace.Select(s => s.ParkingSpaceID).ToList();

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

                ParkingSpace parkingspace = model.CreateObjectFromModel();
                parkingSpaces[i] = parkingspace;
            }
            return(parkingSpaces);
        }
        public bool DepartSpaceShip(Spaceship spaceship, Person person)
        {
            using (var context = new SpaceParkContext())
            {
                ParkingSpace parkingSpace = parkingSpaces.Where(p => p.OccupyingSpaceship.SpaceshipID == spaceship.SpaceshipID).First();
                parkingSpace.OccupyingSpaceship = null;
                var parkSpace = context.Parkingspace.Where(p => p.ParkingSpaceID == parkingSpace.ParkingSpaceID).First();
                parkSpace.Spaceship   = null;
                parkSpace.SpaceshipID = null;

                context.SaveChanges();
                Spaceship.DeleteSpaceshipFromDb(spaceship);
                //Person.DeletePersonFromDb(person);
                return(true);
            }
        }
        public void ParkSpaceship(Person person, Spaceship spaceship)
        {
            if (parkingSpaces.Length < 1)
            {
                return;
            }

            Person.AddPersonToDb(person);

            using (var context = new SpaceParkContext())
            {
                ParkingSpace parkingSpace = parkingSpaces.Where(p => p.OccupyingSpaceship == null).FirstOrDefault();
                parkingSpace.OccupyingSpaceship = spaceship;
                var parkSpace = context.Parkingspace.Where(p => p.ParkingSpaceID == parkingSpace.ParkingSpaceID).First();
                var s         = context.Spaceship.Where(s => s.SpaceshipID == spaceship.SpaceshipID).First();
                var p         = context.Person.Where(p => p.Name == person.Name).First();
                p.Spaceship         = s;
                parkSpace.Spaceship = s;

                context.SaveChanges();
            }
        }