public static string AddEmployee(AddEmployeeViewModel param) { string result = string.Empty; //判斷Name是否重複 if (EmployeeRepository.GetEmployeesByName(param.Name) == null) { //新增員工資料 if (!EmployeeRepository.AddEmployee(param)) { result = "新增錯誤"; } } else { result = "名字已新增過"; } return(result); }
public ActionResult Create(Employee employee) { try { if (ModelState.IsValid) { EmployeeRepository EmpRepo = new EmployeeRepository(); EmpRepo.AddEmployee(employee); ViewBag.Message = "Records added successfully."; return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch { return(View()); } }
private static void CreateEmployee(string firstName, string lastName, string city, string country) { EmployeeEntity employee = new EmployeeEntity(); employee.City = city; employee.Country = country; employee.FirstName = firstName; employee.LastName = lastName; employee.CreatedBy = System.Environment.UserName; employee.ModifiedBy = System.Environment.UserName; employee.CreatedDate = DateTime.Now; employee.ModifiedDate = DateTime.Now; using (HiveDataContext hsDataContext = new HiveDataContext()) { IEmployeeRepository empRepository = new EmployeeRepository(hsDataContext); empRepository.AddEmployee(employee); string message = empRepository.SaveChanges(); Console.WriteLine(message); } }
public static void CreateEmployee(Employee employee) { string query = "Create_Employee"; DBConnection.DatabaseName = "CANE"; if (!EmployeeRepository.EmployeeExist(employee)) { if (DBConnection.IsConnected()) { var cmd = new SqlCommand(query, DBConnection.Connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@FirstName_IN", employee.FirstName)); cmd.Parameters.Add(new SqlParameter("@LastName_IN", employee.LastName)); cmd.Parameters.Add(new SqlParameter("@EmployeeRank_IN", employee.Rank.ToString())); cmd.ExecuteReader(); DBConnection.Close(); } EmployeeRepository.AddEmployee(employee); } }
private void OkButtonAddEmployee_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(OIBMaskedTextBoxAddEmployee.Text)) { MessageBox.Show("OIB is a required field!"); } else if (OIBMaskedTextBoxAddEmployee.Text.Length != 11) { MessageBox.Show("An OIB must have 11 numbers!"); } else if (string.IsNullOrEmpty(LastNameTextBoxAddEmployee.Text)) { MessageBox.Show("Last name is a required field!"); } else { var employeeToAdd = new Employee { OIB = OIBMaskedTextBoxAddEmployee.Text, FirstName = FirstNameTextBoxAddEmployee.Text, LastName = LastNameTextBoxAddEmployee.Text, BirthYear = (int)BirthYearUpDownAddEmployee.Value, Restaurant = _employeeRepository.GetRestaurant(_restaurantOfEmployeeName) }; if (MasterChefRadioAddEmployee.Checked) { employeeToAdd.EmployeeRole = Roles.MainChef; } else if (AssistantChefRadioAddEmployee.Checked) { employeeToAdd.EmployeeRole = Roles.AssistantChef; } else { employeeToAdd.EmployeeRole = Roles.Waiter; } _employeeRepository.AddEmployee(employeeToAdd); Close(); } }
public static void Inputdata() { EmployeeRepository repository = new EmployeeRepository(); EmployeeModel model = new EmployeeModel(); model.EmployeeName = "Nilima"; model.Address = "Wadal"; model.BasicPay = 70000; model.Deductions = 500; model.Department = "It"; model.Gender = "F"; model.PhoneNumber = 9090898787; model.NetPay = 73000; model.Tax = 1000; model.StartDate = DateTime.Now; model.TaxablePay = 500; repository.AddEmployee(model); Console.WriteLine(repository.UpdateSalaryIntoDatabase("Nilima", 50000) ? "Update done successfully " : "Update Failed"); }
public static void LoadEmployees() { int employeeID; string rank = null; string firstName = null; string lastName = null; DBConnection.DatabaseName = "CANE"; if (DBConnection.IsConnected()) { string query = "SELECT * FROM Employee"; SqlCommand cmd = new SqlCommand(query, DBConnection.Connection); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { employeeID = (int)reader["EmployeeID"]; rank = reader["EmployeeRank"].ToString(); Rank newRank; if (rank == "Parttimer") { newRank = Rank.parttimer; } else { newRank = Rank.manager; } firstName = reader["FirstName"].ToString(); lastName = reader["LastName"].ToString(); Employee employee = new Employee(employeeID, firstName, lastName, newRank); EmployeeRepository.AddEmployee(employee); } } DBConnection.Close(); } }
private void SaveButton_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { if (employee == null) { employeeRepository.AddEmployee(SurNameTextBox.Text, FirstNameTextBox.Text, PatronymicTextBox.Text, DateOfBirthTimePicker.Value, DocSeriesTextBox.Text, DocNumberTextBox.Text, PositionTextBox.Text, (DbDepartment)DepartmentComboBox.SelectedItem); refreshTable(); Close(); } else { employeeRepository.EditEmployee(employee.ID, SurNameTextBox.Text, FirstNameTextBox.Text, PatronymicTextBox.Text, DateOfBirthTimePicker.Value, DocSeriesTextBox.Text, DocNumberTextBox.Text, PositionTextBox.Text, DepartmentComboBox.SelectedItem.ToString()); refreshTable(); Close(); } } }
public void CreateFullEmployee(FullEmployee model) { Employee employee = new Employee(); EmployeeRepository employeeRepo = new EmployeeRepository(_context); employee.Emp_ID = model.Emp_ID; employee.Emp_Name = model.Emp_Name; employee.Emp_No = model.Emp_No; employee.Dept_ID = Convert.ToInt64(model.Department.Dept_Name.Split('-')[0]); employee.Is_Active = model.Is_Active; employeeRepo.AddEmployee(employee); EmployeeDetailRepository employeeDetailRepo = new EmployeeDetailRepository(_context); Employee_Detail employeeDetail = new Employee_Detail() { Emp_ID = employee.Emp_ID, Emp_Address = model.Emp_Address, Emp_Contact_No = model.Emp_Contact_No, Emp_Gender = model.Emp_Gender }; employeeDetailRepo.AddEmployeeDetail(employeeDetail); }
public static void CollectInput() { Console.Clear(); DepartmentRepository departmentRepo = new DepartmentRepository(); EmployeeRepository employeeRepo = new EmployeeRepository(); Console.WriteLine("Let's make a new Employee"); Console.WriteLine("First Name"); var firstName = Console.ReadLine(); Console.Clear(); Console.WriteLine("Last Name"); var lastName = Console.ReadLine(); Console.Clear(); Console.WriteLine("Dept ID"); var department = Console.ReadLine(); Console.Clear(); Employee newEmployee = new Employee() { FirstName = firstName, LastName = lastName, DepartmentId = int.Parse(department) }; employeeRepo.AddEmployee(newEmployee); Console.WriteLine($"{firstName} has been added to the employees!\n"); Console.WriteLine("\nEnter anything to return to the main menu"); Console.ReadLine(); }
public static void Menu() { try { Console.WriteLine("1.Add Employee"); Console.WriteLine("2.Get Employee By ID"); Console.WriteLine("3.Get All Employees"); Console.WriteLine("4.Delete Employee"); Console.WriteLine("5.Update Employee"); Console.WriteLine("7.Exit"); Console.WriteLine("6.GetName"); Console.WriteLine("Enter your choice"); int choice = int.Parse(Console.ReadLine()); EmployeeRepository repository = new EmployeeRepository(); switch (choice) { case 1: { Employee employee = new Employee() { Eid = 106, Ename = "TIM", Designation = "Programmer", DeptId = "D002" }; repository.AddEmployee(employee); } break; case 2: { Console.WriteLine("Enter Id"); int eid = int.Parse(Console.ReadLine()); Employee employee = repository.GetEmployeeById(eid); if (employee != null) { Console.WriteLine("Name:{0} Designatio:{1}", employee.Ename, employee.Designation); } else { Console.WriteLine("Invalid Employee Id"); } } break; case 3: { repository.GetEmployees(); } break; case 4: { Console.WriteLine("Enter Id"); int eid = int.Parse(Console.ReadLine()); repository.DeleteEmployee(eid); } break; case 5: { Employee employee = new Employee() { Eid = 106, Ename = "TIM", Designation = "Sr Programmer", DeptId = "D002" }; repository.UpdateEmployee(employee.Eid, employee); } break; case 7: { Environment.Exit(0); } break; case 6: { Console.WriteLine("Enter Id"); int eid = int.Parse(Console.ReadLine()); string name = repository.GetEmplyeeName(eid); if (name != null) { Console.WriteLine("Employee Name: " + name); } else { Console.WriteLine("Invalid Id"); } } break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task <int> AddEmployee(Employee employee) { return(await _employeeRepository.AddEmployee(employee)); }
static void Main(string[] args) { EmployeeRepository employeeRepository = new EmployeeRepository(); employeeRepository.AddEmployee(); }
public IActionResult Post(Employee emp) { _repo.AddEmployee(emp); return(Ok("Employee Added")); }
public ActionResult Create_Post([Bind(Exclude = "EmployeePhoneNumber")] Employee employee) { employeeRepository.AddEmployee(employee); TempData["Message"] = "Employee added"; return(RedirectToAction("Index")); }
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 void Add(Employee employee) { employeeRepository.AddEmployee(employee); }
public void AddEmployee(Employee toAdd) { repository.AddEmployee(toAdd); }
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); }
public ActionResult AddEmployee(EmployeeViewModel model, HttpPostedFileBase profpic) { if (ModelState.IsValid) { EMPLOYEE e = new EMPLOYEE(); e.ACTUAL_SALARY = model.ACTUAL_SALARY; e.ADUITING_SALARY = model.ADUITING_SALARY; e.CreatedBy = Session[Constances.UserId] != null?Convert.ToString(Constances.UserId) : ""; e.CreatedDate = DateTime.Now; e.DEPARTMENTID = model.DEPARTMENTID; e.DESIGNATIONID = model.DESIGNATIONID; e.DOB = model.DOB; e.DOJ = model.DOJ; e.EMPCODE = model.EMPCODE; e.EMP_NAME = model.EMP_NAME; e.FATHER_NAME = model.FATHER_NAME; e.MOTHER_NAME = model.MOTHER_NAME; e.GENDER = model.GENDER; e.MARITAL_STATUS = model.MARITAL_STATUS; e.MACCODE = model.MACCODE; e.UNITID = model.UNITID; e.WAGES_TYPEID = model.WAGES_TYPEID; e.ModifiedBy = Session[Constances.UserId] != null?Convert.ToString(Session[Constances.UserId]) : ""; e.ModifiedDate = DateTime.Now; e.Mode = model.Mode; e.IsActive = true; e.IsDeleted = false; EmployeeRepository emp = new EmployeeRepository(); var id = emp.AddEmployee(e); if (id > 0 && profpic != null && profpic.ContentLength > 0) { string[] formats = new string[] { ".jpg", ".png", ".gif", ".jpeg" }; var validfile = formats.Any(item => profpic.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)); if (validfile) { var path = Server.MapPath("~/EmployeeImage"); DirectoryInfo di = new DirectoryInfo(path); if (!di.Exists) { di.Create(); } string filename = id + "_" + profpic.FileName.Replace(" ", "_"); profpic.SaveAs(path + "\\" + filename); var empDetails = emp.UpdateEmployeeImage(id, filename); } } } else { CommonRepository _repo = new CommonRepository(); ViewBag.ListDepartment = _repo.ListDepartment(); ViewBag.ListDesignation = _repo.ListDesignation(); ViewBag.ListUNIT = _repo.ListUNIT(); ViewBag.ListWAGESTYPE = _repo.ListWAGESTYPE(); ViewBag.ListGENDER = new List <SelectListItem> { new SelectListItem { Text = Gender.Male.ToString(), Value = Gender.Male.ToString() }, new SelectListItem { Text = Gender.FeMale.ToString(), Value = Gender.FeMale.ToString() } }; ViewBag.ListMARITALSTATUS = new List <SelectListItem> { new SelectListItem { Text = MARITALSTATUS.Single.ToString(), Value = MARITALSTATUS.Single.ToString() }, new SelectListItem { Text = MARITALSTATUS.Married.ToString(), Value = MARITALSTATUS.Married.ToString() } }; ViewBag.ListMode = new List <SelectListItem> { new SelectListItem { Text = Mode.ACTUAL.ToString(), Value = Mode.ACTUAL.ToString() }, new SelectListItem { Text = Mode.ADUITING.ToString(), Value = Mode.ADUITING.ToString() } }; return(View(model)); } return(RedirectToAction("ListEmployee")); }
private void AddBindings() { Mock <IEmployeeRepository> mock = new Mock <IEmployeeRepository>(); mock.Setup(m => m.Employees).Returns(EmployeeRepository.Employees); mock.Setup(m => m.AddEmployee(It.IsAny <Employee>())).Callback((Employee employee) => EmployeeRepository.AddEmployee(employee)); mock.Setup(m => m.Employee(It.IsAny <int>())).Callback((int empId) => EmployeeRepository.Employee(empId)); kernel.Bind <IEmployeeRepository>().ToConstant(mock.Object); }
public void AddEmployeedata(Employee employee) { repository.AddEmployee(employee); }
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!"); }
public ActionResult Create(EmployeeDatabase employee) { employeeDatabase.AddEmployee(employee); TempData["Message"] = "Employee Added Successfully!"; return(RedirectToAction("Index")); }
public void AddEmployee(Employee employee) //Add Employee into Database { repository.AddEmployee(employee); }
public Guid AddEmployee(Employee employee) { return(employeeRepository.AddEmployee(employee)); }
public int AddEmployee(EmployeeModel employee) { int result = _employeeRepository.AddEmployee(employee); return(result); }
static void Main(string[] args) { 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}"); } 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}"); } EmployeeRepository employeeRepoWithDep = new EmployeeRepository(); Console.WriteLine("Getting All Employees with Departments:"); Console.WriteLine("-----------------------"); List <Employee> allEmployeesWithDept = employeeRepoWithDep.GetAllEmployeesWithDepartment(); foreach (Employee emp in allEmployeesWithDept) { Console.WriteLine($"{emp.Id}: {emp.FirstName} {emp.LastName} in {emp.Department.DeptName} department"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Department with Id 1"); Department singleDepartment = departmentRepo.GetDepartmentById(1); Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); Console.WriteLine("----------------------------"); Console.WriteLine("Getting Employee with Id 1"); Employee singleEmployee = employeeRepo.GetEmployeeById(1); Console.WriteLine($"{singleEmployee.Id}: {singleEmployee.FirstName} {singleEmployee.LastName} in department {singleEmployee.Department.DeptName}"); /* * //ADDING NEW DEPARTMENTS * * Console.WriteLine(); * Console.WriteLine(); * Console.WriteLine(); * * var legal = new Department(); * Console.WriteLine("What Department would you like to make?"); * * legal.DeptName = Console.ReadLine(); * * departmentRepo.AddDepartment(legal); * * //UPDATE DEPARTMENTS * * Console.WriteLine("What department 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 { DeptName = newDepartmentName }); * * //DELETE DEPARTMENTS * * departmentRepo.DeleteDepartment(5); */ //ADDING NEW EMPLOYEES Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); var newEmployee = new Employee(); Console.WriteLine("New Employee Name"); Console.WriteLine(">"); newEmployee.FirstName = Console.ReadLine(); Console.WriteLine("New Employee Last Name"); Console.WriteLine(">"); newEmployee.LastName = Console.ReadLine(); Console.WriteLine("New Employee Department Number"); Console.WriteLine(">"); newEmployee.DepartmentId = Int32.Parse(Console.ReadLine()); employeeRepo.AddEmployee(newEmployee); /* * //UPDATE EMPLOYEE * * Console.WriteLine("Which employee would you like to update?"); * var employeeToUpdate = Int32.Parse(Console.ReadLine()); * * Console.WriteLine("What should the new employee name be?"); * var newEmployeeName = Console.ReadLine(); * * Console.WriteLine("What should the new employee last name be?"); * var newEmployeeLastName = Console.ReadLine(); * * Console.WriteLine("What should the new employee department number be?"); * var newEmployeeDepartmentId = Int32.Parse(Console.ReadLine()); * * employeeRepo.UpdateEmployee(employeeToUpdate, new Employee { FirstName = newEmployeeName, LastName = newEmployeeLastName, * DepartmentId = newEmployeeDepartmentId}); */ //DELETE EMPLOYEE //employeeRepo.DeleteEmployee(4); }
public async Task Handle(CreateEmployeeCommand command) { Employee employee = _mapper.Map <Employee>(command); await Task.Run(() => _employeeRepository.AddEmployee(employee)); }