Esempio n. 1
0
        private static void CheckCampersCouncelour()
        {
            using (CampSleepawayContext context = new CampSleepawayContext())
            {
                //======
                // Ask for Next of kin info
                string bigfirstname = MenuUtils.AskForString("Vad heter målsmannen i förnamn?");
                string biglastname  = MenuUtils.AskForString("Vad heter målsmannen i efternamn?");
                // Query data from next of kin

                NextOfKin nextOfKin = (from nextOfKins in context.NextOfKins
                                       where nextOfKins.FirstName == bigfirstname &&
                                       nextOfKins.LastName == biglastname
                                       select nextOfKins).FirstOrDefault();
                context.Entry(nextOfKin).Collection(c => c.Campers).Load();

                int      campersCount     = nextOfKin.Campers.Count();
                string[] campersFirstName = new string[campersCount];
                string[] campersLastName  = new string[campersCount];
                int[]    camperIds        = new int[campersCount];
                int      i = 0;
                foreach (var campersInQuery in nextOfKin.Campers)
                {
                    campersFirstName[i] = campersInQuery.FirstName;
                    campersLastName[i]  = campersInQuery.LastName;
                    camperIds[i]        = campersInQuery.CamperId;
                    i++;
                }
                // Checks out and prints all the campers of the next of kin.
                int choice = MenuUtils.AlternetivesMenu(0, campersFirstName, "Vilken unge vill du hämta?");

                //var camperQuery = (from camper in context.Campers
                //                   where camper.LastName == campersLastName[choice] &&
                //                   camper.FirstName == campersFirstName[choice]
                //                   select camper.Cabin).ToList();
                string camperFirstName = campersFirstName[choice];
                string camperLastName  = campersLastName[choice];
                int    camperId        = camperIds[choice];
                //======

                string camperName  = MenuUtils.AskForString("Vad heter parveln i förnamn?");
                var    camperQuery = (from camper in context.Campers
                                      where camper.CamperId == camperId
                                      select camper.Cabin).ToList();


                // visa info om valda kabin
                Cabin cabinInfo = camperQuery[0];
                context.Entry(cabinInfo).Reference(c => c.Counselor).Load();
                if (cabinInfo.Counselor != null)
                {
                    Console.WriteLine($"\nGruppledarens namn: {cabinInfo.Counselor.FirstName}");
                }
                else
                {
                    Console.WriteLine("Hittade ingen råggivare till den kamparen");
                }
            }
            MenuUtils.PauseUntilFeedback("Tryck en knapp för att fortsätta");
        }
Esempio n. 2
0
        private static void CheckInCamper()
        {
            using (CampSleepawayContext context = new CampSleepawayContext())
            {
                string bigfirstname = MenuUtils.AskForString("Vad heter målsmannen i förnamn?");
                string biglastname  = MenuUtils.AskForString("Vad heter målsmannen i efternamn?");


                bool          oneMore = true;
                List <Camper> family  = new List <Camper>();
                while (oneMore)
                {
                    string firstname = MenuUtils.AskForString("Vad heter kamparen i förnamn?");
                    string lastname  = MenuUtils.AskForString("Vad heter kamparen i efternamn?");

                    family.Add(new Camper {
                        FirstName = firstname, LastName = lastname
                    });

                    oneMore = MenuUtils.AlternetivesMenu(1, new string[] { "Ja", "Nej" }, "Var det alla?") == 0 ? false : true;
                }

                NextOfKin nextOfKin = new NextOfKin
                {
                    FirstName = bigfirstname,
                    LastName  = biglastname,
                    Campers   = family
                };
                context.NextOfKins.Add(nextOfKin);
                // Let user choose cabin for all campers.
                bool chooseCabin = MenuUtils.AlternetivesMenu(1, new string[] { "Ja, nu på en gång.", "Nej, det kan göras senare." }, "Vill du välja stugor själv?") == 0 ? true : false;
                if (chooseCabin)
                {
                    foreach (var camper in nextOfKin.Campers)
                    {
                        var cabins = (from emptyCabins in context.Cabins
                                      where emptyCabins.Campers.Count <= 3
                                      select emptyCabins).ToList();
                        // Will query for all empty cabins
                        string[] cabinText = new string[cabins.Count()];
                        int      y         = 0;
                        foreach (var cabin in cabins)
                        {
                            context.Entry(cabin).Collection(c => c.Campers).Load();
                            cabinText[y] = String.Format($"{cabin.Name}: {3 - cabin.Campers.Count}");
                        }
                        // Let user choose from cabins, and see remaining spots.

                        int cabinChoice = MenuUtils.AlternetivesMenu(0, cabinText, "välj cabin för " + camper.FirstName + ".");
                        y++;
                        camper.Cabin = cabins[cabinChoice];
                        cabins[cabinChoice].Campers.Add(camper);


                        // Loop until all campers has a cabin.
                    }
                }
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        private static void MoveVehicle()
        {
            DbHandler handler   = new DbHandler();
            string    regNumber = MenuUtils.AskForStringWithoutSpecialChar("Vänligen skriv in reg-numret för fordonet som ska flyttas.").ToUpper();

            string[] freeParkingSpaces  = handler.FetchFreeParkingSpaces();
            int      parkingspaceChoice = MenuUtils.AlternetivesMenu(0, freeParkingSpaces, "Välj en plats att flytta fordonet");
            string   choosenSpot        = freeParkingSpaces[parkingspaceChoice];
            int      spaceMoveFrom      = handler.FetchVehicleSpot(regNumber);
            int      spaceMoveTo        = Convert.ToInt32(choosenSpot);

            bool result = handler.MoveVehicle(regNumber, spaceMoveTo);

            Console.Clear();
            if (result)
            {
                Console.WriteLine("Flytten lyckades!");


                Console.WriteLine($"Flytta fordonet med reg-nummer {regNumber} från plats {spaceMoveFrom} till plats {spaceMoveTo}");
                MenuUtils.PauseUntilFeedback(OrderMessage);
            }
            else
            {
                Console.WriteLine("Något gick fel!");
                MenuUtils.PauseUntilFeedback("Tryck på en knapp för att fortsätta");
            }
        }
Esempio n. 4
0
        private static void CheckIn()
        {
            DbHandler handler       = new DbHandler();
            int       carType       = MenuUtils.AlternetivesMenu(0, new string[] { "Bil", "Mc" }, "Vilken typ av fordon är det?") + 1;
            string    regNumber     = MenuUtils.AskForStringWithoutSpecialChar("Vänligen skriv in reg-numret för fordonet som ska checkas in.").ToUpper();
            string    checkOutOrder = handler.CheckInVehicle(regNumber, carType);

            Console.Clear();
            Console.WriteLine(checkOutOrder);

            MenuUtils.PauseUntilFeedback(OrderMessage);
        }
Esempio n. 5
0
        private void CheckOutFromList()
        {
            DbHandler      handler  = new DbHandler();
            List <Vehicle> vehicles = handler.GetAllVehicles();

            string[] regChoices = new string[vehicles.Count];
            for (int i = 0; i < vehicles.Count; i++)
            {
                regChoices[i] = String.Format($"Regnum: {vehicles[i].RegNum} In time: {vehicles[i].StartTime.ToString()} Parkeringsnummer: {vehicles[i].ParkingNum+1}");
            }

            int choice = MenuUtils.AlternetivesMenu(0, regChoices, "Choose a vehicle to check out.");

            Console.Clear();
            CheckOut(handler, vehicles[choice].RegNum);


            //MenuUtils.PauseUntilFeedback("Tryck på en knapp för att återvända till menyn");
        }
Esempio n. 6
0
        private static void CheckOutCamper()
        {
            using (CampSleepawayContext context = new CampSleepawayContext())
            {
                // Ask for Next of kin info
                string bigfirstname = MenuUtils.AskForString("Vad heter målsmannen i förnamn?");
                string biglastname  = MenuUtils.AskForString("Vad heter målsmannen i efternamn?");
                // Query data from next of kin

                NextOfKin nextOfKin = (from nextOfKins in context.NextOfKins
                                       where nextOfKins.FirstName == bigfirstname &&
                                       nextOfKins.LastName == biglastname
                                       select nextOfKins).FirstOrDefault();
                context.Entry(nextOfKin).Collection(c => c.Campers).Load();

                int      campersCount     = nextOfKin.Campers.Count();
                string[] campersFirstName = new string[campersCount];
                string[] campersLastName  = new string[campersCount];
                int[]    camperIds        = new int[campersCount];
                int      i = 0;
                foreach (var campersInQuery in nextOfKin.Campers)
                {
                    campersFirstName[i] = campersInQuery.FirstName;
                    campersLastName[i]  = campersInQuery.LastName;
                    camperIds[i]        = campersInQuery.CamperId;
                    i++;
                }
                // Checks out and prints all the campers of the next of kin.
                int choice = MenuUtils.AlternetivesMenu(0, campersFirstName, "Vilken unge vill du hämta?");

                //var camperQuery = (from camper in context.Campers
                //                   where camper.LastName == campersLastName[choice] &&
                //                   camper.FirstName == campersFirstName[choice]
                //                   select camper.Cabin).ToList();

                int camperId = camperIds[choice];
                context.Campers.RemoveRange(context.Campers.Where(c => c.CamperId == camperId));
                context.SaveChanges();
            }
        }
Esempio n. 7
0
        public void Menu()
        {
            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;
            bool running = true;

            while (running)
            {
                int choice = MenuUtils.AlternetivesMenu(0,
                                                        new string[] { "Checka in ett fordon", "Checka ut ett fordon", "Checka ut utan kostnad", "Flytta ett fordon", "Sök efter ett fordon", "Se överblicks-karta", "Optimesera alla MC platser", "Visa intäckts-rapport", "Sökbar intäckts-rapport", "Visa fordon som parkerat mer än två dygn", "Checka ut från lista.", "Lista över parkerade fordon.", "Avsluta programmet" },
                                                        "Välkommen till PragueParking!");
                int checkIn = 0, checkOut = 1, checkOutFree = 2, moveVehicle = 3, search = 4, viewParkinglot = 5;
                int optimizeMcSpace = 6, viewEarnings = 7, searchForEarnings = 8, viewLongParkedVehicles = 9, checkOutFromList = 10, listAllVehicles = 11, exit = 12;
                if (choice == checkIn)
                {
                    CheckIn();
                }
                else if (choice == checkOut)
                {
                    CheckOut();
                }
                else if (choice == checkOutFree)
                {
                    CheckOutFree();
                }
                else if (choice == moveVehicle)
                {
                    MoveVehicle();
                }
                else if (choice == search)
                {
                    SearchForVehicle();
                }
                else if (choice == viewParkinglot)
                {
                    ViewParkingLot();
                }
                else if (choice == optimizeMcSpace)
                {
                    OptimizeMcSpace();
                }
                else if (choice == viewEarnings)
                {
                    ViewEarnings();
                }
                else if (choice == searchForEarnings)
                {
                    SearchForEarnings();
                }
                else if (choice == viewLongParkedVehicles)
                {
                    ViewLongParkedVehicles();
                }
                else if (choice == exit)
                {
                    running = false;
                }
                else if (choice == checkOutFromList)
                {
                    CheckOutFromList();
                }
                else if (choice == listAllVehicles)
                {
                    ListAllVehicles();
                }
            }
        }