public async Task <IActionResult> Post(XML model, 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 Parceiro = await _repo.GetXMLByParceiroIdAsync(model.ParceiroId);

                if (Parceiro != null)
                {
                    return(this.StatusCode(StatusCodes.Status401Unauthorized, "XML ja cadastrado para esse parceiro."));
                }
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(this.StatusCode(StatusCodes.Status200OK, model));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Post(Vendedor model, 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 login = _repo.GetVendedorByUserAsync(model.Usuario);
                if (login.Result != null)
                {
                    return(this.StatusCode(StatusCodes.Status401Unauthorized, "Usuario ja existe."));
                }
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(this.StatusCode(StatusCodes.Status200OK, model));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
예제 #3
0
        public async Task <IActionResult> Post(Contato model, 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
            {
                model.DataAbertura = DateTime.Now;
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(this.StatusCode(StatusCodes.Status200OK, model));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
예제 #4
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 controleArquivosXml = await _repo.GetAllControleAquivoXMLAsync();

                var parceiros = await _repo.GetAllParceirosAsync();

                foreach (var parceiro in parceiros)
                {
                    var controle = controleArquivosXml.Where(x => x.ParceiroId == parceiro.Id).FirstOrDefault();
                    if (controle != null)
                    {
                        controle.FlagArquivoXML  = false;
                        controle.DataSolicitacao = DateTime.Now;
                        controle.Mensagem        = $"Iniciado processo de criação do arquivo para o parceiro: {controle.oParceiro.Nome} na data: {DateTime.Now.ToString("dd/MM/yyyy")}.";
                        _repo.Update(controle);
                        await _repo.SaveChangesAsync();
                    }
                    else
                    {
                        var controleNew = new ControleArquivoXML();
                        controleNew.ParceiroId      = parceiro.Id;
                        controleNew.FlagArquivoXML  = false;
                        controleNew.DataSolicitacao = DateTime.Now;
                        controleNew.Mensagem        = $"Iniciado processo de criação do arquivo para o parceiro: {parceiro.Nome} na data: {DateTime.Now.ToString("dd/MM/yyyy")}.";
                        _repo.Add(controleNew);
                        await _repo.SaveChangesAsync();
                    }
                }

                Thread thread = new Thread(GeraArquivosXML);
                thread.Start();

                return(this.StatusCode(StatusCodes.Status200OK));
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Ocorreu um erro no banco de Dados.{ex.Message}"));
            }
        }
        public async Task <IActionResult> Put(ParceiroCarga[] listModel, 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
            {
                foreach (var model in listModel)
                {
                    _repo.Update(model);
                    await _repo.SaveChangesAsync();
                }
                return(this.StatusCode(StatusCodes.Status200OK, listModel));
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
        }
예제 #6
0
        public async Task <IActionResult> Post(Parceiro model, 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 Parceiro = await _repo.GetParceiroByNameAsync(model.Nome);

                if (Parceiro != null)
                {
                    return(this.StatusCode(StatusCodes.Status401Unauthorized, "Parceiro ja existe."));
                }
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    var oParceiroCarga = new ParceiroCarga
                    {
                        ParceiroId     = model.Id,
                        AnuncioSimples = 0,
                        Destaque       = 0,
                        SuperDestaque  = 0
                    };
                    _repo.Add(oParceiroCarga);

                    if (await _repo.SaveChangesAsync())
                    {
                        return(this.StatusCode(StatusCodes.Status200OK, model));
                    }
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Post(Imovel model, 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 Imovel = await _repo.GetImovelByRefAsync(model.Nome);

                if (Imovel != null)
                {
                    return(this.StatusCode(StatusCodes.Status401Unauthorized, "Imovel ja existe com essa Referencia."));
                }
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/Imoveis/GetById/{model.Id}", model));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
        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());
        }