Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/Naren_Coding_Evaluation/v17/.wsuo
Binary file not shown.
4 changes: 4 additions & 0 deletions dotnet/MyOrganization/MyOrganization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
Expand Down
56 changes: 52 additions & 4 deletions dotnet/MyOrganization/Organization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down