From 6098a194cf8d9788cd9264e44b6e99c6cba34ca4 Mon Sep 17 00:00:00 2001 From: Ravivani12kar <148895407+Ravivani12kar@users.noreply.github.com> Date: Tue, 24 Oct 2023 12:00:49 -0700 Subject: [PATCH] Raviram - Proposed changes as per American Airlines Changes done as per request from Hire method --- dotnet/MyOrganization/Organization.cs | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/dotnet/MyOrganization/Organization.cs b/dotnet/MyOrganization/Organization.cs index 7480481..f4bae30 100644 --- a/dotnet/MyOrganization/Organization.cs +++ b/dotnet/MyOrganization/Organization.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,6 +9,7 @@ namespace MyOrganization internal abstract class Organization { private Position root; + private int empId = 0; public Organization() { @@ -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; } + /// + /// To get the position that has the title + /// + /// + /// + /// + 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, "");