示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }