public Person UpdatePerson(long id, Person person) { var personToUpdate = persons.FirstOrDefault(p => p.Id == id); if(person != null) { personToUpdate = person; return personToUpdate; } return null; }
static void Main(string[] args) { //create an object from Persons Persons myFriends = new Persons(); //create friends... Person person1 = new Person { Firstname="Hannes", Lastname ="Vehnä", SocialSecurityNumber="666666-666"}; Person person2 = new Person { Firstname = "Otto", Lastname = "Niemi", SocialSecurityNumber = "010101-000" }; Person person3 = new Person { Firstname = "Vesa", Lastname = "Ihan", SocialSecurityNumber = "123456-789" }; //add persons to collection myFriends.AddPerson(person1); myFriends.AddPerson(person2); myFriends.AddPerson(person3); //print collection myFriends.PrintCollection(); //get one person Console.WriteLine("Get one person from collection: "); Person person4 = myFriends.GetPerson(0); if (person4 != null) { Console.WriteLine(person4.ToString()); } else { Console.WriteLine("Cannot find person in that position..."); } //find person with SocialSecurityNumber string socialSecurityNumber = "666666 - 666"; Console.WriteLine("Find persons with sotu: " + socialSecurityNumber); Person person5 = myFriends.FindPerson(socialSecurityNumber); if (person5 !=null) { Console.WriteLine(person5.ToString()); }else { Console.WriteLine("Not found..."); } }
/// <summary> /// Adds a person to collection /// </summary> /// <param name="person">Added person</param> public void AddPerson(Person person) { persons.Add(person); }
public Person AddPerson(Person person) { person.Id = GetNewId(); persons.Add(person); return person; }
partial void DeletePerson(Person instance);
partial void UpdatePerson(Person instance);
partial void InsertPerson(Person instance);