コード例 #1
0
        // Method for Update Car Rent Screen logic
        public void UpdateReservaion()
        {
            Console.Clear();

            Car car = new Car();
            PrintColorMessage  printColorMessage   = new PrintColorMessage();
            ReservationService reservationServices = new ReservationService();
            Customer           customer            = new Customer();
            Reservation        reservation         = new Reservation();
            Navigation         navigation          = new Navigation();


            Console.Write("Reservation ID:");
            reservation.ReservationID = Convert.ToInt32(Console.ReadLine());

            Console.Write("Customer ID: ");
            reservation.CustomerID = Convert.ToInt32(Console.ReadLine());

            Console.Write("Car Plate: ");
            reservation.CarPlate = Console.ReadLine();

            Console.Write("Start Date: ");
            reservation.StartDate = Convert.ToDateTime(Console.ReadLine());

            Console.Write("End Date: ");
            reservation.EndDate = Convert.ToDateTime(Console.ReadLine());

            Console.Write("Location: ");
            reservation.Location = Console.ReadLine();

            reservationServices.UpdateReservation(reservation);

            printColorMessage.Print(ConsoleColor.Yellow, "Reservation Updated succesffuly!");
            navigation.GoToMenu();
        }
コード例 #2
0
        // Update Customer database manipulations
        public void Update(Customer customer)
        {
            Car car = new Car();
            CustomerValidator validator    = new CustomerValidator();
            ValidationResult  result       = validator.Validate(customer);
            PrintColorMessage colorMessage = new PrintColorMessage();

            // Input Customer Name Validation
            if (!result.IsValid)
            {
                colorMessage.Print(ConsoleColor.Red, "\n Customer is not Updated! See reason below:");

                //data validation
                foreach (var failure in result.Errors)
                {
                    Console.WriteLine("\n '" + failure.PropertyName + "' written incorrectly . \n Details: " + failure.ErrorMessage);
                }
            }
            else
            {
                //EF
                using (var context = new ApplicationDbContext())
                {
                    var customerToUpdate =
                        context.Customers.First(x => x.CustomerID == customer.CustomerID);
                    customerToUpdate.Name      = customer.Name;
                    customerToUpdate.BirthDate = customer.BirthDate;

                    context.SaveChanges();
                }
            }
        }
コード例 #3
0
        // Method for Register New Customer Screen logic
        public void RegisterNewCustomer()
        {
            CustomerService   customerServices = new CustomerService();
            PrintColorMessage colorMessage     = new PrintColorMessage();
            Navigation        navigation       = new Navigation();
            Customer          customer         = new Customer();

            Console.Clear();

            customer.CustomerID = customer.CustomerID;

            Console.Write("Name: ");
            customer.Name = Console.ReadLine();

            Console.Write("Birth Date: ");

            // Birth Date format validation
            try
            {
                customer.BirthDate = Convert.ToDateTime(Console.ReadLine());
            }
            catch (Exception e)
            {
                if (e is System.FormatException)
                {
                    colorMessage.Print(ConsoleColor.Red, "\n 'Birth Date' written incorrectly.");
                    Console.WriteLine("\n Details: The format should be: dd-MM-yyyy");
                }
            }

            customerServices.Create(customer);

            navigation.GoToMenu();
        }
コード例 #4
0
        public void Print()
        {
            PrintColorMessage printColorMessage = new PrintColorMessage();

            // Print Welcome message
            printColorMessage.Print(ConsoleColor.Green, "\n\n   Welcome to RentC, your brand new solution to manage and control your            company's data without missing anything.");

            Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();

            printColorMessage.Print(ConsoleColor.Yellow, "\t Press 'ENTER' to continue or 'ESC' to quit.");
        }
コード例 #5
0
        // Register Customer db manipulations
        public void Create(Customer customer)
        {
            PrintColorMessage colorMessage = new PrintColorMessage();
            CustomerValidator validator    = new CustomerValidator();
            ValidationResult  result       = validator.Validate(customer);
            Navigation        navigation   = new Navigation();


            // Input Customer Name Validation
            if (!result.IsValid)
            {
                colorMessage.Print(ConsoleColor.Red, "\nCustomer not registered! See reason below:");

                //data validation
                foreach (var failure in result.Errors)
                {
                    Console.WriteLine("\n '" + failure.PropertyName + "' written incorrectly . \n Details: " + failure.ErrorMessage);
                }
            }
            else
            {
                using (var context = new ApplicationDbContext())
                {
                    try
                    {
                        context.Customers.Add(customer);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (SqlException)
                        {
                            colorMessage.Print(ConsoleColor.Red, "Error: CustomerID should not exist in the Customer table");
                        }

                        colorMessage.Print(ConsoleColor.Yellow, "Customer created succesffuly !");

                        navigation.GoToMenu();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
コード例 #6
0
        // Method for Update Customers screen logic
        public void UpdateCustomer()
        {
            Console.Clear();

            PrintColorMessage colorMessage     = new PrintColorMessage();
            CustomerService   customerServices = new CustomerService();
            Customer          customer         = new Customer();
            Navigation        navigation       = new Navigation();

            Console.Write("Customer ID: ");
            customer.CustomerID = Convert.ToInt32(Console.ReadLine());

            Console.Write("Name: ");
            customer.Name = Console.ReadLine();

            Console.Write("Birth Date: ");
            customer.BirthDate = Convert.ToDateTime(Console.ReadLine());

            customerServices.Update(customer);

            colorMessage.Print(ConsoleColor.Yellow, "Customer Updated succesffuly!");
            navigation.GoToMenu();
        }
コード例 #7
0
        // Method for Register New Car Rent Screen logic
        public void RegisterNewCarRent()
        {
            Console.Clear();

            Car car = new Car();
            PrintColorMessage  printColorMessage   = new PrintColorMessage();
            ReservationService reservationServices = new ReservationService();
            Customer           customer            = new Customer();
            Reservation        reservation         = new Reservation();
            Navigation         navigation          = new Navigation();

            Console.Write("Car Plate: ");
            reservation.CarPlate = Console.ReadLine();

            Console.Write("Car ID: ");
            reservation.CarID = Convert.ToInt32(Console.ReadLine());

            Console.Write("Customer ID: ");
            reservation.CustomerID = Convert.ToInt32(Console.ReadLine());

            reservation.ReservStatsID = 1;

            Console.Write("Start Date: ");
            reservation.StartDate = Convert.ToDateTime(Console.ReadLine());

            Console.Write("End Date: ");
            var endDate = Console.ReadLine();

            reservation.EndDate = Convert.ToDateTime(endDate);

            Console.Write("Location: ");
            reservation.Location = Console.ReadLine();

            reservationServices.CreateReservation(reservation);

            navigation.GoToMenu();
        }
コード例 #8
0
        // Update Reservation database manipulations
        public void UpdateReservation(Reservation reservation)
        {
            Car car = new Car();
            ReservationValidator validator    = new ReservationValidator();
            ValidationResult     result       = validator.Validate(reservation);
            PrintColorMessage    colorMessage = new PrintColorMessage();


            // Input Customer Name Validation
            if (!result.IsValid)
            {
                colorMessage.Print(ConsoleColor.Red, "\nReservation is not Updated! See reason below:");

                //data validation
                foreach (var failure in result.Errors)
                {
                    Console.WriteLine("\n '" + failure.PropertyName + "' written incorrectly . \n Details: " + failure.ErrorMessage);
                }
            }
            else
            {
                //EF
                using (var context = new ApplicationDbContext())
                {
                    var reservationToUpdate =
                        context.Reservations.First(x => x.ReservationID == reservation.ReservationID);
                    reservationToUpdate.CarPlate  = reservation.CarPlate;
                    reservationToUpdate.StartDate = reservation.StartDate;
                    reservationToUpdate.EndDate   = reservation.EndDate;
                    reservationToUpdate.Location  = reservation.Location;


                    context.SaveChanges();
                }
            }
        }