Esempio n. 1
0
        async Task ExecuteLoadItemsBuscaCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Imovels.Clear();

                Geocoder coder = new Geocoder();

                List <Imovel> FiltroImoveis = LstImoveis;

                if (mPesquisa.categoria != null)
                {
                    FiltroImoveis = FiltroImoveis.Where(p => p.categoria == mPesquisa.categoria).ToList();
                }

                if (mPesquisa.negocio != null)
                {
                    FiltroImoveis = FiltroImoveis.Where(p => p.negocio == mPesquisa.negocio).ToList();
                }

                if (mPesquisa.cidade != null)
                {
                    FiltroImoveis = FiltroImoveis.Where(p => p.cidade == mPesquisa.cidade).ToList();
                }

                if (mPesquisa.bairro != null)
                {
                    if (mPesquisa.bairro.Count > 0)
                    {
                        FiltroImoveis = FiltroImoveis.Where(p => mPesquisa.bairro.Contains(p.bairro)).ToList();
                    }
                }

                if (mPesquisa.busca != null)
                {
                    if (mPesquisa.busca != "")
                    {
                        FiltroImoveis = FiltroImoveis.Where(p => (p.descricao.ToUpper().Contains(mPesquisa.busca.ToUpper())) || (p.titulo.ToUpper().Contains(mPesquisa.busca.ToUpper()))).ToList();
                    }
                }

                if (mPesquisa.dormitorios != null)
                {
                    if (mPesquisa.dormitorios.Count > 0)
                    {
                        FiltroImoveis = FiltroImoveis.Where(p => mPesquisa.dormitorios.Contains(p.dormitorios)).ToList();
                    }
                }

                if (mPesquisa.faixa1 > 0 && mPesquisa.faixa2 > 0)
                {
                    FiltroImoveis = FiltroImoveis.Where(p => p.valor >= mPesquisa.faixa1 && p.valor <= mPesquisa.faixa2).ToList();
                }

                foreach (var i in FiltroImoveis)
                {
                    i.uriImage = new UriImageSource {
                        CachingEnabled = true, Uri = new Uri(i.imagem), CacheValidity = new TimeSpan(5, 0, 0, 0)
                    };
                    Imovels.Add(i);
                }
                if (Imovels.Count <= 0)
                {
                    CrossToastPopUp.Current.ShowToastMessage("Sem imóveis para esta busca", Plugin.Toast.Abstractions.ToastLength.Long);
                }
            }
            catch (Exception ex)
            {
                IsBusy = false;
                foreach (var i in LstImoveis)
                {
                    Imovels.Add(i);
                }
                CrossToastPopUp.Current.ShowToastMessage("Erro ao gerar busca", Plugin.Toast.Abstractions.ToastLength.Long);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 2
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Imovels.Clear();
                if (LstImoveis.Count < 1)
                {
                    LstImoveis = await Services.Sistema.RESTAPI.getAsync <List <Imovel> >("");
                }

                Sistema.USUARIO = await Services.Sistema.DATABASE.database.Table <Models.Usuario>().Where(p => p.logado).FirstOrDefaultAsync();

                favoritos.Clear();
                if (Sistema.USUARIO != null)
                {
                    favoritos = await Services.Sistema.DATABASE.database.Table <Models.Favoritos>().Where(p => p.idUsuario == Sistema.USUARIO.cod).ToListAsync();
                }

                // Imovels = new ObservableCollection<Imovel>(imo as List<Imovel>);
                Geocoder coder = new Geocoder();
                foreach (var i in LstImoveis)
                {
                    if (favoritos != null)
                    {
                        if (favoritos.Where(p => p.idImovel.Equals(i.id)).Count() > 0)
                        {
                            i.favorito = "Red";
                        }
                        else
                        {
                            i.favorito = "White";
                        }
                    }
                    if (i.position != null)
                    {
                        Location loc = new Location();
                        var      a   = await coder.GetPositionsForAddressAsync(i.logradouro + "," + i.bairro + "," + i.cidade + "-" + i.uf + "," + i.cep);

                        if (a.Any())
                        {
                            loc.Latitude  = a.ElementAt(0).Latitude;
                            loc.Longitude = a.ElementAt(0).Longitude;
                            i.localizacao = loc;
                            i.position    = new Position(a.ElementAt(0).Latitude, a.ElementAt(0).Longitude);
                            i.icon        = BitmapDescriptorFactory.FromView(new ViewPin());
                            i.uriImage    = new UriImageSource {
                                CachingEnabled = true, Uri = new Uri(i.imagem), CacheValidity = new TimeSpan(5, 0, 0, 0)
                            };
                        }
                    }



                    Imovels.Add(i);
                }
            }
            catch (Exception ex)
            {
                IsBusy = false;
            }
            finally
            {
                IsBusy = false;
            }
        }