using System;
using Model;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections.Generic;

namespace Manager
{
    public class PersonManager
    {
        /// 虚拟数据源
        private List<Person> DataSource()
        {
            FileStream fileStream = new FileStream("./DataSource.sour", FileMode.Open, FileAccess.ReadWrite);
            BinaryFormatter formatter = new BinaryFormatter();
            List<Person> personList=(List<Person>)formatter.Deserialize((fileStream));
            
            return personList;
        }

        //获取所有的Person
        public List<Person> GetList()
        {
            List<Person> personList = DataSource();
            return personList;
        }

        //根据输入ID获取对应的Person
        public Person GetPersonByID(int id)
        {
            foreach (Person person in DataSource())
            {
                if (person.ID == id)
                    return person;
            }
            return null;
        }
    }
}
