Example #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);
        }
Example #2
0
        private List <Person> ReadFile(string path)
        {
            List <Person> personsDeserialize = new List <Person>();

            if (File.Exists(path))
            {
                personsDeserialize = (List <Person>)SaveReadToFile.Deserialize(path);
            }

            return(personsDeserialize);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }