Beispiel #1
0
 public static void GetAll(ORM orm)
 {
     Console.WriteLine();
     foreach (var car in orm.GetAllCars())
     {
         Console.WriteLine("{0}\t{1}\t{2}\t{3}", car.Id, car.Brand, car.Number, car.Year);
     }
 }
Beispiel #2
0
        public static void Update(ORM orm)
        {
            bool checkUpdate = true;

            while (checkUpdate == true)
            {
                Console.Write("\nEnter the id you want to update: ");
                int id = Convert.ToInt32(Console.ReadLine());
                if (id == 0)
                {
                    checkUpdate = false;
                }
                var car = orm.GetAllCars().Where(x => x.Id == id).FirstOrDefault();

                Console.WriteLine("\nChoose the column you want to change:\n" + "1.Brand\n" + "2.Number\n" + "3.Year\n" + "<-Back\n");
                Console.Write(">>");
                string choiceUpdate = Console.ReadLine();
                try
                {
                    switch (choiceUpdate)
                    {
                    case "Brand":
                        Console.Write("\nUpdate Brand: ");
                        string br = Console.ReadLine();

                        orm.Update(new Cars
                        {
                            Id     = car.Id,
                            Brand  = br,
                            Number = car.Number,
                            Year   = car.Year
                        });
                        break;

                    case "Number":
                        Console.Write("\nUpdate Number: ");
                        string n = Console.ReadLine();

                        orm.Update(new Cars
                        {
                            Id     = car.Id,
                            Brand  = car.Brand,
                            Number = n,
                            Year   = car.Year
                        });
                        break;

                    case "Year":
                        Console.Write("\nUpdate Year: ");
                        var year = Convert.ToDateTime(Console.ReadLine());

                        orm.Update(new Cars
                        {
                            Id     = car.Id,
                            Brand  = car.Brand,
                            Number = car.Number,
                            Year   = year
                        });
                        break;

                    case "Back":
                        checkUpdate = false;
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }