Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hire Method Changes #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 44 additions & 2 deletions dotnet/MyOrganization/Organization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MyOrganization
internal abstract class Organization
{
private Position root;

private int empId = 0;
public Organization()
{
root = CreateOrganization();
Expand All @@ -26,9 +26,51 @@ public Organization()
*/
public Position? Hire(Name person, string title)
{
//your code here

Position? position = GetPosition(title, root);

if (position != null)
{
//Checking for availed position
if (!position.IsFilled())
{
//New hiring
Employee newEmployee = new Employee(GetId(), person);
position.SetEmployee(newEmployee);
return position;
}
}
return null;
}
/// <summary>
/// To get the position that has the title
/// </summary>
/// <param name="title"></param>
/// <param name="currentPosition"></param>
/// <returns></returns>
private Position? GetPosition(string title, Position currentPosition)
{
if (currentPosition.GetTitle() != title)
{
foreach (Position? position in from Position pos in currentPosition.GetDirectReports()
let position = GetPosition(title, pos)
where position != null
select position)
{
return position;
}

return null;
}

return currentPosition;
}

private int GetId()
{
empId++;
return empId;
}

override public string ToString()
{
Expand Down