public async Task <IActionResult> Get(string Token, long edificioId) { 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 listaEdificios = await _repo.GetAllEdificiosAsync(); var listaFotoEdificio = await _repo.GetFotosEdificioByIdAsync(edificioId); var listaFotoAreaEdificio = await _repo.GetFotosAreaEdificioByIdAsync(edificioId); var listaFotoPlantaEdificio = await _repo.GetFotosPlantaEdificioByIdAsync(edificioId); var retorno = new FotosEdificioReturn { FotosEdificio = listaFotoEdificio.ToList(), FotosAreaEdificio = listaFotoAreaEdificio.ToList(), FotosPlantaEdificio = listaFotoPlantaEdificio.ToList() }; return(Ok(retorno)); } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Ocorreu um erro no banco de Dados.{ex.Message}")); } }
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}")); } }
public async Task <IActionResult> Upload(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 file = Request.Form.Files[0]; var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); var tipoUpload = dict["TipoUpload"]; var idReferencia = dict["IdReferencia"]; if (Convert.ToInt32(tipoUpload) > 9) { return(this.StatusCode(StatusCodes.Status401Unauthorized, "Favor informar um Tipo de UPLOAD Válido (1.Edificio, 2.Imovel, 3.Vendedor)")); } else if (Convert.ToInt32(tipoUpload) <= 0) { return(this.StatusCode(StatusCodes.Status401Unauthorized, "Favor informar um Tipo de UPLOAD Válido (1.Edificio, 2.Imovel, 3.Vendedor)")); } if (Convert.ToInt64(idReferencia) <= 0) { return(this.StatusCode(StatusCodes.Status401Unauthorized, "Favor informar um Id de Referência Válido.")); } var folderName = ""; //var pathToSave = "C:\\Projetos\\reclameaqui\\ReclameAquiAdmin\\src\\assets"; var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), "Resources"); //var pathToSave = "C:\\Users\\evito\\projetos\\WAIH\\smartimoveis\\smartimoveisAdmin\\src\\assets"; string[] extensoesImagens = new string[] { ".jpg", ".png", ".jpeg" }; if (file.Length > 0) { var nameTipoArquivo = ""; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var extension = Path.GetExtension(fileName); if (extensoesImagens.Contains(extension)) { folderName = "Image"; nameTipoArquivo = DateTime.Now.ToString().Replace(":", "-").Replace(" ", "").Replace("/", "-") + "-IDR-" + idReferencia + "-TU-" + tipoUpload + extension; } else { return(this.StatusCode(StatusCodes.Status401Unauthorized, "Só é permitido UPLOAD de Imagens.")); } pathToSave = Path.Combine(pathToSave, folderName); var fullPath = Path.Combine(pathToSave, fileName); var fullPathNew = Path.Combine(pathToSave, nameTipoArquivo); //var dbPath = Path.Combine("assets", folderName, nameTipoArquivo); var dbPath = Path.Combine(folderName, nameTipoArquivo); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } System.IO.File.Move(fullPath, fullPathNew); if (Convert.ToInt32(tipoUpload) == 1) //Edificio { var listFotoEdificio = await _repo.GetFotosEdificioByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoEdificio(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.EdificioId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 2) //Imovel { var listFotoEdificio = await _repo.GetFotosImovelByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoImovel(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.ImovelId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 3) //Vendedor { var oVendedor = await _repo.GetVendedorByIdAsync(Convert.ToInt64(idReferencia)); oVendedor.Foto = dbPath; _repo.Update(oVendedor); } else if (Convert.ToInt32(tipoUpload) == 4) //FotoAreaEdificio { var listFotoEdificio = await _repo.GetFotosAreaEdificioByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoAreaEdificio(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.EdificioId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 5) //FotoPlantaEdificio { var listFotoEdificio = await _repo.GetFotosPlantaEdificioByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoPlantaEdificio(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.EdificioId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 6) //FotoAreaImovel { var listFotoEdificio = await _repo.GetFotosAreaImovelByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoAreaImovel(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.ImovelId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 7) //FotoPlantaImovel { var listFotoEdificio = await _repo.GetFotosPlantaImovelByIdAsync(Convert.ToInt64(idReferencia)); var ordemFinal = 1; if (listFotoEdificio.Count() > 0) { var fotoF = listFotoEdificio.OrderByDescending(x => x.Ordem).FirstOrDefault(); ordemFinal = fotoF.Ordem + 1; } var oFoto = new FotoPlantaImovel(); dbPath = dbPath.Replace("\\", "/"); oFoto.NomeFoto = nameTipoArquivo; oFoto.Caminho = dbPath; oFoto.Ordem = Convert.ToInt32(ordemFinal); oFoto.ImovelId = Convert.ToInt64(idReferencia); _repo.Add(oFoto); } else if (Convert.ToInt32(tipoUpload) == 8) //Foto Padrão Imovel { var listFotoEdificio = _repo.GetFotosEdificioByIdAsync(Convert.ToInt64(idReferencia)); var oFoto = await _repo.GetFotosImovelByIdAsync(Convert.ToInt64(idReferencia)); dbPath = dbPath.Replace("\\", "/"); var oFotoF = oFoto.Where(x => x.Ordem == 0).FirstOrDefault(); if (oFotoF == null) { oFotoF = new FotoImovel(); oFotoF.NomeFoto = nameTipoArquivo; oFotoF.Caminho = dbPath; oFotoF.Ordem = 0; oFotoF.ImovelId = Convert.ToInt64(idReferencia); _repo.Add(oFotoF); } else { oFotoF.NomeFoto = nameTipoArquivo; oFotoF.Caminho = dbPath; oFotoF.Ordem = 0; _repo.Update(oFotoF); } } else if (Convert.ToInt32(tipoUpload) == 9) //Foto Padrão Edificio { var oFoto = await _repo.GetFotosEdificioByIdAsync(Convert.ToInt64(idReferencia)); dbPath = dbPath.Replace("\\", "/"); var oFotoF = oFoto.Where(x => x.Ordem == 0).FirstOrDefault(); if (oFotoF == null) { oFotoF = new FotoEdificio(); oFotoF.NomeFoto = nameTipoArquivo; oFotoF.Caminho = dbPath; oFotoF.Ordem = 0; oFotoF.EdificioId = Convert.ToInt64(idReferencia); _repo.Add(oFotoF); } else { oFotoF.NomeFoto = nameTipoArquivo; oFotoF.Caminho = dbPath; oFotoF.Ordem = 0; _repo.Update(oFotoF); } } if (await _repo.SaveChangesAsync()) { var ftpApi = new FTP { Host = _config.GetValue <string>("FTP:Host"), Login = _config.GetValue <string>("FTP:Login"), Senha = _config.GetValue <string>("FTP:Senha") }; using (WebClient client = new WebClient()) { client.Credentials = new NetworkCredential(ftpApi.Login, ftpApi.Senha); var caminhoftp = $"ftp://{ftpApi.Host}/{dbPath}"; client.UploadFile(caminhoftp, WebRequestMethods.Ftp.UploadFile, fullPathNew); } return(Ok(new { dbPath })); } } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex.Message}")); } return(BadRequest()); }