예제 #1
0
        private static void AddCar()
        {
            Console.WriteLine("");
            Console.WriteLine("Specify Make: ");
            var make = Console.ReadLine();

            Console.WriteLine("Specify Model: ");
            var model = Console.ReadLine();

            Console.WriteLine("and now the Year: ");
            var year = Console.ReadLine();

            Console.WriteLine("What colour is it?");
            var colour = Console.ReadLine();

            Console.WriteLine("Whats the odometer reading?");
            var mile = Console.ReadLine();

            using (var db = new CarRentalDBContext())
            {
                //Car car = new Car();
                //car.Make = make;
                //db.Cars.Add(car);

                db.Cars.Add(new Car()
                {
                    Make   = make,
                    Model  = model,
                    Year   = Convert.ToInt32(year),
                    Colour = colour,
                    Milage = Convert.ToInt32(mile)
                });
                db.SaveChanges();
            }
        }
예제 #2
0
 private static void DeleteCustomer()
 {
     Console.WriteLine("");
     Console.WriteLine("");
     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 car does not exist");
             DeleteCar();
             return;
         }
         db.Customers.Remove(idRecieved);
         db.SaveChanges();
     }
 }
예제 #3
0
 public CarBookingsController(CarRentalDBContext context,
                              UserDBContext userDBContext, IEmailConfiguration emailConfiguration)
 {
     _context            = context;
     _usersDBContext     = userDBContext;
     _emailConfiguration = emailConfiguration;
 }
예제 #4
0
        public void IntializeReturn()
        {
            using (var db = new CarRentalDBContext())
            {
                var resevations = db.Resevations.Where(x => x.Car.IsRented == true).ToList();
                Console.WriteLine("Select Booking number");
                var loop = 1;
                foreach (var item in resevations)
                {
                    Console.WriteLine($"{loop} - {item.BookingNumber}");
                    loop++;
                }
                var listindex = int.Parse(Console.ReadLine());
                var userresv  = resevations.ElementAt(listindex - 1);
                var car       = db.Cars.Find(userresv.CarId);
                var dayspent  = (DateTime.Now - userresv.BookingDate).Days;
                //var tempdate = new DateTime(2021,03,13);
                //var dayspent = (DateTime.Now - tempdate).Days;
                Console.WriteLine("What is the current milage on the car? Enter numbers");
                var currentmileage = int.Parse(Console.ReadLine());

                var mileage        = currentmileage - car.Mileage;
                var rentalcategory = userresv.RentalCategory;
                var cost           = CalculateCost(dayspent, mileage, rentalcategory);
                Console.WriteLine($"Total cost of the resevation is {cost}");
                car.Mileage  = currentmileage;
                car.IsRented = false;
                db.Update(car);
                db.SaveChanges();
                Console.ReadLine();
            }
        }
예제 #5
0
 public void InitializeRent()
 {
     using (var db = new CarRentalDBContext())
     {
         var cars = db.Cars.Where(x => x.IsRented == false).ToList();
         Console.WriteLine("Select one of the available cars by writting the modelname");
         var loop = 1;
         foreach (var item in cars)
         {
             Console.WriteLine($"{loop} - {item.CarModel}");
             loop++;
         }
         var result = Console.ReadLine();
         Console.WriteLine("And what type of Category?");
         foreach (var item in categories)
         {
             Console.WriteLine($"{item}");
         }
         var category = Console.ReadLine().ToUpper();
         Console.WriteLine("Please enter your date of birth with 10 letters");
         var customernumber = Console.ReadLine();
         var selectedcar    = db.Cars.Single(x => x.CarModel.ToLower().Contains(result.ToLower()));
         RentCar(selectedcar, Enum.Parse <RentalCategory>(category), customernumber, db);
         Console.ReadLine();
     }
 }
예제 #6
0
 private static void DeleteCar()
 {
     Console.WriteLine("");
     Console.WriteLine("");
     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");
             DeleteCar();
             return;
         }
         db.Cars.Remove(returnedCar);
         db.SaveChanges();
     }
 }
예제 #7
0
        private static void AddCustomer()
        {
            Console.WriteLine("First Name: ");
            var nameFirst = Console.ReadLine();

            Console.WriteLine("Last name: ");
            var namelast = Console.ReadLine();

            Console.WriteLine("Drivers License: ");
            var license = Console.ReadLine();

            Console.WriteLine("Phone number");
            var phone = Console.ReadLine();

            using (var db = new CarRentalDBContext())
            {
                db.Customers.Add(new Customer()
                {
                    first_name   = nameFirst,
                    last_name    = namelast,
                    DL_Number    = Convert.ToInt32(license),
                    phone_number = Convert.ToInt32(phone),
                });
                db.SaveChanges();
            }
        }
예제 #8
0
 public CarsViewComponent(CarRentalDBContext ctx)
 {
     this._ctx = ctx;
     if (_ctx.CarSet.Count() == 0)
     {
         _ctx.CarSet.Add(new Car {
             Id = 1, BrandName = "DMC", ModelName = "Delorian", YearOfConstruction = 1975
         });
         _ctx.SaveChanges();
     }
 }
예제 #9
0
        private ReservationOfCarsLogic CreateLogicInstance(out CarRentalDBContext ctx)
        {
            Guid databaseName = Guid.NewGuid();
            DbContextOptionsBuilder <CarRentalDBContext> builder = new DbContextOptionsBuilder <CarRentalDBContext>().UseInMemoryDatabase(databaseName.ToString());
            CarRentalDBContext context = new CarRentalDBContext(builder.Options);

            SeedData.PopulateTestData(context);
            context.SaveChanges();

            ctx = context;
            return(new ReservationOfCarsLogic(context));
        }
예제 #10
0
        public CarsAsyncController(CarRentalDBContext carRentalDBContext)
        {
            _carRentalDBContext = carRentalDBContext;

            if (_carRentalDBContext.CarSet.Count() == 0)
            {
                _carRentalDBContext.CarSet.Add(new Car {
                    Id = 1, BrandName = "DMC", ModelName = "Delorian", YearOfConstruction = 1975
                });
                _carRentalDBContext.SaveChanges();
            }
        }
예제 #11
0
 private static void ListCustomers()
 {
     Console.WriteLine("");
     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("Press enter to return to Customer menu");
         Console.ReadLine();
     }
 }
예제 #12
0
 private static void ListCars()
 {
     Console.WriteLine("");
     using (var db = new CarRentalDBContext())
     {
         db.Cars
         .ToList()
         .ForEach(car => Console.WriteLine("Id:" + car.Id + "  " + car.Make + " " + car.Model));
         Console.WriteLine("");
         Console.WriteLine("Press enter to return to Car menu");
         Console.ReadLine();
     }
 }
예제 #13
0
        private static void AddRental()

        {
            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();
                }
            }
        }
 public CarTypesController(CarRentalDBContext context)
 {
     _context = context;
 }
 public ReservationOfCarsLogic(CarRentalDBContext dbContext)
 {
     repos = new GenericRepository(dbContext);
 }
예제 #16
0
        public void RentCar(Car car, RentalCategory category, string socialsecuritynumber, CarRentalDBContext db)
        {
            var resevation = new Resevation();
            var customer   = new Customer();

            resevation.CarId               = car.Id;
            resevation.Car                 = car;
            resevation.RentalCategory      = category;
            resevation.BookingNumber       = random.Next(1, 999999);
            resevation.CustomerId          = customer.Id;
            resevation.BookingDate         = DateTime.Now;
            customer.SocialSercurityNumber = socialsecuritynumber;
            car.IsRented = true;
            db.Update(car);
            db.Add(customer);
            db.Add(resevation);
            db.SaveChanges();
            Console.WriteLine($"You have rented the car with booking number {resevation.BookingNumber}");
        }
예제 #17
0
 public BookingController(CarRentalDBContext dbContext)
 {
     logicInstance = new ReservationOfCarsLogic(dbContext);
 }
예제 #18
0
 public CustomersController(CarRentalDBContext context)
 {
     _context = context;
 }
예제 #19
0
        private static void UpdateCustomer()
        {
            Console.WriteLine("");
            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;
                }
            }
        }
예제 #20
0
        public static void PopulateTestData(CarRentalDBContext context)
        {
            context.Cars.Add(new Car
            {
                Id             = 1,
                Category       = CarCategory.Compact,
                TotalCarMilage = 3000
            });

            context.Cars.Add(new Car
            {
                Id             = 2,
                Category       = CarCategory.Premium,
                TotalCarMilage = 10000
            });

            context.Cars.Add(new Car
            {
                Id             = 3,
                Category       = CarCategory.Minivan,
                TotalCarMilage = 400
            });

            context.Cars.Add(new Car
            {
                Id             = 4,
                Category       = CarCategory.Compact,
                TotalCarMilage = 500
            });

            context.Cars.Add(new Car
            {
                Id             = 5,
                Category       = CarCategory.Premium,
                TotalCarMilage = 583
            });

            context.Cars.Add(new Car
            {
                Id             = 6,
                Category       = CarCategory.Minivan,
                TotalCarMilage = 2086
            });

            //context.Bookings.Add(new Booking
            //{
            //    Id = 1,
            //    CarId = 1,
            //    CustomerBirthDate = new DateTime(1989, 09, 03),
            //    TotalCostOfRent = 0.0m,
            //    RentalDate = new DateTime(2021, 1, 2),
            //    DateOfRentalEnd = new DateTime(2021, 1, 2),
            //    KmDrivenWithinReservation = 0
            //});

            //context.Bookings.Add(new Booking
            //{
            //    Id = 2,
            //    CarId = 3,
            //    CustomerBirthDate = new DateTime(1989, 09, 03),
            //    TotalCostOfRent = 0.0m,
            //    RentalDate = new DateTime(2021, 2, 2),
            //    DateOfRentalEnd = new DateTime(2021, 2, 3),
            //    KmDrivenWithinReservation = 0
            //});
        }
 public CcompaniesController(CarRentalDBContext context)
 {
     _context = context;
 }
예제 #22
0
        private static void UpdateCar()
        {
            Console.WriteLine("");
            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;
                }
            }
        }