Ejemplo n.º 1
0
        public async Task <IActionResult> Get(string Token)
        {
            var TokenApi = new Token
            {
                TokenDef = _config.GetValue <string>("Token:TokenDef")
            };

            if (TokenApi.TokenDef != Token)
            {
                return(this.StatusCode(StatusCodes.Status401Unauthorized, $"O Token informado não é autorizado."));
            }
            try
            {
                var XMLs = await _repo.GetAllXMLsAsync();

                var Cargas = await _repo.GetAllParceiroCargasAsync();

                var Imoveis = await _repo.GetAllImoveisAtivosAsync(true);

                var Parceiros = await _repo.GetAllParceirosAsync();

                var cargaSimples       = 0;
                var cargaDestaque      = 0;
                var cargaSuperDestaque = 0;


                if (XMLs.Count() == 0)
                {
                    return(this.StatusCode(StatusCodes.Status204NoContent, $"Não há XMLs cadastrados para parceiros."));
                }

                if (Imoveis.Count() == 0)
                {
                    return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Não há Imoveis Ativos."));
                }

                foreach (var xml in XMLs)
                {
                    var parceiroCarga = Cargas.Where(x => x.ParceiroId == xml.ParceiroId).FirstOrDefault();
                    var parceiro      = Parceiros.Where(x => x.Id == xml.ParceiroId).FirstOrDefault();
                    cargaSimples       = parceiroCarga.AnuncioSimples;
                    cargaDestaque      = parceiroCarga.Destaque;
                    cargaSuperDestaque = parceiroCarga.SuperDestaque;
                    var stringXML = new StringBuilder();
                    stringXML.AppendLine(xml.XmlImovelInicio);
                    stringXML.AppendLine($"");
                    foreach (var imovel in Imoveis)
                    {
                        //parte B
                        var stringFotos = new StringBuilder();

                        var fotos = await _repo.GetAllVideosByImovelIdAsync(imovel.Id);

                        if (fotos.Count() > 0)
                        {
                            stringFotos.AppendLine(xml.XmlFotosInicio);
                            foreach (var foto in fotos)
                            {
                                stringFotos.AppendLine(xml.XmlFotosCorpo.Replace("@fotoNome", foto.Nome).Replace("@fotoLink", foto.Link));
                            }
                            stringFotos.AppendLine(xml.XmlFotosFim);
                        }

                        var stringVideos = new StringBuilder();
                        var videos       = await _repo.GetAllVideosByImovelIdAsync(imovel.Id);

                        if (videos.Count() > 0)
                        {
                            stringVideos.AppendLine(xml.XmlVideosInicio);
                            foreach (var video in videos)
                            {
                                stringVideos.AppendLine(xml.XmlVideosCorpo.Replace("@videoNome", video.Nome).Replace("@videoLink", video.Link));
                            }
                            stringVideos.AppendLine(xml.XmlVideosFim);
                        }

                        var flagTipoCarga = parceiro.TagSimples;
                        if (cargaDestaque > 0)
                        {
                            if (imovel.FlagDestaque != null && Convert.ToInt32(imovel.FlagSuperDestaque) > 0)
                            {
                                flagTipoCarga = parceiro.TagDestaque;
                                cargaDestaque--;
                            }
                        }
                        if (cargaSuperDestaque > 0)
                        {
                            if (imovel.FlagSuperDestaque != null && Convert.ToInt32(imovel.FlagSuperDestaque) > 0)
                            {
                                flagTipoCarga = parceiro.TagSuperDestaque;
                                cargaSuperDestaque--;
                            }
                        }

                        stringXML.AppendLine(xml.XmlImovelCorpo.Replace("@nome", imovel.Nome)
                                             .Replace("@referencia", imovel.Referencia)
                                             .Replace("@fotos", stringFotos.ToString())
                                             .Replace("@videos", stringVideos.ToString())
                                             .Replace("@descricao", imovel.Descricao)
                                             .Replace("@precoVenda", imovel.PrecoVenda.ToString())
                                             .Replace("@precoCondominio", imovel.PrecoCondominio.ToString())
                                             .Replace("@latitude", imovel.oEndereco.Latitude.ToString())
                                             .Replace("@longitude", imovel.oEndereco.Longitude.ToString())
                                             .Replace("@areaUtil", imovel.AreaUtil.ToString())
                                             .Replace("@areaTotal", imovel.AreaTotal.ToString())
                                             .Replace("@qtdDormitorios", imovel.QtdDormitorios.ToString())
                                             .Replace("@qtdSuites", imovel.QtdSuites.ToString())
                                             .Replace("@qtdBanheiros", imovel.QtdBanheiros.ToString())
                                             .Replace("@qtdSalas", imovel.QtdSalas.ToString())
                                             .Replace("@qtdVagas", imovel.QtdVagas.ToString())
                                             .Replace("@qtdElevador", imovel.QtdElevador.ToString())
                                             .Replace("@qtdUnidadesAndar", imovel.QtdUnidadesAndar.ToString())
                                             .Replace("@anoConstrucao", imovel.AnoConstrucao.ToString())
                                             .Replace("@armarioCozinha", Convert.ToInt32(imovel.ArmarioCozinha).ToString())
                                             .Replace("@armarioEmbutido", Convert.ToInt32(imovel.ArmarioEmbutido).ToString())
                                             .Replace("@estacionamentoVisitantes", Convert.ToInt32(imovel.EstacionamentoVisitantes).ToString())
                                             .Replace("@piscina", Convert.ToInt32(imovel.Piscina).ToString())
                                             .Replace("@quadraSquash", Convert.ToInt32(imovel.QuadraSquash).ToString())
                                             .Replace("@quadraTenis", Convert.ToInt32(imovel.QuadraTenis).ToString())
                                             .Replace("@quadraPoliesportiva", Convert.ToInt32(imovel.QuadraPoliesportiva).ToString())
                                             .Replace("@salaGinastica", Convert.ToInt32(imovel.SalaGinastica).ToString())
                                             .Replace("@salaoFestas", Convert.ToInt32(imovel.SalaoFestas).ToString())
                                             .Replace("@salaoJogos", Convert.ToInt32(imovel.SalaoJogos).ToString())
                                             .Replace("@sauna", Convert.ToInt32(imovel.Sauna).ToString())
                                             .Replace("@varanda", Convert.ToInt32(imovel.Varanda).ToString())
                                             .Replace("@lavabo", Convert.ToInt32(imovel.Lavabo).ToString())
                                             .Replace("@depositoSubsolo", Convert.ToInt32(imovel.DepositoSubsolo).ToString())
                                             .Replace("@closet", Convert.ToInt32(imovel.Closet).ToString())
                                             .Replace("@hidromassagem", Convert.ToInt32(imovel.Hidromassagem).ToString())
                                             .Replace("@lareira", Convert.ToInt32(imovel.Lareira).ToString())
                                             .Replace("@andarInteiro", Convert.ToInt32(imovel.AndarInteiro).ToString())
                                             .Replace("@meioAndar", Convert.ToInt32(imovel.MeioAndar).ToString())
                                             .Replace("@salaAlmoco", Convert.ToInt32(imovel.SalaAlmoco).ToString())
                                             .Replace("@salaJantar", Convert.ToInt32(imovel.SalaJantar).ToString())
                                             .Replace("@salaIntima", Convert.ToInt32(imovel.SalaIntima).ToString())
                                             .Replace("@brinquedoteca", Convert.ToInt32(imovel.Brinquedoteca).ToString())
                                             .Replace("@playground", Convert.ToInt32(imovel.Playground).ToString())
                                             .Replace("@tagTipoCarga", flagTipoCarga)
                                             .Replace("@logradouro", imovel.oEndereco.Logradouro.ToString())
                                             .Replace("@numero", imovel.oEndereco.Numero.ToString())
                                             .Replace("@bairro", imovel.oEndereco.Bairro.ToString())
                                             .Replace("@cidade", imovel.oEndereco.Cidade.ToString())
                                             .Replace("@uf", imovel.oEndereco.UF.ToString())
                                             .Replace("@cep", imovel.oEndereco.CEP.ToString())
                                             .Replace("@complemento", imovel.Complemento.ToString())
                                             );
                    }
                    stringXML.AppendLine($"");
                    stringXML.AppendLine(xml.XmlImovelFim);

                    //Falta a parte de salvar esse xml e enviar via FTP.
                }
                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Ocorreu um erro no banco de Dados.{ex.Message}"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var Imoveis = await _repo.GetAllImoveisAtivosAsync(true);

                var Vendedores = await _repo.GetAllVendedoresAsync();

                var listaLocations  = new List <Locations>();
                var listaProperties = new List <Propertie>();
                foreach (var imovel in Imoveis)
                {
                    var lat = "";
                    var lng = "";
                    if (imovel.oEndereco != null)
                    {
                        lat = imovel.oEndereco.Latitude;
                    }
                    else
                    {
                        lat = imovel.oEdificio.oEndereco.Latitude;
                    }
                    if (imovel.oEndereco != null)
                    {
                        lng = imovel.oEndereco.Longitude;
                    }
                    else
                    {
                        lng = imovel.oEdificio.oEndereco.Longitude;
                    }

                    listaLocations.Add(new Locations
                    {
                        propertyId = imovel.Id,
                        id         = imovel.Id,
                        lat        = lat,
                        lng        = lng
                    });

                    var oEndereco = new Endereco();
                    if (imovel.EdificioId > 0)
                    {
                        if (imovel.oEdificio.oEndereco != null)
                        {
                            oEndereco = new Endereco
                            {
                                Bairro      = imovel.oEdificio.oEndereco.Bairro,
                                CEP         = imovel.oEdificio.oEndereco.CEP,
                                Cidade      = imovel.oEdificio.oEndereco.Cidade,
                                Complemento = imovel.oEdificio.oEndereco.Complemento + " " + imovel.Complemento,
                                Logradouro  = imovel.oEdificio.oEndereco.Logradouro,
                                Numero      = imovel.oEdificio.oEndereco.Numero,
                                UF          = imovel.oEdificio.oEndereco.UF
                            };
                        }
                    }
                    else
                    {
                        oEndereco = new Endereco
                        {
                            Bairro      = imovel.oEndereco.Bairro,
                            CEP         = imovel.oEndereco.CEP,
                            Cidade      = imovel.oEndereco.Cidade,
                            Complemento = imovel.oEndereco.Complemento + " " + imovel.Complemento,
                            Logradouro  = imovel.oEndereco.Logradouro,
                            Numero      = imovel.oEndereco.Numero,
                            UF          = imovel.oEndereco.UF
                        };
                    }

                    var listGalery   = new List <Gallery>();
                    var listPlans    = new List <Plan>();
                    var fotosImoveis = await _repo.GetFotosImovelByIdAsync(imovel.Id);

                    if (fotosImoveis.Count() > 0)
                    {
                        foreach (var foto in fotosImoveis)
                        {
                            listGalery.Add(new Gallery
                            {
                                small  = foto.Caminho,
                                medium = foto.Caminho,
                                big    = foto.Caminho
                            });
                        }
                    }
                    var fotosAreaImoveis = await _repo.GetFotosAreaImovelByIdAsync(imovel.Id);

                    if (fotosAreaImoveis.Count() > 0)
                    {
                        foreach (var foto in fotosAreaImoveis)
                        {
                            listGalery.Add(new Gallery
                            {
                                small  = foto.Caminho,
                                medium = foto.Caminho,
                                big    = foto.Caminho
                            });
                        }
                    }

                    var fotosPlantaImoveis = await _repo.GetFotosPlantaImovelByIdAsync(imovel.Id);

                    if (fotosPlantaImoveis.Count() > 0)
                    {
                        foreach (var foto in fotosPlantaImoveis)
                        {
                            listPlans.Add(new Plan
                            {
                                image = foto.Caminho,
                            });
                        }
                    }

                    if (imovel.EdificioId != null && imovel.EdificioId > 0)
                    {
                        var fotosEdificio = await _repo.GetFotosEdificioByIdAsync(imovel.Id);

                        if (fotosEdificio.Count() > 0)
                        {
                            foreach (var foto in fotosImoveis)
                            {
                                listGalery.Add(new Gallery
                                {
                                    small  = foto.Caminho,
                                    medium = foto.Caminho,
                                    big    = foto.Caminho
                                });
                            }
                        }
                        var fotosAreaEdificio = await _repo.GetFotosAreaEdificioByIdAsync(imovel.Id);

                        if (fotosAreaImoveis.Count() > 0)
                        {
                            foreach (var foto in fotosAreaImoveis)
                            {
                                listGalery.Add(new Gallery
                                {
                                    small  = foto.Caminho,
                                    medium = foto.Caminho,
                                    big    = foto.Caminho
                                });
                            }
                        }

                        var fotosPlantaEdificio = await _repo.GetFotosPlantaEdificioByIdAsync(imovel.Id);

                        if (fotosPlantaEdificio.Count() > 0)
                        {
                            foreach (var foto in fotosPlantaEdificio)
                            {
                                listPlans.Add(new Plan
                                {
                                    image = foto.Caminho,
                                });
                            }
                        }
                    }
                    var videos = await _repo.GetAllVideosByImovelIdAsync(imovel.Id);

                    var listaVideos = new List <Video>();

                    if (videos.Count() > 0)
                    {
                        foreach (var video in videos)
                        {
                            listaVideos.Add(new Video
                            {
                                link = video.Link,
                                name = video.Nome
                            });
                        }
                    }
                    var listaBairro   = new List <string>();
                    var listaRua      = new List <string>();
                    var listaStatus   = new List <string>();
                    var listaFeatures = RetonaListaFeatures(imovel);

                    if (imovel.PrecoVenda > 0)
                    {
                        listaStatus.Add("À Venda");
                    }
                    else
                    {
                        listaStatus.Add("Para Alugar");
                    }
                    listaBairro.Add(oEndereco.Bairro);
                    listaRua.Add(oEndereco.Logradouro);

                    var oPropertie = new Propertie
                    {
                        area = new Area
                        {
                            unit  = "m2",
                            value = imovel.AreaUtil
                        },
                        bathrooms   = imovel.QtdBanheiros,
                        bedrooms    = imovel.QtdDormitorios,
                        city        = oEndereco.Cidade,
                        gallery     = listGalery,
                        videos      = listaVideos,
                        garages     = imovel.QtdVagas,
                        id          = imovel.Id,
                        desc        = imovel.Descricao,
                        reference   = imovel.Referencia,
                        priceDollar = new PriceDollar
                        {
                            rent = imovel.PrecoLocacao,
                            sale = imovel.PrecoVenda
                        },
                        priceEuro = new PriceEuro
                        {
                            rent = imovel.PrecoLocacao,
                            sale = imovel.PrecoVenda
                        },
                        neighborhood = listaBairro,
                        location     = new Location
                        {
                            lat = lat,
                            lng = lng
                        },
                        title              = imovel.Nome,
                        street             = listaRua,
                        yearBuilt          = imovel.AnoConstrucao,
                        lastUpdate         = imovel.DataAlteracao.ToString(),
                        published          = imovel.DataAlteracao.ToString(),
                        zipCode            = oEndereco.CEP,
                        ratingsValue       = 5,
                        ratingsCount       = 100,
                        views              = 1000,
                        propertyType       = imovel.Tipo,
                        formattedAddress   = oEndereco.Logradouro + " " + oEndereco.Numero + " " + oEndereco.Complemento,
                        additionalFeatures = new List <AdditionalFeature>(),
                        featured           = false,
                        propertyStatus     = listaStatus,
                        features           = listaFeatures,
                        plans              = listPlans
                    };

                    listaProperties.Add(oPropertie);
                }
                var retorno = new HomeReturn
                {
                    agents     = Vendedores.ToList(),
                    locations  = listaLocations,
                    properties = listaProperties
                };
                return(Ok(retorno));
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Ocorreu um erro no banco de Dados.{ex.Message}"));
            }
        }