public ContactsVM()
        {
            int i = 0;
            _DB = new CSharpContext();
            Contacts = new ObservableCollection<Contact>();
            SaveCommand = new DelegateCommand(() => _DB.SaveChanges());
            AddCommand = new DelegateCommand(() =>
            {
                CurrentContact = new Contact();
                Contacts.Add(CurrentContact);
                _DB.Contacts.Add(CurrentContact);
            });
            AddEmailCommand = new DelegateCommand(() =>
            {
                var cm = new ContactMethod();
                CurrentContact.ContactMethods.Add(cm);
            });
            DeleteCommand = new DelegateCommand(() =>
            {
                _DB.Contacts.Remove(CurrentContact);
                Contacts.Remove(CurrentContact);
            });

            Init();
        }
Beispiel #2
0
       //public ContactsVM()
       //{
       //    AddCommand = new DelegateCommand(
       //        () =>
       //        {
       //            Contacts.Add(new Contact { FirstName = this.FirstName });
       //            FirstName = null;
       //        },
       //    () => !String.IsNullOrWhiteSpace(FirstName)
       //        );

       //    var db = new CSharpContext();
       //    Contacts = db.Contacts.Local;
       //    db.Contacts.LoadAsync();
       //}

       //private string _firstName;
       //public string FirstName
       //{
       //    get { return _firstName; }
       //    set { _firstName = value; }
       //}

       //public DelegateCommand AddCommand { get; private set; }

       //public ObservableCollection<Contact> Contacts { get; private set; }
       #endregion

       #region "Constructor"
       public ContactsVM()
       {
           var db = new CSharpContext();
           Contacts = db.Contacts.Local;
           var contacts = db.Contacts.ToList();
           //db.Contacts.Load();
       }
 public IEnumerable<Contact> GetContacts(int page)
 {
     var db = new CSharpContext();
     db.Configuration.ProxyCreationEnabled = false;
     //db.Configuration.LazyLoadingEnabled = false;
     return db.Contacts.OrderBy(x=> x.LastName).Skip(page*10).Take(10).ToList();
 }