// TODO: Break out some of this static method into sub methods. public static PersonModel Convert(RemoteObjects.People.person person) { // RULE: For string type NO nulls empty string instead. if (person == null) throw new ArgumentNullException("Cannot convert a Null person to a PersonModel."); PersonModel personModel = new PersonModel(); personModel.ID = person.id ?? ""; personModel.HouseholdID = person.householdID ?? ""; personModel.Name = new Name(person.firstName ?? "", "", person.lastName ?? "", person.prefix ?? ""); Gender gender; if (!Enum.TryParse(person.gender.ToString(), true, out gender)) gender = Gender.Unknown; personModel.Gender = gender; personModel.MaritalStatus = ""; if (person.maritalStatus != null) personModel.MaritalStatus = person.maritalStatus.ToString(); personModel.DateOfBirth = DateTime.MinValue; if (person.dateOfBirth != null) { Match match = Regex.Match(person.dateOfBirth, @"(?<Date>\d{4}-\d{2}-\d{2})T\d{2}:\d{2}:\d{2}"); if (match.Success) { personModel.DateOfBirth = DateTime.Parse(match.Groups["Date"].Value); } } personModel.HouseholdMemberTypeName = ""; if (person.householdMemberType != null && person.householdMemberType.name != null) personModel.HouseholdMemberTypeName = person.householdMemberType.name.ToString(); personModel.StatusName = ""; if (person.status != null && person.status.name != null) personModel.StatusName = person.status.name; return personModel; }
public void AddPerson(PersonModel personModel) { if (People == null) People = new List<PersonModel>(); People.Add(personModel); }