예제 #1
0
        private static void ListCustomer()
        {
            Console.WriteLine("List Cusomers");
            using (var db = new RentCDb())
            {
                var query = (from c in db.Customers
                             select c).ToArray();

                int      nrRows  = query.Count();
                string[] headers = { "CustomerID", "Name", "Birt Date" };

                string[][] rows = new string[query.Length][];
                int        i    = 0;

                foreach (var item in query)
                {
                    string[] row = new string[3];
                    row[0]  = item.CostumerID.ToString();
                    row[1]  = item.Name.ToString();
                    row[2]  = item.BirthDate.Date.ToString();
                    rows[i] = row;
                    i++;
                }
                DrawTable.DrawMyTable(headers, query.Length, rows);
            }
            Console.ReadKey();
            SelectOption();
        }
예제 #2
0
        public static int ValidateCar(string carPlate)
        {
            using (var db = new RentCDb())
            {
                while (!db.Cars.Any(c => c.Plate == carPlate))
                {
                    Console.WriteLine("Car doesn't exist! Enter an existing car" +
                                      "\n or type quit to go to main menu!");
                    Console.WriteLine("Car Plate:");
                    var ans = Console.ReadLine();
                    if (ans == "QUIT")
                    {
                        MenuPage.SelectOption();
                    }
                    else
                    {
                        carPlate = ans;
                    }
                }
                var stringID = from c in db.Cars
                               where c.Plate == carPlate
                               select c.CarID;

                return(stringID.FirstOrDefault());
            }
        }
예제 #3
0
        private static void ListRents()
        {
            Console.WriteLine("List Rentals");
            using (var db = new RentCDb())
            {
                var query = (from r in db.Reservations
                             select r).ToArray();

                int      nrRows  = query.Count();
                string[] headers = { "CarPlate", "ClientID", "Start Date", "End Date", "Location" };

                string[][] rows = new string[query.Length][];
                int        i    = 0;

                foreach (var item in query)
                {
                    string[] row = new string[5];
                    row[0] = item.Car.Plate;
                    row[1] = item.CostumerID.ToString();
                    row[2] = item.StartDate.Date.ToString();
                    row[3] = item.EndDate.ToShortDateString();

                    var location = db.Locations.Find(item.LocationID).Name;
                    row[4] = location;

                    rows[i] = row;
                    i++;
                }
                DrawTable.DrawMyTable(headers, query.Length, rows);
            }
            Console.ReadKey();
            SelectOption();
        }
        public static void AddCustomer()
        {
            Console.Write("Enter Cusomer Name: ");
            var customerName = Console.ReadLine();

            Console.Write("Enter customer Birth Date: ");
            var customerBirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());

            Customer customer = new Customer
            {
                Name      = customerName,
                BirthDate = customerBirthDate
            };

            using (var db = new RentCDb())
            {
                db.Customers.Add(customer);
                db.SaveChanges();
            }
            Console.WriteLine("Customer saved:");
            DisplayCustomer(customer);
            Console.ReadLine();

            MenuPage.SelectOption();
        }
예제 #5
0
        private static void ListAvailableCars()
        {
            localhost.WebService1 proxy = new localhost.WebService1();
            var jsonAvailableCars       = proxy.AvalialbleCars();

            Car[] availableCars = JsonConvert.DeserializeObject <List <Car> >(jsonAvailableCars).ToArray();

            using (var db = new RentCDb())
            {
                int      nrRows  = availableCars.Length;
                string[] headers = { "CarID", "Plate", "Manufacturer", "Model", "PricePerDay", "Location" };

                string[][] rows = new string[availableCars.Length][];
                int        i    = 0;

                foreach (var item in availableCars)
                {
                    string[] row = new string[5];
                    row[0] = item.CarID.ToString();
                    row[1] = item.Plate;
                    row[2] = item.Manufacturer;
                    row[3] = item.Model;
                    row[3] = item.PricePerDay.ToString();
                    row[3] = db.Locations.Find(item.LocationID).Name;

                    var location = db.Locations.Find(item.LocationID).Name;
                    row[4] = location;

                    rows[i] = row;
                    i++;
                }
                DrawTable.DrawMyTable(headers, availableCars.Length, rows);
                SelectOption();
            }
        }
        public static void UpdateCustomer()
        {
            Console.Write("Please enter customerID :");
            var customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine());

            using (var db = new RentCDb())
            {
                while (!db.Customers.Any(c => c.CostumerID == customerID))
                {
                    Console.WriteLine("Please enter an existing customer");
                    customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine());
                }

                Customer customer = db.Customers.Find(customerID);
                DisplayCustomer(customer);
Options:
                Console.WriteLine("Which field do you want to update?");
                Console.WriteLine("1. Name");
                Console.WriteLine("2. BirthDate");


                var ans = Console.ReadLine();
                switch (ans)
                {
                case "1":
                    Console.Write("Enter Cusomer Name: ");
                    customer.Name = Console.ReadLine();
                    break;

                case "2":
                    Console.Write("Enter customer Birth Date: ");
                    customer.BirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());
                    break;

                default:
                    Console.WriteLine("This is not a valid option!");
                    goto Options;
                }

                Console.WriteLine("New Reservation Data:");
                DisplayCustomer(customer);
                Console.WriteLine("Would you like to modify something else? \n" +
                                  "If yes, type YES if no type NO to go back to main menu");
                ans = Console.ReadLine();
                if (ans == "NO")
                {
                    MenuPage.SelectOption();
                }
                else if (ans == "YES")
                {
                    goto Options;
                }

                db.SaveChanges();
                Console.WriteLine("Customer saved:");
                DisplayCustomer(customer);
                Console.ReadLine();
                MenuPage.SelectOption();
            }
        }
예제 #7
0
        public static void DisplayReservationInfo(Reservation reservation)
        {
            Car car; Location location;

            using (var db = new RentCDb())
            {
                car      = db.Cars.Find(reservation.CarID);
                location = db.Locations.Find(reservation.LocationID);
            }

            Console.WriteLine("Car Plate: " + car.Plate);
            Console.WriteLine("Client ID: " + reservation.CostumerID);
            Console.WriteLine("Start Date: " + reservation.StartDate);
            Console.WriteLine("End Date: " + reservation.EndDate);
            Console.WriteLine("Location: " + location.Name);
        }
예제 #8
0
        static Reservation GetReservation()
        {
            Console.WriteLine("Please enter a reservationID");
            var reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine());

            using (var db = new RentCDb())
            {
                while (!db.Reservations.Any(r => r.ReservationID == reservationID))
                {
                    Console.WriteLine("Please enter a valid reservationID");
                    reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine());
                }
                var reservation = db.Reservations.Find(reservationID);
                ReservationManagement.DisplayReservationInfo(reservation);
                return(reservation);
            }
        }
예제 #9
0
        static public List <Nullable <DateTime> > IsCarAvailabe(int carId, DateTime startDate, DateTime endDate)
        {
            List <Nullable <DateTime> > carReserved = new List <Nullable <DateTime> >();

            using (var db = new RentCDb())
            {
                var query = from r in db.Reservations
                            where ((r.StartDate == startDate) && (r.EndDate == endDate) && (r.CarID == carId))
                            select r;

                foreach (var item in query)
                {
                    if (item.ReservStatsID != 1)
                    {
                        carReserved.Add(item.StartDate);
                    }
                }
            }
            return(carReserved);
        }
예제 #10
0
 public static int ValidateClient(int id)
 {
     using (var db = new RentCDb())
     {
         while (!db.Customers.Any(c => c.CostumerID == id))
         {
             Console.WriteLine("Client doesn't exist! Enter an existing client" +
                               "\n or type quit to go to main menu!");
             Console.WriteLine("Client:");
             var ans = Console.ReadLine();
             if (ans.ToUpper() == "QUIT")
             {
                 MenuPage.SelectOption();
             }
             else
             {
                 id = ValidateUserInput.ValidateInputInt(Console.ReadLine());
             }
         }
         return(id);
     }
 }
예제 #11
0
        public static int ValidateCarLocation(int id, String location)
        {
            using (var db = new RentCDb())
            {
                var query = from l in db.Locations
                            where l.Name == location
                            select l;
                var loc = query.First().LocationID;

                var carLocation = (from c in db.Cars
                                   where c.CarID == id
                                   select c).First().LocationID;

                while (!(carLocation == loc))
                {
                    Console.WriteLine("The car is not in the same location Please select another car" +
                                      "\n or type quit to go to main menu!");

                    Console.WriteLine("Car Plate:");
                    var ans = Console.ReadLine();
                    if (ans.ToUpper() == "QUIT")
                    {
                        MenuPage.SelectOption();
                    }
                    else
                    {
                        ValidateCar(Console.ReadLine());
                    }
                }

                var locationID = from l in db.Locations
                                 where l.Name == location
                                 select l;
                return(locationID.First().LocationID);
            }
        }
예제 #12
0
 public ReservationService()
 {
     _dbContext = new RentCDb();
 }
예제 #13
0
        public static void UpdateRental()
        {
            //  Reservation reservation = GetReservation();


            Console.WriteLine("Please enter a reservationID");
            var reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine());

            using (var db = new RentCDb())
            {
                while (!db.Reservations.Any(r => r.ReservationID == reservationID))
                {
                    Console.WriteLine("Please enter a valid reservationID");
                    reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine());
                }
                var reservation = db.Reservations.Find(reservationID);
                ReservationManagement.DisplayReservationInfo(reservation);

Options:
                var ans = UpdateCarRentalOptions();

                switch (ans)
                {
                case "1":
                    Console.WriteLine("Please enter a new car Plate");
                    var carPlate = Console.ReadLine();
                    var carID    = ReservationManagement.ValidateCar(carPlate);
                    reservation.CarID = carID;
                    db.SaveChanges();
                    break;

                case "2":
                    Console.WriteLine("Please enter a Client ID:");
                    var clientID = ReservationManagement.ValidateClient
                                       (ValidateUserInput.ValidateInputInt(Console.ReadLine()));
                    reservation.CostumerID = clientID;
                    db.SaveChanges();
                    break;

                case "3":
                    Console.WriteLine("Please enter Start Date (mm.dd.yyy):");
                    var enteredStartDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());
                    var validStartDate   = ReservationManagement.ValidateDates(enteredStartDate, reservation.EndDate).Item1;
                    reservation.StartDate = validStartDate;
                    db.SaveChanges();
                    break;

                case "4":
                    Console.WriteLine("Please enter End Date (mm.dd.yyy):");
                    var enteredEndDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());
                    var validEndDate   = ReservationManagement.ValidateDates(reservation.StartDate, enteredEndDate).Item2;
                    reservation.EndDate = validEndDate;
                    db.SaveChanges();
                    break;

                case "5":
                    Console.WriteLine("Please enter a new location: ");
                    var enteredLocation = Console.ReadLine();
                    var newLocation     = ReservationManagement.ValidateCarLocation(reservation.CarID, enteredLocation);
                    reservation.LocationID = newLocation;
                    db.SaveChanges();
                    break;

                default:
                    Console.WriteLine("Option not available");
                    goto Options;
                }

                Console.WriteLine("New Reservation Data:");
                ReservationManagement.DisplayReservationInfo(reservation);
                Console.WriteLine("Would you like to modify something else? \n" +
                                  "If yes, type YES if no type NO to go back to main menu");
                ans = Console.ReadLine();
                if (ans.ToUpper() == "NO")
                {
                    MenuPage.SelectOption();
                }
                else if (ans.ToUpper() == "YES")
                {
                    goto Options;
                }


                db.SaveChanges();
            }
        }
 public ReservationsController()
 {
     db = new RentCDb();
     reservationRepository = new ReservationRepository();
 }
예제 #15
0
 public CarService()
 {
     _dbContext = new RentCDb();
 }
        public static void DisplayScreen()
        {
            Reservation reservation = new Reservation();

            Console.Write("Car Plate:");
            var carPlate = Console.ReadLine();
            var carID    = ReservationManagement.ValidateCar(carPlate);

            reservation.CarID = carID;


            Console.Write("Client ID:");
            var clientID = ValidateUserInput.ValidateInputInt(Console.ReadLine());

            reservation.CostumerID = ReservationManagement.ValidateClient(clientID);


            Console.Write("Start Date(mm.dd.yyyy):");
            var startDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());

            Console.Write("End Date(mm.dd.yyyy):");
            var endDate = ValidateUserInput.ValidateInputDate(Console.ReadLine());

            reservation.StartDate = ReservationManagement.ValidateDates(startDate, endDate).Item1;
            reservation.EndDate   = ReservationManagement.ValidateDates(startDate, endDate).Item2;


            Console.Write("Location:");
            var location = Console.ReadLine();

            reservation.LocationID = ReservationManagement.ValidateCarLocation(carID, location);


            List <Nullable <DateTime> > carReserved = ReservationManagement.IsCarAvailabe(carID, startDate, endDate);

            if (carReserved.Count() > 0)
            {
                Console.WriteLine("Car is not available on: " + carReserved);
                ReservationManagement.DisplayReservationInfo(reservation);
            }

            using (var db = new RentCDb())
            {
                Car car = db.Cars.Find(reservation.CarID);

                var     price = car.PricePerDay * (decimal)((endDate - startDate).TotalDays);
                decimal totalPrice;

                Console.WriteLine("The car is available for " + car.PricePerDay + "/day");
                Console.Write("Do you have a cupone code?\nIf yes enter it, if no type NO: ");
                var ans = Console.ReadLine();
                if (ans.ToUpper() == "NO")
                {
                    totalPrice = price;
                }
                else
                {
                    var customerCupon = Console.ReadLine();
                    var cupon         = db.Coupons.FirstOrDefault(c => c.CouponCode == customerCupon);
                    if (cupon != null)
                    {
                        Console.WriteLine("Discount: " + cupon.Discount + ": " + cupon.Description);
                        totalPrice = price - (cupon.Discount * price);
                    }
                    totalPrice = price;
                }

                Console.WriteLine("Total price: " + totalPrice);
                Console.WriteLine("Save the reservation? Type YES to save \nNO to go back to main menu: ");

                ans = Console.ReadLine();
                if (ans == "NO")
                {
                    MenuPage.SelectOption();
                }
                else
                {
                    reservation.ReservStatsID = 1;
                    db.Reservations.Add(reservation);
                    db.SaveChanges();
                }
            }
        }
예제 #17
0
 public SQLRepository(RentCDb context)
 {
     this.context = context;
     this.dbSet   = context.Set <T>();
 }