Esempio n. 1
0
        public static void ShowAvailableShip(DatabasePerson currentPerson, List <DatabaseStarship> unpayedShips)
        {
            //Program.SelectMenu();
            bool loop = true;
            int  selector;

            Console.WriteLine($"{currentPerson.Name} \n" +
                              $"Current credits {currentPerson.Credits}\n" +
                              $"Avaible ships to checkout: ");
            for (int i = 0; i <= (unpayedShips.Count - 1); i++)
            {
                Console.WriteLine($"[{i}] {unpayedShips[i].ShipName} Price: {unpayedShips[i].NumberOfDays * unpayedShips[i].PricePerDay}");
            }

            while (loop)
            {
                Console.WriteLine("Please select a ship to checkout:  ");
                try
                {
                    selector = int.Parse(Console.ReadLine());
                    Console.WriteLine($"you have selected: {unpayedShips[selector].ShipName}");
                    CheckOutShip(currentPerson, (currentPerson.Startships.Where(s => s.ShipID ==
                                                                                unpayedShips[selector].ShipID).FirstOrDefault()));
                    loop = false;
                }
                catch
                {
                    Console.WriteLine("Invalid input");
                }
            }
        }
        public static void AddMoreFunds(DatabasePerson person)
        {
            Console.WriteLine($"You have {person.Credits} in credits");


            bool loop = true;

            while (loop)
            {
                try
                {
                    Console.WriteLine("Please add credits to your card (Minimum 1000 credits): ");
                    int inputCreadits = int.Parse(Console.ReadLine());
                    if (inputCreadits >= 1000)
                    {
                        MyContext myContext = new MyContext();
                        person.Credits = inputCreadits + person.Credits;
                        myContext.Entry(myContext.Persons.FirstOrDefault(p => p.PersonID == person.PersonID)).CurrentValues.SetValues(person);
                        myContext.SaveChanges();
                        loop = false;
                    }
                }
                catch
                {
                    Console.WriteLine("Error, please add credits to your card (Minimum 1000 credits): ");
                }
            }
        }
Esempio n. 3
0
        public static void ControlPersonInDatabase(string personName)
        {
            personLogIn = context.Persons.Include(p => p.Startships).Where(p => p.Name == personName).FirstOrDefault();

            if (personLogIn != null)
            {
                MainMenu.Menu(personLogIn);
            }
            else
            {
                var newCustomer = new CreateNewCustomer().AddNameToPerson(personName).AddFunds().UpdateDatabase();
                personLogIn = context.Persons.Include(p => p.Startships).Where(p => p.Name == personName).FirstOrDefault();
                MainMenu.Menu(personLogIn);
            }
        }
Esempio n. 4
0
        public static void CheckingForShips(DatabasePerson currentPerson)
        {
            var unpayedShips = context.Spaceships.Where(s => s.Person == currentPerson && s.Payed == false).ToList();


            if (unpayedShips.Count > 0)
            {
                ShowAvailableShip(currentPerson, unpayedShips);
            }
            else
            {
                Console.WriteLine($"No ships available for {currentPerson.Name}, press any key to go back to main menu");
                Console.ReadKey();
            }
        }
Esempio n. 5
0
        public static void Menu(DatabasePerson person)
        {
            bool menu = true;

            while (menu)
            {
                Console.Clear();

                Welcome();
                Console.WriteLine($"Welcome {person.Name}\nCredits: {person.Credits}");

                Console.WriteLine("---- Main Menu -----");
                Console.WriteLine("[0] Dock your ship");
                Console.WriteLine("[1] Checkout ship");
                Console.WriteLine("[2] Profile page");
                Console.WriteLine("[3] Add more Funds");
                Console.WriteLine("[4] Exit");

                string option = Console.ReadLine();

                Console.Clear();
                Welcome();
                switch (option)
                {
                case "0":

                    MenuDockShip.ControlParkingspace(person);
                    break;

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

                case "2":
                    MenuProfilePage.Profile(person);
                    break;

                case "3":
                    MenuAddCredits.AddMoreFunds(person);
                    break;

                case "4":
                    Console.WriteLine("Exit program");
                    menu = false;
                    break;
                }
            }
        }
Esempio n. 6
0
        public static void ControlParkingspace(DatabasePerson person)
        {
            //Program.SelectMenu();
            MyContext myContext      = new MyContext();
            var       availableSlots = myContext.Spaceships.Where(p => p.Payed == false).ToList();

            if (availableSlots.Count < 20)
            {
                Console.WriteLine($"{(20 - availableSlots.Count)} docking spots available");
                var addNewShip = new CreateShip(person).StarshipControl().Charge().UpdateDatabase();
            }
            else
            {
                Console.WriteLine("No docking spots are available for the moment, please come back later!");
                Console.ReadKey();
            }
        }
Esempio n. 7
0
        public static void CheckOutShip(DatabasePerson person, DatabaseStarship shipToCheckout)
        {
            int totalsum = shipToCheckout.NumberOfDays * shipToCheckout.PricePerDay;

            if (totalsum <= person.Credits)
            {
                shipToCheckout.Payed = true;
                person.Credits       = person.Credits - totalsum;
                using (var myContext = new MyContext())
                {
                    myContext.Entry(myContext.Spaceships.FirstOrDefault(s => s.ShipID == shipToCheckout.ShipID)).CurrentValues.SetValues(shipToCheckout);
                    myContext.Entry(myContext.Persons.FirstOrDefault(p => p.PersonID == person.PersonID)).CurrentValues.SetValues(person);
                    myContext.SaveChanges();
                }
                Console.WriteLine($"The check out for {shipToCheckout.ShipName} succeded, {totalsum} have been withdrawn from your card\n" +
                                  $"your current amount of credits: {person.Credits}");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine($"Not enough credits on your card {person.Name}, please add more funds");
                Console.ReadKey();
            }
        }
 public CreateShip(DatabasePerson person)
 {
     this.createPerson = person;
 }