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 TreeViewDNDWithRia.Web;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
using System.Linq;

namespace TreeViewDNDWithRia.ViewModels
{
    public class TreeViewViewModel : ViewModelBase
    {
        private DomainServiceNorthwind context;

        private ObservableCollection<CategoryViewModel> categories;
        public ObservableCollection<CategoryViewModel> Categories
        {
            get
            {
                if (categories == null)
                {
                    context = new DomainServiceNorthwind();
                    context.Load<Category>(context.GetCategoriesQuery(), lo =>
                    {
                        categories = new ObservableCollection<CategoryViewModel>(
                            context.Categories.Select(x => new CategoryViewModel(x)));
                        OnPropertyChanged("Categories");
                    }, null);
                }
                return categories;
            }
        }
    }
}
