Esempio n. 1
0
 public void Add(string nameFirst, string namelast, int license, int phone)
 {
     using (var db = new CarRentalDBContext())
     {
         db.Customers.Add(new Customer()
         {
             first_name   = nameFirst,
             last_name    = namelast,
             DL_Number    = license,
             phone_number = phone,
         });
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public void Add(string model, string make, int year, string colour, int mile)
 {
     using (var db = new CarRentalDBContext())
     {
         var newCar = db.Cars.Add(new Car()
         {
             Make   = make,
             Model  = model,
             Year   = year,
             Colour = colour,
             Milage = mile
         });
         db.SaveChanges();
     }
 }
Esempio n. 3
0
        public void Add()
        {
            using (var db = new CarRentalDBContext())
            {
                db.Customers
                .ToList()
                .ForEach(Customer => Console.WriteLine("Id:" + Customer.Id + "  " + Customer.first_name + " " + Customer.last_name));
                Console.WriteLine("");
                Console.WriteLine("Enter Id of the Customer");
                int customerId    = Convert.ToInt32(Console.ReadLine());
                var foundCustomer = db.Customers.Find(customerId);

                db.Cars
                .ToList()
                .ForEach(Car => Console.WriteLine("Id:" + Car.Id + "  " + Car.Make + " " + Car.Model));
                Console.WriteLine("");
                Console.WriteLine("Enter Id of the Car they wish to Rent");
                int carId    = Convert.ToInt32(Console.ReadLine());
                var foundCar = db.Cars.Find(carId);

                Console.WriteLine("Enter start date DDMMYY");
                var dateOut = Console.ReadLine();
                Console.WriteLine("Enter end date DDMMYY");
                var dateIn = Console.ReadLine();

                db.Rentals.Add(new Rental()
                {
                    CustomerId = customerId,
                    CarId      = carId,
                    StartDate  = DateTime.ParseExact(dateOut, "ddmmyy", null),
                    EndDate    = DateTime.ParseExact(dateIn, "ddmmyy", null),
                    ReturnDate = DateTime.ParseExact("010101", "ddmmyy", null)
                });

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    Console.WriteLine("Sorry that car's not available");
                    Console.ReadLine();
                }
            }
        }
Esempio n. 4
0
 public void Delete()
 {
     using (var db = new CarRentalDBContext())
     {
         db.Cars
         .ToList()
         .ForEach(car => Console.WriteLine("Id:" + car.Id + "  " + car.Make + " " + car.Model));
         Console.WriteLine("");
         Console.WriteLine("Specify which car ID to remove: ");
         int carId = Int32.Parse(Console.ReadLine());
         Console.WriteLine(carId);
         var returnedCar = db.Cars.FirstOrDefault(car => car.Id.Equals(carId));
         if (returnedCar == null)
         {
             Console.WriteLine("");
             Console.WriteLine("This car does not exist");
             Delete();
             return;
         }
         db.Cars.Remove(returnedCar);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public void Delete()
 {
     using (var db = new CarRentalDBContext())
     {
         db.Customers
         .ToList()
         .ForEach(Customer => Console.WriteLine("Id:" + Customer.Id + "  " + Customer.first_name + " " + Customer.last_name));
         Console.WriteLine("");
         Console.WriteLine("Specify which Customer ID to remove: ");
         int customerId = Int32.Parse(Console.ReadLine());
         Console.WriteLine(customerId);
         var idRecieved = db.Customers.FirstOrDefault(Customer => Customer.Id.Equals(customerId));
         if (idRecieved == null)
         {
             Console.WriteLine("");
             Console.WriteLine("This customer does not exist");
             Delete();
             return;
         }
         db.Customers.Remove(idRecieved);
         db.SaveChanges();
     }
 }
Esempio n. 6
0
        public void Update()
        {
            using (var db = new CarRentalDBContext())

            {
                char selection;

                db.Cars
                .ToList()
                .ForEach(car => Console.WriteLine("Id:" + car.Id + "  " + car.Make + " " + car.Model));
                Console.WriteLine("");
                Console.WriteLine("Enter Id of the car you wish to modify");
                int carId    = Convert.ToInt32(Console.ReadLine());
                var foundCar = db.Cars.Find(carId);
                Console.WriteLine("");
                Console.WriteLine("Choose the field you wish to modify");
                Console.WriteLine("");
                Console.WriteLine("╔══════════╗ ╔═══════════╗ ╔═══════════╗ ╔═══════════╗ ╔═══════════╗");
                Console.WriteLine("║ 1. Make  ║ ║  2. Model ║ ║  3. Year  ║ ║ 4. Colour ║ ║ 5. Milage ║");
                Console.WriteLine("╚══════════╝ ╚═══════════╝ ╚═══════════╝ ╚═══════════╝ ╚═══════════╝");
                selection = Console.ReadKey().KeyChar;
                Console.WriteLine("");
                switch (selection)
                {
                case '1':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Make");
                    foundCar.Make = Console.ReadLine();
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Car's Make has been successfully updated!");
                    break;

                case '2':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Model");
                    foundCar.Model = Console.ReadLine();
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Car's Model has been successfully updated!");
                    break;

                case '3':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Year");
                    foundCar.Year = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Car's Year has been successfully updated!");
                    break;

                case '4':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Colour");
                    foundCar.Colour = Console.ReadLine();
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Car's Colour has been successfully updated!");
                    break;

                case '5':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Milage");
                    foundCar.Milage = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Car's Milage has been successfully updated!");
                    break;

                case 'q':
                    Console.WriteLine("");
                    Console.WriteLine("Quitting now");
                    break;

                default:
                    Console.WriteLine("");
                    Console.WriteLine("Thats not an option you fool");
                    break;
                }
            }
        }
Esempio n. 7
0
        public void Update()
        {
            using (var db = new CarRentalDBContext())

            {
                char selection;

                db.Customers
                .ToList()
                .ForEach(Customer => Console.WriteLine("Id:" + Customer.Id + "  " + Customer.first_name + " " + Customer.last_name));
                Console.WriteLine("");
                Console.WriteLine("Enter Id of the Customer you wish to modify");
                int customerId    = Convert.ToInt32(Console.ReadLine());
                var foundCustomer = db.Customers.Find(customerId);
                Console.WriteLine("");
                Console.WriteLine("Choose the field you wish to modify");
                Console.WriteLine("");
                Console.WriteLine("╔═══════════════╗ ╔══════════════╗ ╔═════════════╗ ╔═════════════╗ ");
                Console.WriteLine("║ 1. First Name ║ ║ 2. Last Name ║ ║    3. DL    ║ ║  4. Phone   ║ ");
                Console.WriteLine("╚═══════════════╝ ╚══════════════╝ ╚═════════════╝ ╚═════════════╝ ");
                selection = Console.ReadKey().KeyChar;
                Console.WriteLine("");
                switch (selection)
                {
                case '1':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new First Name");
                    foundCustomer.first_name = Console.ReadLine();
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Customer's First Name has been successfully updated!");
                    break;

                case '2':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Last Name");
                    foundCustomer.last_name = Console.ReadLine();
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Customer's Last Name has been successfully updated!");
                    break;

                case '3':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Drivers License");
                    foundCustomer.DL_Number = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Customer's Drivers License has been successfully updated!");
                    break;

                case '4':
                    Console.WriteLine("");
                    Console.WriteLine("Enter the new Phone Number");
                    foundCustomer.phone_number = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("");
                    db.SaveChanges();
                    Console.WriteLine("Customer's Phone Number has been successfully updated!");
                    break;

                case 'q':
                    Console.WriteLine("");
                    Console.WriteLine("Quitting now");
                    break;

                default:
                    Console.WriteLine("");
                    Console.WriteLine("Thats not an option you fool");
                    break;
                }
            }
        }