Пример #1
0
        private static void ChangeBoat()
        {
            var boat = new Data.Boat();
            int output = 0;
            var choice = "n";
            ShowBoats();
            Console.WriteLine();
            Console.Write(" Vill du ändra data på någon båt?, j/n: ");
            choice = Console.ReadLine();
            if (choice == "j")
            {
                Console.WriteLine();
                Console.WriteLine("**************** Ändra på data om båt **********************");
                Console.WriteLine();
                Console.WriteLine(" Vilken båt vill du ändra information om? ");
                Console.WriteLine(" Skriv det båt ID som ändringen gäller: ");
                Console.WriteLine();
                using (var DB = new Data.BoatBookingSystemEntities1())
                {

                    if (int.TryParse(Console.ReadLine(), out output))
                    {
                        var currentboat = DB.Boats.Where(x => x.BoatID == output).FirstOrDefault();
                        Console.Write(" Ändra namn på båten, j/n: ");
                        choice = Console.ReadLine();
                        if (choice == "j")
                        {
                            Console.WriteLine();
                            Console.Write(" Ändra namn: ");
                            var boatname = Console.ReadLine();
                            currentboat.Name = boatname;

                            Console.WriteLine();
                            Console.WriteLine(" Ändra kategori till båten, j/n: ");
                            choice = Console.ReadLine();
                            if (choice == "j")
                            {
                                GetCategories();
                                Console.WriteLine();
                                Console.WriteLine(" Ändra categori_id: ");
                                if (int.TryParse(Console.ReadLine(), out output))
                                    currentboat.CatID = output;

                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }

                            }
                            else
                            {
                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }

                            }
                        }
                        else
                        {

                            Console.WriteLine();
                            Console.Write(" Ändra kategori till båten, j/n: ");
                            choice = Console.ReadLine();
                            if (choice == "j")
                            {
                                GetCategories();
                                Console.WriteLine();
                                Console.Write(" Ändra categori_id: ");
                                if (int.TryParse(Console.ReadLine(), out output))
                                {
                                    currentboat.CatID = output;
                                }
                                else
                                {
                                    Console.WriteLine(" Felaktig inmatning categori_id:et har ingen referens ");
                                }
                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    GetPrices();
                                    Console.WriteLine();
                                    Console.Write(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }
                            }
                            else
                            {
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }
                                else
                                {
                                    Console.WriteLine();
                                    Console.WriteLine();
                                    Console.WriteLine(" Återgå till meny - tryck valfri tangent");
                                    Console.ReadKey();
                                    ShowMenu();
                                }
                            }
                        }
                    }
                    try
                    {
                        DB.SaveChanges();
                        ShowBoats();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("The boat could't be saved because of \"{0}\" .", ex.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(" Återgå till meny - tryck valfri tangent");
                Console.ReadKey();
                ShowMenu();

            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
            ShowMenu();

        }
Пример #2
0
        private static void CreateNewBoat()
        {
            var boat = new Data.Boat();
            int output = 0;

            Console.Clear();
            Console.WriteLine("================================");
            Console.WriteLine("Lägg till ny Båt");
            Console.WriteLine("================================");
            Console.WriteLine("Vilket namn skall båten ha? ");
            boat.Name = Console.ReadLine();

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var categories = DB.Categories.ToList();

                foreach (var r in categories)
                {
                    Console.WriteLine("***************************************************************");
                    Console.WriteLine(" ID: " + r.CatID);
                    Console.WriteLine(" Namn: " + r.Name);

                    if (r.Name == "Segelbåt")
                    {
                        if (r.OverSizeFourty == true)
                        {
                            Console.WriteLine(" Över 40 tum.");
                        }
                        else
                        {
                            Console.WriteLine(" mindre än 40 tum.");
                        }
                    }
                    Console.WriteLine();
                }
            }
            GetCategories();
            Console.WriteLine("\r\nVälj Kategori_id: 1, 2, 3 osv.");

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                if (int.TryParse(Console.ReadLine(), out output))
                {
                    boat.CatID = output;
                }
                Console.WriteLine();
                GetPrices();
                Console.WriteLine("\r\nVälj Pris_id: 1, 2, 3 osv.");
                if (int.TryParse(Console.ReadLine(), out output))
                {
                    boat.PriceID = output;
                }
                try
                {
                    DB.Boats.Add(boat);
                    DB.SaveChanges();
                    ShowAllBoats();
                }
                catch (Exception ex)
                {
                    Console.Write("The boat could't be saved because of \"{0}\" .", ex.Message);
                }

            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
        }