Пример #1
0
        static void Main(string[] args)
        {
            bool       loop       = true;
            CarManager carManager = new CarManager(new InMemoryCarDal());

            while (loop)
            {
                System.Console.WriteLine("1. List the Cars \t 2. List by Brand Id \t 3. Add a Car \t 4. Delete a Car \t 5. Update a Car \t 6. Exit");
                System.Console.WriteLine("\nChoice: ");
                int choice = Convert.ToInt32(System.Console.ReadLine());
                switch (choice)
                {
                case 1:
                    foreach (var car in carManager.GetAll())
                    {
                        System.Console.WriteLine("---- CAR ----");
                        System.Console.WriteLine("Car ID: " + car.Id);
                        System.Console.WriteLine("Brand ID: " + car.BrandId);
                        System.Console.WriteLine("Year: " + car.ModelYear);
                        System.Console.WriteLine("Daily Price: " + car.DailyPrice);
                        System.Console.WriteLine("Description: " + car.Description);
                        System.Console.WriteLine("------------\n");
                    }
                    break;

                case 2:
                    System.Console.WriteLine("Insert the brand ID");
                    int Id = Convert.ToInt32(System.Console.ReadLine());
                    foreach (var car in carManager.GetById(Id))
                    {
                        System.Console.WriteLine("---- CAR ----");
                        System.Console.WriteLine("Car ID: " + car.Id);
                        System.Console.WriteLine("Brand ID: " + car.BrandId);
                        System.Console.WriteLine("Year: " + car.ModelYear);
                        System.Console.WriteLine("Daily Price: " + car.DailyPrice);
                        System.Console.WriteLine("Description: " + car.Description);
                        System.Console.WriteLine("------------\n");
                    }
                    break;

                case 3:
                    System.Console.WriteLine("Insert the car ID: ");
                    int id = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the brand ID: ");
                    int brandId = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the year: ");
                    int year = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the daily price: ");
                    decimal price = Convert.ToDecimal(System.Console.ReadLine());
                    System.Console.WriteLine("Insert a description for car: ");
                    string desc = System.Console.ReadLine();

                    Car addedCar = new Car {
                        Id = id, BrandId = brandId, ModelYear = year, DailyPrice = price, Description = desc
                    };
                    carManager.Add(addedCar);
                    System.Console.WriteLine("Car added successfully.\n");
                    break;

                case 4:
                    System.Console.WriteLine("Insert the car ID for deletion process: ");
                    id = Convert.ToInt32(System.Console.ReadLine());
                    Car deletedCar = new Car();
                    foreach (var car in carManager.GetAll())
                    {
                        if (car.Id == id)
                        {
                            deletedCar = car;
                        }
                    }
                    carManager.Delete(deletedCar);
                    System.Console.WriteLine("Car deleted successfully.");
                    break;

                case 5:
                    System.Console.WriteLine("Insert the existing car ID: ");
                    id = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the brand ID: ");
                    brandId = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the year: ");
                    year = Convert.ToInt32(System.Console.ReadLine());
                    System.Console.WriteLine("Insert the daily price: ");
                    price = Convert.ToDecimal(System.Console.ReadLine());
                    System.Console.WriteLine("Insert a description for car: ");
                    desc = System.Console.ReadLine();

                    Car updatedCar = new Car {
                        Id = id, BrandId = brandId, ModelYear = year, DailyPrice = price, Description = desc
                    };
                    carManager.Update(updatedCar);
                    System.Console.WriteLine("Car updated successfully.");
                    break;

                case 6:
                    loop = false;
                    break;

                default:
                    System.Console.WriteLine("You inserted wrong choice number.");
                    break;
                }
            }
        }
Пример #2
0
 static void Main(string[] args)
 {
     CarManager   carManager   = new CarManager(new EfCarDal());
     ColorManager colorManager = new ColorManager(new EfColorDal());
     BrandManager brandManager = new BrandManager(new EfBrandDal());
 }
Пример #3
0
        static void Main(string[] args)
        {
            CustomerManager customermanager = new CustomerManager(new EfCustomerDal());
            UserManager     usermanager     = new UserManager(new EfUserDal());
            User            user            = new User {
                Email = "*****@*****.**", FirstName = "Dzhan", LastName = "Halim", Password = "******"
            };

            usermanager.Add(user);
            Customer customer = new Customer {
                Id = 1, CompanyName = "Odisee"
            };

            Rental rental = new Rental {
                CarId = 1, CustomerId = 1, RentDate = DateTime.Today, ReturnDate = DateTime.Today.AddDays(5)
            };



            CarManager carManager = new CarManager(new EfCarDal());
            Car        car        = new Car {
                BrandId = 1, ColorId = 2, Description = "Mercedes-Benz", ModelYear = 2000, Price = 150
            };
            Car car2 = new Car {
                BrandId = 2, ColorId = 3, Description = "Volvo D40", ModelYear = 2000, Price = 150
            };
            Car car3 = new Car {
                BrandId = 3, ColorId = 1, Description = "Audi A3", ModelYear = 2000, Price = 200
            };

            Car carToUpdate = new Car {
                BrandId = 3, ColorId = 3, Description = "Mercedes2", Id = 5, ModelYear = 2000, Price = 200
            };

            // operation add a new car


            RentalManager rentalManager = new RentalManager(new EfRentalDal());

            // carManager.GetAllBydId(5);
            // carManager.GetCarsByBrandId(3);
            // carManager.GetCarsByColorId(3);

            // operation update
            //carManager.Update(carToUpdate);

            var result2 = rentalManager.GetAllRentals();

            if (result2.Success)
            {
                foreach (var item in result2.Data)
                {
                    Console.WriteLine(item.CarId + " " + item.CustomerId + " " + item.RentDate);
                }
            }
            else
            {
                Console.WriteLine(result2.Message);
            }


            // operation get all cars
            var result = carManager.GetCarDetails();

            if (result.Success)
            {
                foreach (var item in result.Data)
                {
                    //carManager.Delete(item);
                    Console.WriteLine(item.Description + item.BrandName + " / " + item.ColorName + " / " + item.Price);
                }
                Console.WriteLine(result.Message);
            }
            else
            {
                Console.WriteLine(result.Message);
            }
            // operation get a car by his id
            //foreach (var item in carManager.GetAllBydId(5))
            //{
            //    //carManager.Delete(item);
            //    Console.WriteLine(item.Description + " / " );
            //}

            // deleteing operation
            //carManager.Delete(car2);

            Console.ReadLine();
        }