// true if element found and removed. false if key is not found public bool DeleteJob(string jobName) { // Check for employee dependencies using similar approach used in DeletePerson Job job = GetJob(jobName); if (job != null && job.Employees.Count > 0) { IPersonnelSvc pServ = new PersonnelSvcIOImpl(); foreach (Employee emp in job.Employees) { Employee e = pServ.GetEmployee(emp.FirstName, emp.LastName); e.Jobs.Remove(job); pServ.UpdatePerson(e); } } return(DbCollections.SquadronJobs.Remove(jobName)); }
// true if element found and removed. false if key is not found public bool DeleteFlight(Flight flight) { // Check for employee dependencies using similar approach used in DeletePerson /* * Job job = GetJob(jobName); * if (job != null && job.Employees.Count > 0) * { * IPersonnelSvc pServ = new PersonnelSvcIOImpl(); * foreach (Employee emp in job.Employees) * { * Employee e = pServ.GetEmployee(emp.FirstName, emp.LastName); * e.Jobs.Remove(job); * pServ.UpdatePerson(e); * } * } */ Flight flt = GetFlight(flight.Name); if (flt != null && flt.Employees.Count > 0) { IPersonnelSvc pServ = new PersonnelSvcIOImpl(); foreach (Employee emp in flt.Employees) { Employee e = pServ.GetEmployee(emp.FirstName, emp.LastName); // TODO, remove list of flights // e.Flights.Remove(flight); // if not null and equal, reset to new (blank) flight if (e.Flight != null && e.Flight == flt) { e.Flight = new Flight(); } pServ.UpdatePerson(e); } } return(DbCollections.SquadronFlights.Remove(flight.Name)); }