Skip to content

Commit

Permalink
Hire Method Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kulsumayesha committed Oct 24, 2023
1 parent 41127a6 commit c3dd331
Showing 1 changed file with 44 additions and 2 deletions.
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

0 comments on commit c3dd331

Please sign in to comment.