public void DeleteByID(int id) { List <Person> allPersons = ReadFile(this.filePath); allPersons = ReadFile(this.filePath); Person selectedPerson = allPersons.Find(p => p.Id == id); allPersons.Remove(selectedPerson); SaveReadToFile.Serialize(allPersons, this.filePath); }
public bool Delete(Person person) { List <Person> allPersons = ReadFile(this.filePath); bool delateSuccess = false; Person selectedPerson = allPersons.Find(p => p.Id == person.Id); allPersons.Remove(selectedPerson); SaveReadToFile.Serialize(allPersons, this.filePath); delateSuccess = true; return(delateSuccess); }
public void Create(Person person) { List <Person> allPersons = ReadFile(this.filePath); if (allPersons.Any()) { this.nextId = allPersons.Max(d => d.Id); this.nextId++; } person.Id = this.nextId; allPersons.Add(person); SaveReadToFile.Serialize(allPersons, this.filePath); }
public bool Update(Person person) { List <Person> allPersons = ReadFile(this.filePath); allPersons = ReadFile(this.filePath); bool updateSuccess = false; Person selectedPerson = allPersons.Find(p => p.Id == person.Id); if (selectedPerson != null) { allPersons.Remove(selectedPerson); allPersons.Add(person); SaveReadToFile.Serialize(allPersons, this.filePath); updateSuccess = true; } return(updateSuccess); }