diff --git a/.vs/Naren_Coding_Evaluation/v17/.wsuo b/.vs/Naren_Coding_Evaluation/v17/.wsuo new file mode 100644 index 0000000..73f5e50 Binary files /dev/null and b/.vs/Naren_Coding_Evaluation/v17/.wsuo differ diff --git a/dotnet/MyOrganization/MyOrganization.cs b/dotnet/MyOrganization/MyOrganization.cs index 9a354ca..9699e17 100644 --- a/dotnet/MyOrganization/MyOrganization.cs +++ b/dotnet/MyOrganization/MyOrganization.cs @@ -33,6 +33,8 @@ override protected Position CreateOrganization() vpt.AddDirectReport(dct); Position s = new Position("Salesperson"); vps.AddDirectReport(s); + Position pm = new Position("Product Manager"); + vps.AddDirectReport(pm); return ceo; } @@ -46,6 +48,8 @@ static void Main() org.Hire(new Name("Bill", "Lumbergh"), "Director Customer Technology"); org.Hire(new Name("Ford", "Prefect"), "VP Marketing"); org.Hire(new Name("Jane", "Seller"), "VP Sales"); + org.Hire(new Name("Naren", "Reddy"), "Product Manager"); + org.Hire(new Name("Vijay", "Virup"), "President"); org.Hire(new Name("Bean", "Counter"), "VP Finance"); org.Hire(new Name("Victoria", "Sinclair"), "CIO"); org.Hire(new Name("Head", "Geek"), "VP Technology"); diff --git a/dotnet/MyOrganization/Organization.cs b/dotnet/MyOrganization/Organization.cs index 7480481..c3111b2 100644 --- a/dotnet/MyOrganization/Organization.cs +++ b/dotnet/MyOrganization/Organization.cs @@ -24,12 +24,60 @@ public Organization() * @param title * @return the newly filled position or empty if no position has that title */ - public Position? Hire(Name person, string title) - { - //your code here - return null; + public Position? Hire(Name person, string title) + { + Position? targetPosition = FindPositionByTitle(root, title); + + if (targetPosition != null) + { + if (targetPosition.IsFilled()) + { + Employee? previousEmployee = targetPosition.GetEmployee(); + Console.WriteLine($"Position '{title}' is already filled by {previousEmployee}. Cannot hire {person}."); + return null; + } + + Employee newEmployee = new Employee(GetNextEmployeeIdentifier(), person); + targetPosition.SetEmployee(newEmployee); + + Console.WriteLine($"Hired {person} as '{title}'."); + return targetPosition; + } + + Console.WriteLine($"No position found with the title '{title}'. Cannot hire {person}."); + return null; + } + + private Position? FindPositionByTitle(Position currentPosition, string title) + { + if (currentPosition.GetTitle() == title) + { + return currentPosition; + } + + foreach (Position directReport in currentPosition.GetDirectReports()) + { + Position? targetPosition = FindPositionByTitle(directReport, title); + if (targetPosition != null) + { + return targetPosition; + } + } + + return null; } + + + + private int nextEmployeeId = 1000; // Starting employee ID + + private int GetNextEmployeeIdentifier() + { + int employeeId = nextEmployeeId; + nextEmployeeId++; // Increment the employee ID for the next employee + return employeeId; + } override public string ToString() { return PrintOrganization(root, "");