Ejemplo n.º 1
0
        public static void ShowAvailableShip(DatabasePerson person, MyContext context)
        {
            bool loop = true;
            int  selector;

            Console.WriteLine($"{person.Name} \n" +
                              $"Current credits {person.Credits}\n" +
                              $"Avaible ships to checkout: ");
            for (int i = 0; i <= (person.Startships.Count - 1); i++)
            {
                if (person.Startships[i].Payed == false)
                {
                    Console.WriteLine($"[{i}] {person.Startships[i].ShipName}");
                }
            }
            while (loop)
            {
                Console.WriteLine("Please select a ship to checkout:  ");
                ConsoleKeyInfo userInput = Console.ReadKey();
                if (char.IsDigit(userInput.KeyChar))
                {
                    selector = int.Parse(userInput.KeyChar.ToString());
                    Console.WriteLine($"you have selected: {person.Startships[selector].ShipName}");
                    CheckOutShip(person.Startships[selector], person, context);
                    loop = false;
                }
                else
                {
                    Console.WriteLine("Invalid input");
                }
            }
        }
Ejemplo n.º 2
0
        public static void ControlParkingspace(DatabasePerson person)
        {
            MyContext myContext      = new MyContext();
            var       availableSlots = myContext.Spaceships.Where(p => p.Payed == false).ToList();

            if (availableSlots.Count < 20)
            {
                Console.WriteLine($"There is { (20 - availableSlots.Count)}");
                var addNewShip = new CreateShip(person).StarshipControl().Charge().UpdateDatabase();
            }
            else
            {
                Console.WriteLine("No parkingslots are available for the moment, please come back later!");
            }
        }
Ejemplo n.º 3
0
        public static void History(DatabasePerson name)
        {
            Console.WriteLine("This is your History");

            List <DatabasePerson> list = new List <DatabasePerson>();

            List <DatabasePerson> newList = list.Where(p => p.PersonID == name.PersonID && p.Startships.Any(u => u.Payed == false)).ToList();

            var checkPerson = context.Persons.Where(p => p.PersonID == name.PersonID).ToList();
            var checkShip   = context.Spaceships.Where(p => p.Payed == true && p.Person == checkPerson[0]).ToList();

            for (int i = 0; i < checkShip.Count; i++)
            {
                Console.WriteLine($"[{i}] {checkShip[i].ShipName}");
            }
        }
Ejemplo n.º 4
0
        public static void Menu(DatabasePerson person)
        {
            bool menu = true;

            while (menu)
            {
                Console.WriteLine("Welcom to the Spaceport, you have to be in starwars movie to park here \n");
                Console.WriteLine("plz enter you name to identify your self \n");

                Console.WriteLine("[0] Dock your ship");
                Console.WriteLine("[1] Checkout ship");
                Console.WriteLine("[2] Docking history");
                Console.WriteLine("[3] Exit");

                string option = Console.ReadLine();

                Console.Clear();

                switch (option)
                {
                case "0":
                    Program.ControlParkingspace(person);
                    break;

                case "1":
                    MenuCheckOutStarship.CheckingForShips(person);
                    break;

                case "2":
                    MenuCheckOutStarship.History(person);
                    break;

                case "3":
                    MenuCheckOutStarship.History(person);
                    break;

                case "4":
                    Console.WriteLine("Exit program");
                    Console.ReadKey();
                    menu = false;
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public static void CheckOutShip(DatabaseStarship shipToRemove, DatabasePerson person, MyContext myContext)
        {
            int totalsum = shipToRemove.NumberOfDays * shipToRemove.PricePerDay;

            if (totalsum <= person.Credits)
            {
                shipToRemove.Payed = true;
                person.Credits     = person.Credits - totalsum;
                myContext.Entry(myContext.Spaceships.FirstOrDefault(s => s.ShipID == shipToRemove.ShipID)).CurrentValues.SetValues(shipToRemove);
                myContext.Entry(myContext.Persons.FirstOrDefault(p => p.PersonID == person.PersonID)).CurrentValues.SetValues(person);
                myContext.SaveChanges();

                Console.WriteLine($"The check out for {shipToRemove.ShipName} succeded, {totalsum} have been withdrawn from your card\n" +
                                  $"your current amount of credits: {person.Credits}");
            }
            else
            {
                Console.WriteLine($"Not enough credits on your card {person.Name}");
            }
        }
Ejemplo n.º 6
0
        public static void CheckingForShips(DatabasePerson name)
        {
            //var personCheck = context.Persons.Include(p => p.Startships).Where(p => p.PersonID == name.PersonID).FirstOrDefault();
            //var a = context.Spaceships.Where(p => p.Payed == false);

            //var personCheck = context.Persons.Where(p => p.PersonID == name.PersonID).ToList();
            //var shipCheck = context.Spaceships.Where(p => p.Payed == false && p.Person == personCheck[0]).ToList();

            //List<DatabasePerson> list = new List<DatabasePerson>();
            //List<DatabasePerson> newList = list.Where(p => p.PersonID == name.PersonID && p.Startships.Any(u => u.Payed == false)).ToList();

            var test = context.Persons.Where(p => p.PersonID == name.PersonID).Select(m => new DatabasePerson {
                PersonID = m.PersonID, Name = m.Name, Credits = m.Credits, Startships = m.Startships.Where(s => s.Payed == false).ToList()
            }).FirstOrDefault();

            if (test.Startships.Count > 0)
            {
                ShowAvailableShip(test, context);
            }
            else
            {
                Console.WriteLine($"No ships available for {name.Name}");
            }
        }
Ejemplo n.º 7
0
 public CreateShip(DatabasePerson person)
 {
     this.createPerson = person;
 }