Beispiel #1
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();
            }
        }
Beispiel #2
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");
        }
Beispiel #3
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();
            }
        }
Beispiel #4
0
        private static void CreateNewCabinAndCounselour()
        {
            using (CampSleepawayContext context = new CampSleepawayContext())
            {
                string bigfirstname = MenuUtils.AskForString("Vad heter Lägerledaren i förnamn?");
                string biglastname  = MenuUtils.AskForString("Vad heter Lägerledaren i efternamn?");



                string    cabinName = MenuUtils.AskForString("Vad ska kabinen heta?");
                Counselor counselor = new Counselor {
                    FirstName = bigfirstname, LastName = biglastname
                };

                Cabin cabin = new Cabin {
                    Name = cabinName, Counselor = counselor
                };

                context.Cabins.Add(cabin);

                context.SaveChanges();
            }
        }