Ejemplo n.º 1
0
        private void RefreshClients(System.Action callback = null)
        {
            //potentially time consuming loading
            Task.Run(() =>
            {
                lock (_syncRoot)
                {
                    Clients.Clear();
                }

                using (IDataContextWrapper dataContext = _dataContextLocator())
                {
                    var clientsList = dataContext.Table <Client>().AsEnumerable();

                    clientsList.Apply(c =>
                    {
                        if (c.Longitude != null && c.Latitude != null)
                        {
                            c.Distance = geoLocation.CalculateDistance(currentPosition, (double)c.Latitude, (double)c.Longitude);
                        }
                    });

                    if (BeginDate.Ticks > 0)
                    {
                        clientsList = clientsList.Where(c => c.Birthdate >= BeginDate);
                    }
                    if (EndDate.Ticks > 0)
                    {
                        clientsList = clientsList.Where(c => c.Birthdate <= EndDate);
                    }
                    if (Distance < Int32.MaxValue)
                    {
                        clientsList = clientsList.Where(c => c.Distance <= Distance);
                    }

                    lock (_syncRoot)
                    {
                        Clients = new BindableCollection <Client>(clientsList);
                        if (callback != null)
                        {
                            callback();
                        }
                    }
                }
            });
        }