public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot pilot = (Pilot)this.pilots .FirstOrDefault(p => p.Name == selectedPilotName && p.GetType().Name == "Pilot"); IMachine machine = (BaseMachine)this.machines.FirstOrDefault(m => m.Name == selectedMachineName); if (pilot == null) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } else if (machine == null) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } else if (machine.Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } else { machine.Pilot = pilot; pilot.AddMachine(machine); return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); } }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { StringBuilder sb = new StringBuilder(); IPilot pilot = pilots.FirstOrDefault(p => p.Name == selectedPilotName); IMachine machine = machines.FirstOrDefault(m => m.Name == selectedMachineName); if (pilot == null) { sb.AppendLine($"{string.Format(OutputMessages.PilotNotFound, selectedPilotName) }"); } else if (machine == null) { sb.AppendLine($"{string.Format(OutputMessages.MachineNotFound, selectedMachineName) }"); } else if (machine != null) { //IPilot machinePilot = machine.Pilot; if (machine.Pilot != null) { sb.AppendLine($"{string.Format(OutputMessages.MachineHasPilotAlready, machine.Name)}"); } else if (machine.Pilot == null) { pilot.AddMachine(machine); machine.Pilot = pilot; sb.AppendLine($"{string.Format(OutputMessages.MachineEngaged, pilot.Name, machine.Name)}"); } } return(sb.ToString().TrimEnd()); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IMachine machine = machines.FirstOrDefault(m => m.Name == selectedMachineName); IPilot pilot = pilots.FirstOrDefault(p => p.Name == selectedPilotName); if (!pilots.Any(p => p.Name == selectedPilotName)) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } else if (!machines.Any(m => m.Name == selectedMachineName)) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } else if (machines.First(m => m.Name == selectedMachineName).Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } else if (machines.First(m => m.Name == selectedMachineName).Pilot is null) { machine.Pilot = pilot; pilot.AddMachine(machine); return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); } return(null); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot pilot = this.pilots.FirstOrDefault(p => p.Name == selectedPilotName); IMachine machine = this.machines.FirstOrDefault(m => m.Name == selectedMachineName); if (pilot == null) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } if (machine == null) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } if (machine.Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } pilot.AddMachine(machine); machine.Pilot = pilot; return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot pilot = this.pilots .FirstOrDefault(p => p.Name == selectedPilotName); if (pilot == null) { return($"Pilot {selectedPilotName} could not be found"); } IMachine machine = this.machines .FirstOrDefault(m => m.Name == selectedMachineName); if (machine == null) { return($"Machine {selectedMachineName} could not be found"); } if (machine.Pilot != null) { return($"Machine {selectedMachineName} is already occupied"); } pilot.AddMachine(machine); machine.Pilot = pilot; return($"Pilot {selectedPilotName} engaged machine {selectedMachineName}"); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { if (this.pilots.ContainsKey(selectedPilotName) == false) { return($"Pilot {selectedPilotName} could not be found"); } if (this.machines.ContainsKey(selectedMachineName) == false) { return($"Machine {selectedMachineName} could not be found"); } //dont know what machine not occupied means //one more if statement IPilot pilot = this.pilots[selectedPilotName]; IMachine machine = this.machines[selectedMachineName]; if (machine.Pilot != null) { return($"Machine {selectedMachineName} is already occupied"); } pilot.AddMachine(machine); machine.Pilot = pilot; return($"Pilot {selectedPilotName} engaged machine {selectedMachineName}"); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { if (!IsThatPilotExist(selectedPilotName)) { return(String.Format( OutputMessages.PilotNotFound, selectedPilotName)); } if (!IsThatMachineExist(selectedMachineName)) { return(String.Format( OutputMessages.MachineNotFound, selectedPilotName)); } IPilot pilot = this.pilots[selectedPilotName]; IMachine machine = this.machines[selectedMachineName]; if (machine.Pilot != null) { return(String.Format( OutputMessages.MachineHasPilotAlready, selectedMachineName)); } pilot.AddMachine(machine); machine.Pilot = pilot; return(String.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot pilot = null; IMachine machine = null; if (!pilots.ContainsKey(selectedPilotName)) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } pilot = pilots[selectedPilotName]; if (!machines.ContainsKey(selectedMachineName)) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } machine = machines[selectedMachineName]; if (machine.Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } pilot.AddMachine(machine); machine.Pilot = pilot; return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IMachine machine = this.machines.FirstOrDefault(x => x.Name == selectedMachineName && x.Pilot == null); string result = string.Empty; IPilot pilot = this.pilots.FirstOrDefault(x => x.Name == selectedPilotName); if (pilot == null) { result = $"Pilot {selectedPilotName} could not be found"; } else if (machine == null) { result = $"Machine {selectedMachineName} could not be found"; } else if (machine.Pilot != null) { result = $"Machine {selectedMachineName} is already occupied"; } else { machine.Pilot = pilot; pilot.AddMachine(machine); result = $"Pilot {selectedPilotName} engaged machine {selectedMachineName}"; } return(result); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot foundPilot = this.pilots .FirstOrDefault(p => p.Name == selectedPilotName); IMachine foundMachine = this.machines .FirstOrDefault(p => p.Name == selectedMachineName); if (foundPilot == null) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } if (foundMachine == null) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } if (foundMachine.Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, foundMachine.Name)); } else { foundPilot.AddMachine(foundMachine); foundMachine.Pilot = foundPilot; return(string.Format(OutputMessages.MachineEngaged, foundPilot.Name, foundMachine.Name)); } }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot repot = pilots.FirstOrDefault(x => x.Name == selectedPilotName); IMachine machine = machines.FirstOrDefault(x => x.Name == selectedMachineName); if (repot == null) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } if (machine == null) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } if (machine.Pilot != null) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } repot.AddMachine(machine); machine.Pilot = repot; return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName)); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { if (!CheckIfPilotExists(selectedPilotName)) { return(string.Format(OutputMessages.PilotNotFound, selectedPilotName)); } if (!CheckIfMachineExists(selectedMachineName)) { return(string.Format(OutputMessages.MachineNotFound, selectedMachineName)); } IPilot pilot = GetPilot(selectedPilotName); IMachine machine = GetMachine(selectedMachineName); if (!CheckIfNull(machine.Pilot)) { return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName)); } machine.Pilot = pilot; pilot.AddMachine(machine); return(string.Format(OutputMessages.MachineEngaged, pilot.Name, machine.Name)); }
public string EngageMachine(string selectedPilotName, string selectedMachineName) { IPilot pilot = this.pilots.Where(x => x.Name == selectedPilotName).FirstOrDefault(); IMachine machine = this.machines.Where(x => x.Name == selectedMachineName).FirstOrDefault(); if (pilot == null) { return($"Pilot {selectedPilotName} could not be found"); } else if (machine == null) { return($"Machine {selectedMachineName} could not be found"); } else if (machine.Pilot != null) { return($"Machine {selectedMachineName} is already occupied"); } else { pilot.AddMachine(machine); machine.Pilot = pilot; return($"Pilot {pilot.Name} engaged machine {machine.Name}"); } }