using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace SilverlightApplication9
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            this.DataContext = new MainViewModel();
        }
    }

        
    public class User : INotifyPropertyChanged
    {
        private int id;

        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
                this.OnPropertyChanged("Id");
            }
        }

        private string userName;

        public string UserName
        {
            get
            {
                return userName;
            }
            set
            {
                userName = value;
                this.OnPropertyChanged("UserName");
            }
        }

        private DateTime lastLoginDate;

        public DateTime LastLoginDate
        {
            get
            {
                return lastLoginDate;
            }
            set
            {
                lastLoginDate = value;
                this.OnPropertyChanged("LastLoginDate");
            }
        }


        private bool active;

        public bool Active
        {
            get
            {
                return active;
            }
            set
            {
                active = value;
                this.OnPropertyChanged("Active");
            }
        }


        private bool approved;

        public bool Approved
        {
            get
            {
                return approved;
            }
            set
            {
                approved = value;
                this.OnPropertyChanged("Approved");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

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

    public class MainViewModel
    {
        private ObservableCollection<User> data;

        public ObservableCollection<User> Data
        {
            get { return data; }
            set { data = value; }
        }

        public MainViewModel()
        {
            GenerateData(100);
        }

        private void GenerateData(int c)
        {
            this.data = new ObservableCollection<User>((
                from p in Enumerable.Range(0, c)
                select new User
                {
                    Id = p,
                    Active = p % 2 == 0,
                    Approved = p % 3 == 0,
                    LastLoginDate = DateTime.Now.AddDays(-p),
                    UserName = "User " + p
                }).ToList());
        }

    }
      
}
