using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace WpfApplication2
{
	public partial class Person : INotifyPropertyChanged
	{
		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		private void OnPropertyChanged(string propertyName)
		{
			if (this.PropertyChanged != null)
				this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		#endregion

		private string firstName;
		public string FirstName
		{
			get
			{
				return this.firstName;
			}
			set
			{
				if (this.firstName != value)
				{
					this.firstName = value;
					this.OnPropertyChanged("FirstName");
				}
			}
		}

		private string lastName;
		public string LastName
		{
			get
			{
				return this.lastName;
			}
			set
			{
				if (this.lastName != value)
				{
					this.lastName = value;
					this.OnPropertyChanged("LastName");
				}
			}
		}

		private DateTime birthDay;
		public DateTime BirthDay
		{
			get
			{
				return this.birthDay;
			}
			set
			{
				if (this.birthDay != value)
				{
					this.birthDay = value;
					this.OnPropertyChanged("BirthDay");
				}
			}
		}

		public string PeriodFormatted
		{
			get
			{
				return this.BirthDay.ToString();
			}
			set
			{
				this.BirthDay = this.StringToPeriod(value);
				this.OnPropertyChanged("PeriodFormatted");
			}
		}

		private DateTime StringToPeriod(string value)
		{
			DateTime result;
			if (DateTime.TryParse(value, out result))
			{
				return result;
			}
			return DateTime.Today;
		}
	}
}
