Пример #1
0
        private static List <Person> ReadFile(string path)
        {
            List <Person> personsDeserialize = new List <Person>();

            if (fileExist || null != (List <Person>)SaveReadToFile.Deserialize(path))
            {
                fileExist          = true;
                personsDeserialize = (List <Person>)SaveReadToFile.Deserialize(path);
            }

            //if (null != (List<Person>)SaveReadToFile.Deserialize(path))
            //{
            //    personsDeserialize = (List<Person>)SaveReadToFile.Deserialize(path);

            //}
            return(personsDeserialize);
        }
Пример #2
0
        public void Create(Person person)
        {
            persons = ReadFile("MyFile1.dat");
            if (person == null)
            {
                throw new ArgumentNullException("No Data");
            }
            if (persons.Count > 0)
            {
                nextId = persons.Max(d => d.Id);
                nextId++;
            }

            person.Id = nextId;
            persons.Add(person);
            SaveReadToFile.Serialize(persons, "MyFile1.dat");
        }
Пример #3
0
        public bool Delete(Person person)
        {
            bool delateSuccess = false;

            persons = ReadFile("MyFile1.dat");

            try
            {
                persons.RemoveAll(p => p.Id == person.Id);
                SaveReadToFile.Serialize(persons, "MyFile1.dat");
                delateSuccess = true;
            }
            catch
            {
                throw new EntryPointNotFoundException();
            }

            return(delateSuccess);
        }
Пример #4
0
        public bool Update(Person person)
        {
            persons = ReadFile("MyFile1.dat");
            bool updateSuccess = false;

            if (person == null)
            {
                throw new ArgumentNullException("No data");
            }
            int index = persons.FindIndex(p => p.Id == person.Id);

            if (index == -1)
            {
                updateSuccess = false;
            }
            else
            {
                persons.RemoveAt(index);
                persons.Add(person);
                SaveReadToFile.Serialize(persons, "MyFile1.dat");
            }

            return(updateSuccess);
        }