Example #1
0
        async void Init()
        {
            var soapClient = new Bubble.ContactsSoapClient();
            IEnumerable <Person>  persons;
            IEnumerable <Email>   ems;
            IEnumerable <Address> ads;
            IEnumerable <Phone>   phs;

            persons = await soapClient.GetPeopleAsync();

            foreach (var dude in persons)
            {
                ContactList.Add(dude);
            }
            ems = await soapClient.GetEmailsAsync();

            foreach (var e in ems)
            {
                EmailList.Add(e);
            }
            ads = await soapClient.GetAddressesAsync();

            foreach (var a in ads)
            {
                AddressList.Add(a);
            }
            phs = await soapClient.GetPhonesAsync();

            foreach (var p in phs)
            {
                PhoneList.Add(p);
            }

            foreach (var dude in ContactList)
            {
                foreach (var e in EmailList)
                {
                    if (dude.PID == e.PersonID)
                    {
                        dude.elist.Add(e);
                    }
                }
                foreach (var a in AddressList)
                {
                    if (dude.PID == a.PersonID)
                    {
                        dude.alist.Add(a);
                    }
                }
                foreach (var p in PhoneList)
                {
                    if (dude.PID == p.PersonID)
                    {
                        dude.plist.Add(p);
                    }
                }
            }
        }
Example #2
0
        public ContactsVM()
        {
            var BubbleClient = new Bubble.ContactsSoapClient();

            //db = new FinalContext();

            //ContactList = db.People.Local;
            //db.People.Load();

            //EmailList = db.Emails.Local;
            //db.Emails.Load();

            //PhoneList = db.Phones.Local;
            //db.Phones.Load();

            //AddressList = db.Addresses.Local;
            //db.Addresses.Load();
            ContactList = new ObservableCollection <Person>();
            EmailList   = new ObservableCollection <Email>();
            PhoneList   = new ObservableCollection <Phone>();
            AddressList = new ObservableCollection <Address>();
            Init();

            SaveCommand      = new DelegateCommand(() => BubbleClient.Save());
            AddPersonCommand = new DelegateCommand(() => {
                CurrentPerson = new Person();
                ContactList.Add(CurrentPerson);
                BubbleClient.AddPersonAsync(CurrentPerson);
            });
            AddEmailCommand = new DelegateCommand(() => {
                var em      = new Email();
                em.PersonID = CurrentPerson.PID;
                EmailList.Add(em);
                CurrentPerson.elist.Add(em);
                BubbleClient.AddEmailAsync(em);
            });
            DeletePersonCommand = new DelegateCommand(() => {
                db.People.Remove(CurrentPerson);
                ContactList.Remove(CurrentPerson);
            });
            AddPhoneCommand = new DelegateCommand(() => {
                var pn      = new Phone();
                pn.PersonID = CurrentPerson.PID;
                PhoneList.Add(pn);
                CurrentPerson.plist.Add(pn);
                BubbleClient.AddPhoneAsync(pn);
            });
            AddAddressCommand = new DelegateCommand(() => {
                var ad      = new Address();
                ad.PersonID = CurrentPerson.PID;
                CurrentPerson.alist.Add(ad);
                AddressList.Add(ad);
                BubbleClient.AddAddressAsync(ad);
            });
            DeleteAddressCommand = new DelegateCommand(() => {
                CurrentPerson.alist.Remove(CurrentAddress);
                AddressList.Remove(CurrentAddress);
                BubbleClient.RemoveAddressAsync(CurrentAddress);
            });
            DeletePhoneCommand = new DelegateCommand(() => {
                CurrentPerson.plist.Remove(CurrentPhone);
                PhoneList.Remove(CurrentPhone);
                BubbleClient.RemovePhoneAsync(CurrentPhone);
            });
            DeleteEmailCommand = new DelegateCommand(() => {
                CurrentPerson.elist.Remove(CurrentEmail);
                EmailList.Remove(CurrentEmail);
                BubbleClient.RemoveEmailAsync(CurrentEmail);
            });
        }