Exemplo n.º 1
0
        public void GetAllDepartmentsTest()
        {
            DepartmentRepository departmentRepository = new DepartmentRepository();
            Department           department1          = new Department
            {
                DepartmentID = 98,
                Name         = "TestDepartmentName1",
                GroupName    = "TestGroupName1",
                ModifiedDate = DateTime.Now
            };
            Department department2 = new Department
            {
                DepartmentID = 99,
                Name         = "TestDepartmentName2",
                GroupName    = "TestGroupName2",
                ModifiedDate = DateTime.Now
            };

            departmentRepository.AddDepartment(department1);
            departmentRepository.AddDepartment(department2);
            Assert.IsTrue(departmentRepository.GetAllDepartments().ToArray().Length >= 2);
            Assert.AreEqual("TestDepartmentName1", departmentRepository.GetAllDepartments().ToArray()[departmentRepository.GetAllDepartments().ToArray().Length - 2].Name);
            Assert.AreEqual("TestDepartmentName2", departmentRepository.GetAllDepartments().ToArray()[departmentRepository.GetAllDepartments().ToArray().Length - 1].Name);
            departmentRepository.DeleteDepartmentByName("TestDepartmentName1");
            departmentRepository.DeleteDepartmentByName("TestDepartmentName2");
        }
Exemplo n.º 2
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtDeptNo.Text != "" && txtDeptName.Text != "" && txtDeptLocation.Text != "")
     {
         _deptRepository.AddDepartment(Convert.ToInt32(txtDeptNo.Text), txtDeptName.Text, txtDeptLocation.Text);
     }
 }
Exemplo n.º 3
0
        public ActionResult AddDepartment(Department department)
        {
            string messages = "";

            try
            {
                if (ModelState.IsValid)
                {
                    bool isSaved = _departmentRepository.AddDepartment(department);

                    if (isSaved)
                    {
                        messages    = "Department Saved Successfully";
                        ViewBag.SMs = messages;
                    }
                }

                messages = Utility.GetModelStateError(ModelState);
                return(View());
            }
            catch (Exception exception)
            {
                messages    = exception.Message;
                ViewBag.SMg = messages;
                return(View());
            }
        }
 public ActionResult Create(Department department)
 {
     {
         DepartmentRepository departmentRepo = new DepartmentRepository();
         departmentRepo.AddDepartment(department);
         return(RedirectToAction(nameof(Index)));
     }
 }
        public ActionResult Create(Department dept)
        {
            _departmentRepository.AddDepartment(dept);

            Alert("Success", "Department added successfully", Enums.NotificationType.success);

            return(RedirectToAction("Index", _data));
        }
 public ActionResult Create(Department dep)
 {
     try
     {
         d.AddDepartment(dep);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 7
0
        public ActionResult Create(Department model)
        {
            if (ModelState.IsValid)
            {
                var Db = new ApricotContext();
                DepartmentRepository repo = new DepartmentRepository(Db);
                repo.AddDepartment(model);
                return(RedirectToAction("Index"));
            }

            //Something Went wrong, redisplay form
            return(View(model));
        }
Exemplo n.º 8
0
        public bool AddNewDepartment(string dept_name)
        {
            if (_context.Departments.Where(a => a.Dept_Name == dept_name).Single() != null)
            {
                return(false);
            }
            Department dept = new Department()
            {
                Dept_Name = dept_name
            };
            DepartmentRepository _dept = new DepartmentRepository(_context);

            _dept.AddDepartment(dept);
            return(true);
        }
Exemplo n.º 9
0
        public string Department(Department department)
        {
            //return View();
            DepartmentRepository departmentRepository = new DepartmentRepository();

            bool   isSaved  = departmentRepository.AddDepartment(department);
            string messages = "";

            if (isSaved)
            {
                messages = "Department Saved Successfully";
            }

            return(messages);
        }
Exemplo n.º 10
0
        public void AddDepartmentTest()
        {
            DepartmentRepository departmentRepository = new DepartmentRepository();
            Department           department           = new Department
            {
                DepartmentID = 98,
                Name         = "TestDepartmentName",
                GroupName    = "TestGroupName",
                ModifiedDate = DateTime.Now
            };
            int amount = departmentRepository.GetAllDepartments().ToArray().Length;

            departmentRepository.AddDepartment(department);
            Assert.AreEqual(amount + 1, departmentRepository.GetAllDepartments().ToArray().Length);
            departmentRepository.DeleteDepartmentByName("TestDepartmentName");
        }
Exemplo n.º 11
0
        public void GetDepartmentTest()
        {
            DepartmentRepository departmentRepository = new DepartmentRepository();
            Department           department           = new Department
            {
                DepartmentID = 98,
                Name         = "TestDepartmentName",
                GroupName    = "TestGroupName",
                ModifiedDate = DateTime.Now
            };
            string groupName = department.GroupName;

            departmentRepository.AddDepartment(department);
            Assert.AreEqual(groupName, departmentRepository.GetDepartmentByName("TestDepartmentName").GroupName);
            departmentRepository.DeleteDepartmentByName("TestDepartmentName");
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            var repo      = new EmployeeRepository();
            var employees = repo.GetAllEmployees();

            foreach (var employee in employees)
            {
                Console.WriteLine($"{employee.FirstName} {employee.LastName} is in {employee.Department.DeptName}");
            }

            Console.WriteLine("Let's get an employee with the ID 2");

            var employeeWithId2 = repo.GetEmployeeById(2);

            Console.WriteLine($"Employee with Id 2 is {employeeWithId2.FirstName} {employeeWithId2.LastName}");

            DepartmentRepository departmentRepo = new DepartmentRepository();

            Console.WriteLine("Getting All Departments:");
            Console.WriteLine();

            List <Department> allDepartments = departmentRepo.GetAllDepartments();

            foreach (Department dept in allDepartments)
            {
                Console.WriteLine($"{dept.Id} {dept.DeptName}");
            }

            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Department with Id 1");

            Department singleDepartment = departmentRepo.GetDepartmentById(1);

            Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}");


            Department legalDept = new Department
            {
                DeptName = "Legal"
            };

            departmentRepo.AddDepartment(legalDept);

            Console.WriteLine("-------------------------------");
            Console.WriteLine("Added the new Legal Department!");
        }
Exemplo n.º 13
0
        public static void CollectInput()
        {
            Console.Clear();

            DepartmentRepository departmentRepo = new DepartmentRepository();

            Console.WriteLine("Please enter the name of the department you'd like to add:");
            Console.Write("> ");
            var option = Console.ReadLine();

            Department department = new Department()
            {
                DeptName = option
            };

            departmentRepo.AddDepartment(department);
            Console.WriteLine($"The {option} department has been added to the departments!");

            Console.WriteLine("\nEnter anything to return to the main menu");
            Console.ReadLine();
        }
Exemplo n.º 14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(deptCdTextBox.Text.Trim()))
            {
                MessageBox.Show("Please enter Department Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                deptCdTextBox.Focus();
                return;
            }
            if (String.IsNullOrEmpty(deptNmTextBox.Text.Trim()))
            {
                MessageBox.Show("Please enter Department Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                deptCdTextBox.Focus();
                return;
            }
            Department department = new Department();

            department.DeptCd    = deptCdTextBox.Text.ToUpper();
            department.DeptNm    = deptNmTextBox.Text.ToUpper();
            department.CreatedBy = "Test";
            DepartmentRepository repository = new DepartmentRepository();

            if (repository.GetDepartment(deptCdTextBox.Text) != null)
            {
                MessageBox.Show("Sorry, Department Code provided already exists in database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                deptCdTextBox.Focus();
                return;
            }
            if (repository.AddDepartment(department))
            {
                MessageBox.Show("Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                deptCdTextBox.Text = deptNmTextBox.Text = "";
                deptCdTextBox.Focus();
            }
            else
            {
                MessageBox.Show("Error Occurred, Please try Again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                deptCdTextBox.Focus();
            }
        }
 public void AddDepartment()
 {
     Task.Run(() =>
     {
         try
         {
             Department temp = new Department
             {
                 Name         = Name,
                 GroupName    = GroupName,
                 ModifiedDate = ModifiedDate
             };
             DepartmentRepository.AddDepartment(temp);
             Name         = "";
             GroupName    = "";
             ModifiedDate = DateTime.Now;
             ShowPopupWindow("Department added successfully.");
         }
         catch (Exception e)
         {
             ShowPopupWindow("Adding department failed.\nERROR: " + e.Message);
         }
     });
 }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Welcome User! Choose from Menu");
                Console.WriteLine("-------------------------------");
                Console.WriteLine("1. Show All Departments");
                Console.WriteLine("2. Add New Department");
                Console.WriteLine("3. Change Existing Department");
                Console.WriteLine("4. Show All Employees");
                Console.WriteLine("5. Show Employee by Id");
                Console.WriteLine("6. Add Employee");
                Console.WriteLine("7. Change Existing Employee");
                Console.WriteLine("8. Show Departments by Id with Employees");

                var choice = Console.ReadLine();
                DepartmentRepository departmentRepo = new DepartmentRepository();
                EmployeeRepository   employeeRepo   = new EmployeeRepository();

                switch (Int32.Parse(choice))
                {
                case 1:

                    Console.WriteLine("Getting All Departments:");
                    Console.WriteLine();

                    List <Department> allDepartments = departmentRepo.GetAllDepartments();

                    foreach (Department dept in allDepartments)
                    {
                        Console.WriteLine($"{dept.Id} {dept.DeptName}");
                    }
                    break;

                case 2:

                    Console.WriteLine("New Department Name");
                    var        departmentName = Console.ReadLine();
                    Department newDepartment  = new Department
                    {
                        DeptName = departmentName
                    };

                    departmentRepo.AddDepartment(newDepartment);
                    Console.WriteLine($"Added the new {departmentName} Department!");
                    break;

                    //case 3:
                    //    Console.WriteLine("Update or Delete Department");
                    //    var DeptChangeChoice = int.Parse(Console.ReadLine());

                    //    Console.WriteLine("1. Update");
                    //    Console.WriteLine("2. Delete");

                    //    string option = Console.ReadLine();

                    //    if (option == "1")
                    //    {
                    //        Console.WriteLine("Choose a Department By Id");

                    //        List<Department> allDepts = departmentRepo.GetAllDepartments();

                    //        foreach (Department dept in allDepts)
                    //        {
                    //            Console.WriteLine($"{dept.Id} {dept.DeptName}");
                    //        }

                    //        Department singleDepartment = departmentRepo.GetDepartmentById(DeptChangeChoice);
                    //        Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}");
                    //        break;


                    //    }
                    //    else if (option == "2")
                    //    {
                    //Console.WriteLine("Choose a Department By Id");

                    //List<Department> allDepts = departmentRepo.GetAllDepartments();

                    //foreach (Department dept in allDepts)
                    //{
                    //    Console.WriteLine($"{dept.Id} {dept.DeptName}");
                    //}

                    //Department singleDepartment = departmentRepo.DeleteDepartment(DeptChangeChoice);
                    //Console.WriteLine($"We have Deleted {singleDepartment.Id} {singleDepartment.DeptName}");
                    //}
                }
            }

            //DepartmentRepository departmentRepo = new DepartmentRepository();

            //Console.WriteLine("Getting All Departments:");
            //Console.WriteLine();

            //List<Department> allDepartments = departmentRepo.GetAllDepartments();

            //foreach (Department dept in allDepartments)
            //{
            //    Console.WriteLine($"{dept.Id} {dept.DeptName}");
            //}

            //Console.WriteLine("----------------------------");
            //Console.WriteLine("Getting Department with Id 1");

            //Department singleDepartment = departmentRepo.GetDepartmentById(1);

            //Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}");

            //Department legalDept = new Department
            //{
            //    DeptName = "Legal"
            //};

            //departmentRepo.AddDepartment(legalDept);

            //Console.WriteLine("-------------------------------");
            //Console.WriteLine("Added the new Legal Department!");


            //EmployeeRepository employeeRepo = new EmployeeRepository();


            //Console.WriteLine("Getting All Employees:");
            //Console.WriteLine();

            //List<Employee> allEmployees = employeeRepo.GetAllEmployees();

            //foreach (Employee emp in allEmployees)
            //{
            //    Console.WriteLine($"{emp.Id} {emp.FirstName}");
            //}
        }
        static void Main(string[] args)
        {
            // Below this point is the start of the departments


            DepartmentRepository departmentRepo = new DepartmentRepository();

            Console.WriteLine("Getting All Departments:");;

            Console.WriteLine();

            List <Department> allDepartments = departmentRepo.GetAllDepartments();

            foreach (Department dept in allDepartments)
            {
                Console.WriteLine($"{dept.Id} {dept.DeptName}");

                Console.WriteLine("----------------------------");
                Console.WriteLine("Getting Department with Id 1");

                Department singleDepartment = departmentRepo.GetDepartmentById(1);

                Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}");
            }

            Department legalDept = new Department
            {
                DeptName = "Legal"
            };

            departmentRepo.AddDepartment(legalDept);

            Console.WriteLine("-------------------------------");
            Console.WriteLine("Added the new Legal Department!");


            // Below this point is the start of the employees


            EmployeeRepository employeeRepo = new EmployeeRepository();

            Console.WriteLine("Getting All Employees:");;

            Console.WriteLine();

            List <Employee> allEmployees = employeeRepo.GetAllEmployees();

            foreach (Employee emp in allEmployees)
            {
                Console.WriteLine($"{emp.Id} {emp.FirstName} {emp.LastName}");

                Console.WriteLine("----------------------------");
                Console.WriteLine("Getting Employee with Id 1");

                Employee singleEmployee = employeeRepo.GetEmployeeById(1);

                Console.WriteLine($"{singleEmployee.Id} {singleEmployee.FirstName} {singleEmployee.FirstName}");
            }

            Employee samSmith = new Employee
            {
                FirstName = "Sam",
                LastName  = "Smith"
            };

            employeeRepo.AddEmployee(samSmith);

            Console.WriteLine("-------------------------------");
            Console.WriteLine("Added the new Employee!");
        }
Exemplo n.º 18
0
 public void AddDepartment(Department department)
 {
     repository.AddDepartment(department);
 }
Exemplo n.º 19
0
 protected void btnAddDept_Click(object sender, EventArgs e)
 {
     deptrepo.AddDepartment(Convert.ToInt32(txtDeptNo.Text), txtDepName.Text, txtDeptLocation.Text);
 }
 public void AddDepartment(Department department)                //Add Department to database
 {
     repository.AddDepartment(department);
 }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            //Authored by & stolen from James Nitz
            //For educational purposes only

            //Setting a new instance of the employee repository and dept repo to a variable. Remeber to use the using statement at the top!
            var repo     = new EmployeeRepository();
            var deptRepo = new DepartmentRepository();
            //That both classes has method that gets all employees. Use it and store all them employees in a var.


            var employeeWithId2 = repo.GetEmployeeById(2);


            while (true)
            {
                var departments = deptRepo.GetAllDepartments();
                var employees   = repo.GetAllEmployeesWithDepartment();
                Console.WriteLine("Welcome to muh Database!!");
                Console.WriteLine("Press 1 for Departments");
                Console.WriteLine("Press 2 for Employee");
                Console.WriteLine("Press 3 for a full report");
                Console.WriteLine("Press 4 to get outta here");

                string option = Console.ReadLine();

                if (option == "1")
                {
                    Console.Clear();
                    Console.WriteLine("---DEPARTMENTS---");
                    Console.WriteLine("Press 1 to add a Department");
                    Console.WriteLine("Press 2 to add a Delete");
                    Console.WriteLine("Press 3 to return");
                    string deptOption = Console.ReadLine();

                    switch (Int32.Parse(deptOption))
                    {
                    case 1:
                        Console.Clear();
                        Console.WriteLine("Name of Department?");
                        var        deptNameInput = Console.ReadLine();
                        Department newDepartment = new Department()
                        {
                            DeptName = deptNameInput
                        };
                        deptRepo.AddDepartment(newDepartment);
                        break;

                    case 2:
                        Console.Clear();
                        Console.WriteLine("Delete which Department?");
                        for (var i = 0; i < departments.Count; i++)
                        {
                            Console.WriteLine($"{departments[i].Id}  {departments[i].DeptName}");
                        }
                        var deleteDeptInput = Int32.Parse(Console.ReadLine());
                        try
                        {
                            deptRepo.DeleteDepartment(deleteDeptInput);
                            break;
                        }
                        catch
                        {
                            Console.Clear();
                            Console.WriteLine("Cannot delete department with working employees.");
                            Console.WriteLine("Please fire or transfer:");
                            Console.WriteLine("");
                            foreach (var employee in employees)
                            {
                                if (employee.DepartmentId == deleteDeptInput)
                                {
                                    Console.WriteLine($"{employee.FirstName} {employee.LastName}");
                                }
                            }
                            Console.WriteLine("Press enter to return");
                            Console.ReadLine();
                            break;
                        }

                    case 3:
                        break;

                    default:
                        break;
                    }
                }
                else if (option == "2")
                {
                    Console.Clear();
                    Console.WriteLine("---EMPLOYEES---");
                    Console.WriteLine("Press 1 to add an employee");
                    Console.WriteLine("Press 2 to Fire an Employee");
                    Console.WriteLine("Press 3 to update an employee");
                    Console.WriteLine("Press 4 to return");
                    string empOption = Console.ReadLine();

                    switch (Int32.Parse(empOption))
                    {
                    case 1:
                        Console.Clear();
                        Console.WriteLine("First name of Employee?");
                        var employeeFirstNameInput = Console.ReadLine();
                        Console.WriteLine("Last Name of Employee?");
                        var employeeLastNameInput = Console.ReadLine();
                        Console.WriteLine("Which Department do they work in?");
                        foreach (var dept in departments)
                        {
                            Console.WriteLine($"{dept.Id} {dept.DeptName}");
                        }
                        var employeeDeptChoice = Console.ReadLine();
                        var selectedDept       = departments.Where(dept => int.Parse(employeeDeptChoice) == dept.Id).FirstOrDefault();

                        Employee newEmployee = new Employee()
                        {
                            FirstName = employeeFirstNameInput, LastName = employeeLastNameInput, DepartmentId = selectedDept.Id
                        };
                        repo.AddEmployee(newEmployee);
                        break;

                    case 2:
                        Console.Clear();
                        Console.WriteLine("Fire which Employee?");
                        for (var i = 0; i < employees.Count; i++)
                        {
                            Console.WriteLine($"{employees[i].Id}  {employees[i].FirstName} {employees[i].LastName}");
                        }
                        var deleteEmployeeInput = Int32.Parse(Console.ReadLine());
                        repo.DeleteEmployee(deleteEmployeeInput);
                        break;

                    case 3:
                        Console.Clear();
                        Console.WriteLine("Who you want to update?");
                        for (var i = 0; i < employees.Count; i++)
                        {
                            Console.WriteLine($"{employees[i].Id}  {employees[i].FirstName} {employees[i].LastName}");
                        }
                        var updateEmployeeInput = Int32.Parse(Console.ReadLine());
                        var selectedEmployee    = repo.GetEmployeeById(updateEmployeeInput);
                        Console.Clear();
                        Console.WriteLine($"{selectedEmployee.FirstName} {selectedEmployee.LastName} who works in {selectedEmployee.Department.DeptName}");
                        Console.WriteLine("");
                        Console.WriteLine("What would you like to update?");
                        Console.WriteLine("1. Name");
                        Console.WriteLine("2. Department");
                        var selectedUpdateInput = Console.ReadLine();
                        switch (Int32.Parse(selectedUpdateInput))
                        {
                        case 1:
                            Console.WriteLine("Enter in new first name?");
                            var newFirstName = Console.ReadLine();
                            Console.WriteLine("Enter in new last name?");
                            var newLastName = Console.ReadLine();
                            selectedEmployee.FirstName = newFirstName;
                            selectedEmployee.LastName  = newLastName;
                            repo.UpdateEmployee(selectedEmployee.Id, selectedEmployee);
                            break;

                        case 2:
                            Console.WriteLine("What department do they work in now?");
                            for (var i = 0; i < departments.Count; i++)
                            {
                                Console.WriteLine($"{departments[i].Id}  {departments[i].DeptName}");
                            }
                            var selectedDeptInput = Int32.Parse(Console.ReadLine());

                            var newDept = departments.FirstOrDefault(dept => dept.Id == selectedDeptInput);
                            selectedEmployee.DepartmentId = newDept.Id;
                            repo.UpdateEmployee(selectedEmployee.Id, selectedEmployee);
                            break;

                        default:
                            break;
                        }



                        break;

                    case 4:
                        break;

                    default:
                        break;
                    }
                }
                else if (option == "3")
                {
                    Console.Clear();
                    Console.WriteLine("------------------");
                    foreach (var dept in departments)
                    {
                        Console.WriteLine($"{dept.DeptName} has the following employees:");
                        foreach (var employee in employees)
                        {
                            if (employee.DepartmentId == dept.Id)
                            {
                                Console.WriteLine($"{employee.FirstName} {employee.LastName}");
                            }
                        }
                    }
                    Console.WriteLine("------------------");
                }
                else
                {
                    Console.WriteLine("See ya Later");
                    break;
                }
            }
        }
 public int Add(Departments _Department)
 {
     return(_DepartmentRepository.AddDepartment(_Department));
 }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var departmentRepo = new DepartmentRepository();
            var allDepartments = departmentRepo.GetAllDepartments();

            Console.WriteLine("All Departments");
            Console.WriteLine("------------------");
            foreach (var dept in allDepartments)
            {
                Console.WriteLine(dept.DepartmentName);
            }

            var hardCodedId = 3;

            var departmentWithId3 = departmentRepo.GetDepartmentById(hardCodedId);

            Console.WriteLine("-------");
            Console.WriteLine($"Department with id {hardCodedId} is {departmentWithId3.DepartmentName}");

            var employeeRepo = new EmployeeRepository();
            var allEmployees = employeeRepo.GetAllEmployees();

            Console.WriteLine("All Employees");
            Console.WriteLine("------------------");
            foreach (var emp in allEmployees)
            {
                Console.WriteLine(emp.FirstName);
                Console.WriteLine(emp.LastName);
            }

            var empHardCodedId = 3;

            var employeeWithId3 = employeeRepo.GetEmployeeById(empHardCodedId);

            Console.WriteLine("-------");
            Console.WriteLine($"{employeeWithId3.FirstName} {employeeWithId3.LastName}");

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

            var allEmployeesWithDept = employeeRepo.GetAllEmployeesWithDepartment();

            Console.WriteLine("Employees with departments");
            foreach (var emp in allEmployeesWithDept)
            {
                Console.WriteLine(emp.FirstName);
                Console.WriteLine(emp.LastName);
                Console.WriteLine(emp.DepartmentId);
                // Console.WriteLine(emp.Department);
            }

            var legal = new Department();

            Console.WriteLine("What department would you like to add?");


            legal.DepartmentName = Console.ReadLine();

            departmentRepo.AddDepartment(legal);

            Console.WriteLine("What Department (ID) would you like to update?");
            var departmentToUpdate = Int32.Parse(Console.ReadLine());

            Console.WriteLine("What should the new department name be called?");
            var newDepartmentName = Console.ReadLine();

            departmentRepo.UpdateDepartment(departmentToUpdate, new Department {
                DepartmentName = newDepartmentName
            });
        }
Exemplo n.º 24
0
 public void SaveDepartment(Department dept)
 {
     deptRepo.AddDepartment(dept);
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            //Department
            var departmentRepo = new DepartmentRepository();
            var allDepartments = departmentRepo.GetAllDepartments();

            Console.WriteLine("All Departments");
            Console.WriteLine("---------------");
            foreach (var dept in allDepartments)
            {
                Console.WriteLine(dept.DepartmentName);
            }

            var hardCodedId      = 2;
            var departmentWithId = departmentRepo.GetDepartmentById(hardCodedId);

            Console.WriteLine("---------------");
            Console.WriteLine($"Department with id {hardCodedId} is {departmentWithId.DepartmentName}");
            Console.WriteLine("---------------");

            //Employee List
            var employeeRepo = new EmployeeRepository();
            var allEmployee  = employeeRepo.GetAllEmployees();

            Console.WriteLine("All Employees");
            Console.WriteLine("---------------");
            foreach (var employee in allEmployee)
            {
                Console.WriteLine($"{employee.FirstName} {employee.LastName}");
            }

            var hardCodedEmployeeId = 2;
            var employeeWithId      = employeeRepo.GetEmployeeById(hardCodedEmployeeId);

            Console.WriteLine("---------------");
            Console.WriteLine($"Department with id {hardCodedEmployeeId} is {employeeWithId.FirstName} {employeeWithId.LastName}");

            //Employee with Department

            var allEmployeeRepo           = new EmployeeRepository();
            var allEmployeeWithDepartment = allEmployeeRepo.GetAllEmployeesWithDepartment();

            Console.WriteLine("All Employees");
            Console.WriteLine("---------------");
            foreach (var employee in allEmployeeWithDepartment)
            {
                Console.WriteLine($"{employee.FirstName} {employee.LastName} works in {employee.EmployeeDepartment}");
            }

            Console.WriteLine("--------------------");

            //Add Department

            var legal = new Department();

            Console.WriteLine("What department do you like to add?");
            legal.DepartmentName = Console.ReadLine();
            departmentRepo.AddDepartment(legal);
            //Update Department
            Console.WriteLine("What Department (ID) would you like to update?");
            var departmentToUpdate = Int32.Parse(Console.ReadLine());

            Console.WriteLine("What should the new department name be called?");
            var newDepartmentName = Console.ReadLine();

            departmentRepo.UpdateDepartment(departmentToUpdate, new Department {
                DepartmentName = newDepartmentName
            });

            //Delete Department
            Console.WriteLine("What department do you want to delete?");
            var deleteDept = int.Parse(Console.ReadLine());

            departmentRepo.DeleteDepartment(deleteDept);

            Console.WriteLine("--------------------");
            //Add Employee
            var newEmployee = new Employee();

            Console.WriteLine("What is your first name?");
            newEmployee.FirstName = Console.ReadLine();
            Console.WriteLine("What is your last name?");
            newEmployee.LastName = Console.ReadLine();
            Console.WriteLine("What department do you want to work?");
            newEmployee.DepartmentId = Int32.Parse(Console.ReadLine());

            employeeRepo.AddEmployee(newEmployee);

            //Update Employee

            Console.WriteLine("Which Employee (ID) would you like to update?");
            var employeeToUpdate = Int32.Parse(Console.ReadLine());

            var updateEmployee = new Employee();

            Console.WriteLine("What is your first name?");
            updateEmployee.FirstName = Console.ReadLine();
            Console.WriteLine("What is your last name?");
            updateEmployee.LastName = Console.ReadLine();
            Console.WriteLine("What department do you want to work?");
            updateEmployee.DepartmentId = Int32.Parse(Console.ReadLine());

            employeeRepo.UpdateEmployee(employeeToUpdate, updateEmployee);

            //Delete Employee
            Console.WriteLine("Which employee do you want to delete?");
            var deleteEmp = int.Parse(Console.ReadLine());

            employeeRepo.DeleteEmployee(deleteEmp);
        }