Exemplo n.º 1
0
        private void Search()
        {
            ContactsList.Clear();
            var contacts = new List <Model.Contact>();

            using (var sqlCon = new SqlConnection(@"Server=localhost\SQLEXPRESS;Database=PhoneBook;Trusted_Connection=True;"))
            {
                sqlCon.Query <Model.Contact, City, Phone, PhoneType, Model.Contact>("searchContact",
                                                                                    (contact, city, phone, phoneType) => {
                    var contactForList = contacts.FirstOrDefault(con => con.Id == contact.Id);

                    if (contactForList == null)
                    {
                        contactForList              = contact;
                        contactForList.City         = new City();
                        contactForList.PhoneNumbers = new List <Phone>();
                        contacts.Add(contactForList);
                    }
                    contactForList.City = city;
                    phone.PhoneType     = phoneType;
                    contactForList.PhoneNumbers.Add(phone);
                    return(contact);
                }, new { SearchString = SearchString }, commandType: System.Data.CommandType.StoredProcedure).ToList();
            }

            foreach (Model.Contact con in contacts)
            {
                var contactViewModel = new ContactViewModel(con, _cities, _phoneTypes);
                contactViewModel.OnCotactDeleted    += SingleContactDeleted;
                contactViewModel.EditContactClicked += SingleContactEdit;
                ContactsList.Add(contactViewModel);
            }
        }
        public async void LoadData()
        {
            ContactsList.Clear();
            List <ContactModel> database = await App.Database.GetContactsAsync().ConfigureAwait(false);

            foreach (ContactModel contact in database)
            {
                ContactsList.Add(contact);
            }

            IsLoading = false;
        }
Exemplo n.º 3
0
        void _phoneContacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            ContactsList.Clear();
            try
            {
                if (e.Results.Any())
                {
                    var items = (from r in e.Results
                                 where r.Birthdays.Any()
                                 select r);
                    ContactsList.AddRange(items);
                    if (GetEntriesCompleted != null)
                    {
                        GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                        {
                            Contacts = GetBirthdayContacts().AsQueryable()
                        });
                    }
                }
                else
                {
                    if (GetEntriesCompleted != null)
                    {
                        GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                        {
                            Contacts = new List <BirthdayContact>().AsQueryable()
                        });
                    }
                }
            }
#if DEBUG
            catch (InvalidOperationException iex)
            {
                DebugUtility.SaveDiagnosticException(iex);
#else
            catch
            {
#endif
                if (GetEntriesCompleted != null)
                {
                    GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                    {
                        Contacts = new List <BirthdayContact>().AsQueryable()
                    });
                }
            }
        }
 public void Reload()
 {
     if (Settings.LstContacts != null)
     {
         ContactsList.Clear();
         foreach (Contact c in Settings.LstContacts)
         {
             ContactsList.Add(new Models.Contact()
             {
                 Name   = $"{c.Name} {c.LastName}",
                 Email  = c.EmailsAddress.FirstOrDefault(),
                 Number = c.PhoneNumbers.FirstOrDefault().Number,
                 Photo  = c.Photo,
             });
         }
         OnPropertyChanged("ContactsList");
     }
 }
Exemplo n.º 5
0
        //update data using server
        private void UpdateContactList()
        {
            try
            {
                Task.Run(() =>
                {
                    try
                    {
                        var temp = SelectedContact;

                        var tempUiInfos = UserServiceClient.GetAllContactsUiInfo(GlobalBase.CurrentUser.Id);
                        GlobalBase.loadPictures(UserServiceClient, tempUiInfos);

                        Dispatcher.CurrentDispatcher.Invoke(() =>
                        {
                            lock (GlobalBase.contactsMonitor)
                            {
                                ContactsList.Clear();
                                ContactsList = tempUiInfos;
                            }
                        });

                        if (temp != null)
                        {
                            Dispatcher.CurrentDispatcher.Invoke(() =>
                            {
                                lock (GlobalBase.contactsMonitor)
                                {
                                    SelectedContact = ContactsList.FirstOrDefault(ct => ct.UniqueName == temp.UniqueName);
                                }
                            });
                        }
                    }
                    catch (Exception)
                    {
                    }
                });
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 6
0
        public Task <IQueryable <BirthdayContact> > GetAllEntriesAsync(bool forceRefresh = false)
        {
            TaskCompletionSource <IQueryable <BirthdayContact> > tcs = new TaskCompletionSource <IQueryable <BirthdayContact> >();

            if (ContactsList.Count == 0 || forceRefresh)
            {
                Contacts contacts = new Contacts();
                contacts.SearchCompleted += (s, e) =>
                {
                    try
                    {
                        ContactsList.Clear();
                        if (e.Results.Any())
                        {
                            var items = (from r in e.Results
                                         where r.Birthdays.Any()
                                         select r);
                            ContactsList.AddRange(items);
                            tcs.TrySetResult(GetBirthdayContacts().AsQueryable());
                        }
                        else
                        {
                            tcs.TrySetResult(new List <BirthdayContact>().AsQueryable());
                        }
                    }
                    catch (InvalidOperationException iex)
                    {
                        tcs.TrySetException(iex);
                    }
                };
                contacts.SearchAsync(String.Empty, FilterKind.None, "Load Contacts");
                return(tcs.Task);
            }
            else
            {
                tcs.SetResult(GetBirthdayContacts().AsQueryable());
                return(tcs.Task);
            }
        }