using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;
using System.Collections.ObjectModel;
using Microsoft.Phone.Data.Linq.Mapping;


namespace WPCompiledQuery
{
    public enum Gender
    {
        Male,
        Female
    }

    [Table(Name="Persons")]
    public class Person : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private int id;
        private string name;
        private string firstName;
        private int age;
        private string city;
        private Gender gender;

        [Column]
        public Gender Gender
        {
            get
            {
                return gender;
            }
            set
            {
                if (gender != value)
                {
                    NotifyPropertyChanging("Gender");
                    gender = value;
                    NotifyPropertyChanged("Gender");
                }
            }
        }

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int ID
        {
            get
            {
                return id;
            }
            set
            {
                if (id != value)
                {
                    NotifyPropertyChanging("ID");
                    id = value;
                    NotifyPropertyChanged("ID");
                }
            }
        }

        [Column]
        public string LastName
        {
            get
            {
                return name;
            }
            set
            {
                if (name != value)
                {
                    NotifyPropertyChanging("LastName");
                    name = value;
                    NotifyPropertyChanged("LastName");
                }
            }
        }

        [Column]
        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                if (firstName != value)
                {
                    NotifyPropertyChanging("FirstName");
                    firstName = value;
                    NotifyPropertyChanged("FirstName");
                }
            }
        }

        [Column]
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                if (age != value)
                {
                    NotifyPropertyChanging("Age");
                    age = value;
                    NotifyPropertyChanged("Age");
                }
            }
        }

        [Column]
        public string City
        {
            get
            {
                return city;
            }
            set
            {
                if (city != value)
                {
                    NotifyPropertyChanging("City");
                    city = value;
                    NotifyPropertyChanged("City");
                }
            }
        }

        // Benötigt für höhere Geschwindigkeit
        [Column(IsVersion = true)]
        private Binary version;

        public event PropertyChangedEventHandler PropertyChanged;

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

        public event PropertyChangingEventHandler PropertyChanging;

        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }
    }
}
