Skip to content
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
45 changes: 44 additions & 1 deletion dotnet/MyOrganization/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,6 +9,7 @@ namespace MyOrganization
internal abstract class Organization
{
private Position root;
private int empId = 0;

public Organization()
{
Expand All @@ -27,9 +28,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()
{
return PrintOrganization(root, "");
Expand Down