public override void Execute() { int employeeId = int.Parse(Parameters[0]); int managerId = int.Parse(Parameters[1]); EmployeeManagerDTO dto = new EmployeeManagerDTO() { EmployeeId = employeeId, ManagerId = managerId }; dto = employeeController.SetManager(dto); Console.WriteLine($"{dto.EmployeeName} is now part of {dto.ManagerName}'s team."); }
public EmployeeManagerDTO SetManager(EmployeeManagerDTO dto) { Employee employee = context.Employees.Find(dto.EmployeeId); if (employee == null) { throw new ArgumentException(String.Format(IdNotFound, dto.EmployeeId)); } Employee manager = context.Employees.Find(dto.ManagerId); if (manager == null) { throw new ArgumentException(String.Format(IdNotFound, dto.ManagerId)); } employee.Manager = manager; dto = mapper.Map <EmployeeManagerDTO>(employee); context.SaveChanges(); return(dto); }