From ff893f8e7bb874469c3637d963b9ad8c047c06c9 Mon Sep 17 00:00:00 2001 From: jbalusu4341 <89986520+jbalusu4341@users.noreply.github.com> Date: Fri, 19 May 2023 12:26:39 -0500 Subject: [PATCH] Implemented Hire method Done --- dotnet/MyOrganization/Organization.cs | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/dotnet/MyOrganization/Organization.cs b/dotnet/MyOrganization/Organization.cs index e288ef8..5504820 100644 --- a/dotnet/MyOrganization/Organization.cs +++ b/dotnet/MyOrganization/Organization.cs @@ -10,6 +10,8 @@ internal abstract class Organization { private Position root; + static int identifier = 1; + public Organization() { root = CreateOrganization(); @@ -26,8 +28,35 @@ public Organization() */ public Position? Hire(Name person, string title) { - //your code here - return null; + var p = getPositionhasTitle(root, title); + if (p == null) + return null; + + var emp = new Employee(identifier++, person); + p.SetEmployee(emp); + return p; + } + private Position? getPositionhasTitle(Position p, string title) + { + Position pos = null; + if (p != null) + { + if (p.GetTitle() == title) + return p; + foreach (Position position in p.GetDirectReports()) + { + if (pos != null) + break; + if (position.GetTitle() == title) + { + pos = position; + break; + } + + pos = getPositionhasTitle(position, title); + } + } + return pos; } override public string ToString()