Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Variables
            string input;
            int    id = 0, action;

            Controller.CompanyController  companyController = new Controller.CompanyController(CONSTRING_TAPPQA);
            Controller.EmployeeController employeeController = new Controller.EmployeeController(CONSTRING_TAPPQA);

            Console.WriteLine("An welcher Tabelle wollen Sie was ändern?");
            Console.WriteLine("1) Comnpany");
            Console.WriteLine("2) Employee");
            Console.WriteLine("3) Address");
            action = Convert.ToInt32(Console.ReadLine());

            switch (action)
            {
            case 1:
                // Company
                #region Company
                Company company = new Company();

                Console.WriteLine("What would you do?");
                Console.WriteLine("1) Read all");
                Console.WriteLine("2) Read id");
                Console.WriteLine("3) Create");
                Console.WriteLine("4) Update");
                Console.WriteLine("5) Delete");
                action = Convert.ToInt32(Console.ReadLine());

                switch (action)
                {
                case 1:
                    var companies = companyController.Read();
                    foreach (var companyItem in companies)
                    {
                        Console.WriteLine($"id={companyItem.Id}, name={companyItem.Name}, foudedDate={companyItem.FoundedDate}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Geben Sie bitte die id ein");
                    id      = Convert.ToInt32(Console.ReadLine());
                    company = companyController.Read(id);
                    Console.WriteLine($"id={company.Id}, name={company.Name}, foudedDate={company.FoundedDate}");
                    break;

                case 3:
                    Console.WriteLine("What is the company name?");
                    company.Name = Console.ReadLine();

                    Console.WriteLine("What is the founding date(yyyy-mm-dd)? (can be empty)");
                    input = Console.ReadLine();
                    company.FoundedDate = input == "" ? null : (DateTime?)Convert.ToDateTime(input);

                    company = companyController.Create(company);
                    Console.WriteLine($"id={company.Id}, name={company.Name}, foudedDate={company.FoundedDate}");
                    break;

                case 4:
                    Console.WriteLine("Enter the ID of the company you want to change");
                    company.Id = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("What is the new company name? (no change then press enter)");
                    company.Name = Console.ReadLine();
                    company.Name = company.Name == "" ? null : company.Name;

                    Console.WriteLine("What is the new founding date(yyyy-mm-dd)? (no change then press enter)");
                    input = Console.ReadLine();
                    company.FoundedDate = input == "" ? null : (DateTime?)Convert.ToDateTime(input);


                    company = companyController.Update(company);
                    Console.WriteLine($"id={company.Id}, name={company.Name}, foudedDate={company.FoundedDate}");
                    break;

                case 5:
                    Console.WriteLine("Geben Sie bitte die id von dem Datensatz an, den sie löschen möchte");
                    id = Convert.ToInt32(Console.ReadLine());
                    companyController.Delete(id);
                    break;
                }
                #endregion
                break;

            case 2:
                // Employee
                #region Employee
                Employee employee = new Employee();

                Console.WriteLine("An welcher Tabelle wollen Sie was ändern?");
                Console.WriteLine("1) Read all");
                Console.WriteLine("2) Read id");
                Console.WriteLine("3) Create");
                Console.WriteLine("4) Update");
                Console.WriteLine("5) Delete");
                action = Convert.ToInt32(Console.ReadLine());

                switch (action)
                {
                case 1:
                    Console.WriteLine();
                    var employees = employeeController.Read();
                    foreach (var employeeItem in employees)
                    {
                        Console.WriteLine($"Id={employeeItem.Id}, FirstName={employeeItem.FirstName}, LastName={employeeItem.LastName}" +
                                          $", Birthday={employeeItem.Birthday}, DepartmentId={employeeItem.DepartmentId}, AdressId={employeeItem.AddressId}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Geben Sie bitte die id ein");
                    id = Convert.ToInt32(Console.ReadLine());

                    employee = employeeController.Read(id);
                    Console.WriteLine($"\nId={employee.Id}, FirstName={employee.FirstName}, LastName={employee.LastName}" +
                                      $", Birthday={employee.Birthday}, DepartmentId={employee.DepartmentId}, AdressId={employee.AddressId}");
                    break;

                case 3:
                    Console.WriteLine("\nfirst name");
                    employee.FirstName = Console.ReadLine();

                    Console.WriteLine("\nlast name");
                    employee.LastName = Console.ReadLine();

                    Console.WriteLine("\nbirthday (yyyy-mm-dd) (can be empty)");
                    input             = Console.ReadLine();
                    employee.Birthday = input == "" ? null : (DateTime?)Convert.ToDateTime(input);

                    Console.WriteLine("\ndepartment id");
                    employee.DepartmentId = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("\naddress id (can be empty)");
                    employee.AddressId = Convert.ToInt32(Console.ReadLine());

                    employee = employeeController.Create(employee);
                    Console.WriteLine($"\nId={employee.Id}, FirstName={employee.FirstName}, LastName={employee.LastName}" +
                                      $", Birthday={employee.Birthday}, DepartmentId={employee.DepartmentId}, AdressId={employee.AddressId}");
                    break;

                case 4:
                    Console.WriteLine("Enter the ID of the employee you want to change");
                    employee.Id = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("\nfirst name (no change then press enter)");
                    employee.FirstName = Console.ReadLine();

                    Console.WriteLine("\nlast name (no change then press enter)");
                    employee.LastName = Console.ReadLine();

                    Console.WriteLine("\nbirthday (yyyy-mm-dd)  (no change then press enter)");
                    input             = Console.ReadLine();
                    employee.Birthday = input == "" ? null : (DateTime?)Convert.ToDateTime(input);

                    Console.WriteLine("\ndepartment id (no change then press enter)");
                    employee.DepartmentId = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("\naddress id (no change then press enter)");
                    employee.AddressId = Convert.ToInt32(Console.ReadLine());

                    employee = employeeController.Create(employee);
                    Console.WriteLine($"\nId={employee.Id}, FirstName={employee.FirstName}, LastName={employee.LastName}" +
                                      $", Birthday={employee.Birthday}, DepartmentId={employee.DepartmentId}, AdressId={employee.AddressId}");

                    employee = employeeController.Update(employee);
                    Console.WriteLine($"\nId={employee.Id}, FirstName={employee.FirstName}, LastName={employee.LastName}" +
                                      $", Birthday={employee.Birthday}, DepartmentId={employee.DepartmentId}, AdressId={employee.AddressId}");
                    break;

                case 5:
                    Console.WriteLine("Geben Sie bitte die id von dem Datensatz an, den sie löschen möchte");
                    id = Convert.ToInt32(Console.ReadLine());
                    employeeController.Delete(id);
                    break;
                }
                #endregion
                break;

            case 3:
                break;
            }


            Console.WriteLine("\nPress Enter to quit");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Controller.CompanyController  companyController  = new Controller.CompanyController(CONNECTION_STRING);
            Controller.EmployeeController employeeController = new Controller.EmployeeController(CONNECTION_STRING);
            Controller.AddressController  addressController  = new Controller.AddressController(CONNECTION_STRING);

            Console.WriteLine("Press 1 for Company options");
            Console.WriteLine("Press 2 for Employee options");
            Console.WriteLine("Press 3 for Address options");

            switch (Console.ReadLine())
            {
            case "1":     //COMPANY
                Console.WriteLine("Company options: \nPress 1 for Create\nPress 2 for Update\nPress 3 for Delete\nPress 4 for Read\nPress 5 for Read one Company");
                switch (Console.ReadLine())
                {
                case "1":         //CREATE
                    Console.WriteLine("Name of the company?");
                    string name = Console.ReadLine();
                    name = name == "" ? null : name;

                    Console.WriteLine("Foundation date? (E.g.: Jan 15, 2000");
                    DateTime?foundationDate;
                    string   input = Console.ReadLine();
                    foundationDate = input == "" ? null : (DateTime?)Convert.ToDateTime(input);

                    var newCompany = new Model.Company
                    {
                        Name           = name,
                        FoundationDate = foundationDate
                    };

                    companyController.Create(newCompany);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "2":         //UPDATE
                    Console.WriteLine("ID of company?");
                    int updateId = int.Parse(Console.ReadLine());
                    Console.WriteLine("New Name of the company?");
                    string newName = Console.ReadLine();

                    Console.WriteLine("New foundation date of the company?");
                    DateTime?newFoundationDate;
                    string   newInput = Console.ReadLine();
                    newFoundationDate = newInput == "" ? null : (DateTime?)Convert.ToDateTime(newInput);

                    var updateCompany = new Model.Company
                    {
                        Id             = updateId,
                        Name           = newName,
                        FoundationDate = newFoundationDate
                    };

                    companyController.Update(updateCompany);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "3":         //DELETE
                    Console.WriteLine("Company ID which should be deleted");
                    int deleteId = int.Parse(Console.ReadLine());

                    var deleteCompany = new Model.Company
                    {
                        Id = deleteId
                    };

                    companyController.Delete(deleteId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "4":         //READ
                    Console.WriteLine("------------------------------------------------------------");
                    for (int i = 0; i < companyController.Read().Count; i++)
                    {
                        Console.WriteLine($"ID: {companyController.Read()[i].Id} \nName: {companyController.Read()[i].Name} \nFoundation Date: {companyController.Read()[i].FoundationDate}");
                        Console.WriteLine("------------------------------------------------------------");
                    }

                    var readCompany = new Model.Company
                    {
                    };

                    companyController.Read();

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;
                //case "5": //READONE
                //    Console.WriteLine("------------------------------------------------------------");
                //    Console.WriteLine("Company ID which should be deleted");
                //    int readId = int.Parse(Console.ReadLine());

                //    var companyReadOne = companyController.ReadOneDapper(readId);
                //    Console.WriteLine($"ID: {companyController.ReadOneDapper(readId).Id} \nName: {companyController.ReadOneDapper(readId).Name} \nFoundation Date: {companyController.ReadOneDapper(readId).FoundationDate}");
                //        Console.WriteLine("------------------------------------------------------------");

                //    Console.WriteLine("------------------------------------------------------------");
                //    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                //key = Console.ReadKey();
                //if (key.Key == ConsoleKey.Escape)
                //{
                //    Environment.Exit(0);
                //}
                //    Main(args);
                //    break;
                default:
                    Console.WriteLine("No option for this.");
                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;
                }
                break;

            case "2":     //EMPLOYEE
                Console.WriteLine("Employee options: \nPress 1 for Create\nPress 2 for Update\nPress 3 for Delete\nPress 4 for Read");
                switch (Console.ReadLine())
                {
                case "1":         //CREATE
                    Console.WriteLine("First name of employee");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Second name of employee");
                    string secondName = Console.ReadLine();

                    Console.WriteLine("Birthdate? (E.g.: Jan 15, 2000");
                    DateTime?birthDate;
                    string   input = Console.ReadLine();
                    birthDate = input == "" ? null : (DateTime?)Convert.ToDateTime(input);

                    Console.WriteLine("Department Id?");
                    int departmentId = int.Parse(Console.ReadLine());
                    Console.WriteLine("Address Id?");
                    int addressId = int.Parse(Console.ReadLine());

                    var employeeCreate = employeeController.CreateOrUpdate(firstName, secondName, birthDate, departmentId, addressId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "2":         //UPDATE
                    Console.WriteLine("ID of employee?");
                    int updateId = int.Parse(Console.ReadLine());
                    Console.WriteLine("New first name of employee");
                    string newFirstName = Console.ReadLine();
                    Console.WriteLine("New second name of employee");
                    string newLastName = Console.ReadLine();

                    Console.WriteLine("Birthdate of Employee");
                    DateTime?newBirthDate;
                    string   newInput = Console.ReadLine();
                    newBirthDate = newInput == "" ? null : (DateTime?)Convert.ToDateTime(newInput);

                    Console.WriteLine("Department Id?");
                    int newDepartmentId = int.Parse(Console.ReadLine());
                    Console.WriteLine("Address Id?");
                    int newAddressId = int.Parse(Console.ReadLine());

                    var employeeUpdate = employeeController.CreateOrUpdate(newFirstName, newLastName, newBirthDate, newDepartmentId, newAddressId, updateId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "3":         //DELETE
                    Console.WriteLine("Employee ID which should be deleted");
                    int deleteId       = int.Parse(Console.ReadLine());
                    var employeeDelete = employeeController.Delete(deleteId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "4":         //READ
                    Console.WriteLine("------------------------------------------------------------");
                    for (int i = 0; i < employeeController.Read().Count; i++)
                    {
                        Console.WriteLine($"ID: {employeeController.Read()[i].Id} \nFirst name: {employeeController.Read()[i].FirstName} \nLast name: {employeeController.Read()[i].LastName} " +
                                          $"\nBirth date: {employeeController.Read()[i].BirthDate}");
                        Console.WriteLine("------------------------------------------------------------");
                    }

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                default:
                    Console.WriteLine("No option for this.");
                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;
                }
                break;

            case "3":     //ADDRESS
                Console.WriteLine("Address options: \nPress 1 for Create\nPress 2 for Update\nPress 3 for Delete\nPress 4 for Read");
                switch (Console.ReadLine())
                {
                case "1":         //CREATE
                    Console.WriteLine("Street?");
                    string street = Console.ReadLine();
                    Console.WriteLine("City?");
                    string city = Console.ReadLine();
                    Console.WriteLine("ZIP code?");
                    string ZIP = Console.ReadLine();
                    Console.WriteLine("Country?");
                    string country = Console.ReadLine();

                    var addressCreate = addressController.CreateOrUpdate(street, city, ZIP, country);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "2":         //UPDATE
                    Console.WriteLine("ID of address?");
                    int updateId = int.Parse(Console.ReadLine());
                    Console.WriteLine("New street?");
                    string newStreet = Console.ReadLine();
                    Console.WriteLine("New city?");
                    string newCity = Console.ReadLine();
                    Console.WriteLine("New ZIP code?");
                    string newZIP = Console.ReadLine();
                    Console.WriteLine("New Country?");
                    string newCountry = Console.ReadLine();

                    var addressUpdate = addressController.CreateOrUpdate(newStreet, newCity, newZIP, newCountry, updateId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "3":         //DELETE
                    Console.WriteLine("Address ID which should be deleted");
                    int deleteId      = int.Parse(Console.ReadLine());
                    var addressDelete = addressController.Delete(deleteId);

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                case "4":         //READ
                    Console.WriteLine("------------------------------------------------------------");
                    for (int i = 0; i < addressController.Read().Count; i++)
                    {
                        Console.WriteLine($"ID: {addressController.Read()[i].Id} \nStreet: {addressController.Read()[i].Street} \nCity: {addressController.Read()[i].City} " +
                                          $"\nZIP {addressController.Read()[i].ZIP} \nCountry {addressController.Read()[i].Country}");
                        Console.WriteLine("------------------------------------------------------------");
                    }

                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;

                default:
                    Console.WriteLine("No option for this.");
                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                    Main(args);
                    break;
                }
                break;

            default:
                Console.WriteLine("No option for this.");
                Console.WriteLine("------------------------------------------------------------");
                Console.WriteLine("Press any key to go back to menu or ESCP to exit");
                var key1 = Console.ReadKey();
                if (key1.Key == ConsoleKey.Escape)
                {
                    Environment.Exit(0);
                }
                Main(args);
                break;
            }
        }