public void removeStudent(PilotStudent student) { this.Students.Remove(student); this.FlightSchool.RemoveStudent(student); this.NumberOfStudents = this.Students.Count; }
public void addStudent(PilotStudent student) { this.Students.Add(student); this.FlightSchool.AddStudent(student); this.NumberOfStudents = this.Students.Count; }
//removes a students from the instructor public void RemoveStudent(PilotStudent student) { Students.Remove(student); }
//adds a student to the instructor public void AddStudent(PilotStudent student) { Students.Add(student); }
//sets the status for hiring of students //returns the aircraft for a student private TrainingAircraft getStudentAircraft(PilotStudent student) { Dictionary<TrainingAircraftType, int> types = FlightSchool.Aircrafts.GroupBy(a => a.Type) .Select(group => new { Type = group.Key, Count = group.Sum(g => g.Type.MaxNumberOfStudents) }) .ToDictionary(g => g.Type, g => g.Count); ; foreach (PilotStudent ps in FlightSchool.Students) { types[ps.Aircraft.Type]--; } IOrderedEnumerable<TrainingAircraftType> freeTypes = types.Where(t => t.Value > 0).Select(t => t.Key).OrderBy(t => t.TypeLevel); return FlightSchool.Aircrafts.First(a => a.Type == freeTypes.First()); }
private void btnHire_Click(object sender, RoutedEventArgs e) { IEnumerable<TrainingAircraftType> aircraftsTypesFree = FlightSchool.Aircrafts.Select(a => a.Type); Dictionary<TrainingAircraftType, int> types = FlightSchool.Aircrafts.GroupBy(a => a.Type) .Select(group => new { Type = group.Key, Count = group.Sum(g => g.Type.MaxNumberOfStudents) }) .ToDictionary(g => g.Type, g => g.Count); ; foreach (PilotStudent student in FlightSchool.Students) { TrainingAircraftType firstAircraft = student.Rating.Aircrafts.OrderBy(a => a.TypeLevel) .FirstOrDefault(a => types.ContainsKey(a) && types[a] > 0); if (firstAircraft != null && types.ContainsKey(firstAircraft)) { types[firstAircraft]--; } } var possibleRatings = new List<PilotRating>(); foreach (PilotRating rating in PilotRatings.GetRatings()) { if (rating.Aircrafts.Exists(a => types.ContainsKey(a) && types[a] > 0)) { possibleRatings.Add(rating); } } WPFMessageBoxResult result = WPFMessageBox.Show( Translator.GetInstance().GetString("MessageBox", "2811"), string.Format(Translator.GetInstance().GetString("MessageBox", "2811", "message")), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { List<Town> towns = Towns.GetTowns(FlightSchool.FlightSchool.Airport.Profile.Country); Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate( GameObject.GetInstance().GameTime.AddYears(-35), GameObject.GetInstance().GameTime.AddYears(-23)); var profile = new PilotProfile( Names.GetInstance().GetRandomFirstName(town.Country), Names.GetInstance().GetRandomLastName(town.Country), birthdate, town); var instructor = (Instructor)cbInstructor.SelectedItem; string airlinerFamily = cbTrainAircraft.SelectedItem.ToString(); var student = new PilotStudent( profile, GameObject.GetInstance().GameTime, instructor, GeneralHelpers.GetPilotStudentRating(instructor, possibleRatings), airlinerFamily); TrainingAircraft aircraft = getStudentAircraft(student); student.Aircraft = aircraft; FlightSchool.addStudent(student); instructor.AddStudent(student); setHireStudentsStatus(); double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost); AirlineHelpers.AddAirlineInvoice( GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.AirlineExpenses, -studentPrice); } }