예제 #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);
        }