public bool CreatePoliceStation(PoliceStation policeStation, List <PoliceStation> stations = null) { List <PoliceStation> policeStations = null; if (stations != null) { policeStations = stations; } else { policeStations = GetPoliceStation(); policeStations.Add(policeStation); } XmlSerializer xmlFormatter = new XmlSerializer(typeof(List <PoliceStation>)); try { using (FileStream fs = new FileStream(PathPoliceStation, FileMode.OpenOrCreate)) { xmlFormatter.Serialize(fs, policeStations); } return(true); } catch (Exception ex) { return(false); } }
//List<PoliceStation> PoliceStations public void CreatePoliceStation() { PoliceStation ps = new PoliceStation(); ps.Address = ""; ps.city = am.GetCity()[0]; //cityPs ps.CodePoliceStation = 001; ps.NamePoliceStation = ""; CreatePoliceStation(ps); }
public void AddPolicePersonToStation(int codePs, PolicePeolple policePeople) { List <PoliceStation> poliseStations = GetPoliceStation(); PoliceStation station = poliseStations.FirstOrDefault( f => f.CodePoliceStation == codePs); //Извлекли станцию из списка poliseStations.Remove(station); //Изменили ее station.policePeolple.Add(policePeople); //Добавили снова poliseStations.Add(station); CreatePoliceStation(null, poliseStations); }