Esempio n. 1
0
        // PUT /tbManifesto/token/
        public HttpResponseMessage Put(string token, [FromBody] tbManifesto param)
        {
            using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext())
            {
                tbLogAcessoUsuario log = new tbLogAcessoUsuario();
                try
                {
                    log = Bibliotecas.LogAcaoUsuario.New(token, JsonConvert.SerializeObject(param), "Put", _db);

                    HttpResponseMessage retorno = new HttpResponseMessage();
                    if (Permissoes.Autenticado(token, _db))
                    {
                        GatewayTbManifesto.Update(token, param, _db);
                        log.codResposta = (int)HttpStatusCode.OK;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        log.codResposta = (int)HttpStatusCode.Unauthorized;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }
                catch (Exception e)
                {
                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                    log.msgErro     = e.Message;
                    Bibliotecas.LogAcaoUsuario.Save(log);
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
        }
Esempio n. 2
0
        // GET /tbManifesto/token/colecao/campo/orderBy/pageSize/pageNumber?CAMPO1=VALOR&CAMPO2=VALOR
        public HttpResponseMessage Get(string token, int colecao = 0, int campo = 0, int orderBy = 0, int pageSize = 0, int pageNumber = 0)
        {
            using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext())
            {
                tbLogAcessoUsuario log = new tbLogAcessoUsuario();
                try
                {
                    log = Bibliotecas.LogAcaoUsuario.New(token, null, "Get", _db);

                    Dictionary <string, string> queryString = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
                    HttpResponseMessage         retorno     = new HttpResponseMessage();
                    if (Permissoes.Autenticado(token, _db))
                    {
                        Retorno dados = GatewayTbManifesto.Get(token, colecao, campo, orderBy, pageSize, pageNumber, queryString, _db);
                        log.codResposta = (int)HttpStatusCode.OK;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse <Retorno>(HttpStatusCode.OK, dados));
                    }
                    else
                    {
                        log.codResposta = (int)HttpStatusCode.Unauthorized;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }
                catch (Exception e)
                {
                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                    log.msgErro     = e.Message;
                    Bibliotecas.LogAcaoUsuario.Save(log);
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
        }
Esempio n. 3
0
        // PATCH /tbManifesto/token/
        public HttpResponseMessage Patch(string token)
        {
            // Abre nova conexão
            using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext())
            {
                tbLogAcessoUsuario log = new tbLogAcessoUsuario();
                try
                {
                    log = Bibliotecas.LogAcaoUsuario.New(token, null, "Patch", _db);

                    HttpResponseMessage retorno = new HttpResponseMessage();
                    if (Permissoes.Autenticado(token, _db))
                    {
                        Dictionary <string, string> queryString = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
                        Mensagem mensagem = GatewayTbManifesto.Patch(token, queryString, _db);
                        log.codResposta = mensagem.cdMensagem;
                        if (mensagem.cdMensagem != 200)
                        {
                            log.msgErro = mensagem.dsMensagem;
                        }
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse <Mensagem>(HttpStatusCode.OK, mensagem));
                    }
                    else
                    {
                        log.codResposta = (int)HttpStatusCode.Unauthorized;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }
                catch (Exception e)
                {
                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                    log.msgErro     = e.Message;
                    Bibliotecas.LogAcaoUsuario.Save(log);
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
        }
Esempio n. 4
0
        public HttpResponseMessage Get(string token, int colecao = 0, int campo = 0, int orderBy = 0, int pageSize = 0, int pageNumber = 0)
        {
            // Abre nova conexão
            using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext())
            {
                tbLogAcessoUsuario log = new tbLogAcessoUsuario();
                try
                {
                    log = Bibliotecas.LogAcaoUsuario.New(token, null, "Get", _db);

                    Dictionary <string, string> queryString = new Dictionary <string, string>();
                    queryString = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
                    HttpResponseMessage retorno = new HttpResponseMessage();
                    if (Permissoes.Autenticado(token, _db))
                    {
                        HttpResponseMessage result = null;
                        byte[] arquivo             = null;
                        string nmArquivo           = null;

                        if (colecao == 0) // [PORTAL] Download de um XML NFe
                        {
                            Retorno dados = GatewayTbManifesto.Get(token, 0, campo, orderBy, pageSize, pageNumber, queryString, _db);
                            if (dados.TotalDeRegistros > 0)
                            {
                                dynamic item = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave }).First();
                                arquivo   = GatewayUtilNfe.ArquivoXml(Convert.ToString(item.xmlNFe));
                                nmArquivo = item.nrChave + ".xml";

                                if (arquivo.Length > 0)
                                {
                                    result         = Request.CreateResponse(HttpStatusCode.OK);
                                    result.Content = new StreamContent(new MemoryStream(arquivo));
                                    result.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                                    result.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                                    result.Content.Headers.ContentDisposition.FileName = nmArquivo;
                                    result.Content.Headers.Add("x-filename", nmArquivo);
                                    log.codResposta = (int)HttpStatusCode.OK;
                                    Bibliotecas.LogAcaoUsuario.Save(log, _db);
                                    return(result);
                                }
                                else
                                {
                                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                                    Bibliotecas.LogAcaoUsuario.Save(log);
                                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                                }

                                //return result;
                            }
                            else
                            {
                                log.codResposta = (int)HttpStatusCode.NotFound;
                                Bibliotecas.LogAcaoUsuario.Save(log, _db);
                                throw new HttpResponseException(HttpStatusCode.NotFound);
                            }
                        }
                        else if (colecao == 1) // [PORTAL] Download de um Arquivo ZIP Contendo vários XMLs NFe
                        {
                            Retorno dados = GatewayTbManifesto.Get(token, 0, campo, orderBy, pageSize, pageNumber, queryString, _db);
                            dynamic itens = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave }).ToList();

                            arquivo = GatewayUtilNfe.DownloadZipXmls(dados.Registros);
                            dynamic item      = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave, dtEmissao = e.dtEmissao, nmEmitente = e.nmEmitente, nrEmitenteCNPJCPF = e.nrEmitenteCNPJCPF }).First();
                            string  dtEmissao = item.dtEmissao.ToString().Replace('/', '-'); //DateTime.ParseExact(item.dtEmissao + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture).ToString("yyyyMMdd HH:mm:ss.fff");
                            nmArquivo = "XMLs - " + dtEmissao + " - " + item.nmEmitente + " - " + item.nrEmitenteCNPJCPF + ".zip";

                            if (arquivo.Length > 0)
                            {
                                result         = Request.CreateResponse(HttpStatusCode.OK);
                                result.Content = new StreamContent(new MemoryStream(arquivo));
                                result.Content.Headers.ContentDisposition              = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                                result.Content.Headers.ContentType                     = new MediaTypeHeaderValue("application/octet-stream");
                                result.Content.Headers.ContentDisposition.FileName     = nmArquivo;
                                result.Content.Headers.ContentDisposition.Name         = nmArquivo;
                                result.Content.Headers.ContentDisposition.FileNameStar = nmArquivo;
                                result.Content.Headers.Add("x-filename", nmArquivo);
                            }
                            log.codResposta = (int)HttpStatusCode.OK;
                            Bibliotecas.LogAcaoUsuario.Save(log, _db);
                            return(result);
                        }
                        else if (colecao == 2) // [PORTAL] Download de um PDF DANFE
                        {
                            Retorno dados = GatewayTbManifesto.Get(token, 0, campo, orderBy, pageSize, pageNumber, queryString, _db);
                            if (dados.TotalDeRegistros > 0)
                            {
                                dynamic item = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave }).First();
                                arquivo   = GatewayUtilNfe.PDFDanfe(Convert.ToString(item.xmlNFe), Convert.ToString(item.nrChave));
                                nmArquivo = item.nrChave + ".pdf";

                                if (arquivo.Length > 0)
                                {
                                    result         = Request.CreateResponse(HttpStatusCode.OK);
                                    result.Content = new StreamContent(new MemoryStream(arquivo));
                                    result.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                                    result.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                                    result.Content.Headers.ContentDisposition.FileName = nmArquivo;
                                    result.Content.Headers.Add("x-filename", nmArquivo);
                                }
                                log.codResposta = (int)HttpStatusCode.OK;
                                Bibliotecas.LogAcaoUsuario.Save(log, _db);
                                return(result);
                            }
                            else
                            {
                                log.codResposta = (int)HttpStatusCode.NotFound;
                                Bibliotecas.LogAcaoUsuario.Save(log, _db);
                                throw new HttpResponseException(HttpStatusCode.NotFound);
                            }
                        }
                        else if (colecao == 3) // [PORTAL] Download de um Arquivo ZIP Contendo vários PDFs DANFE
                        {
                            Retorno dados = GatewayTbManifesto.Get(token, 0, campo, orderBy, pageSize, pageNumber, queryString, _db);
                            dynamic itens = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave }).ToList();

                            arquivo = GatewayUtilNfe.DownloadZipPdfs(dados.Registros);
                            dynamic item      = dados.Registros.Cast <dynamic>().Select(e => new { xmlNFe = e.xmlNFe, nrChave = e.nrChave, dtEmissao = e.dtEmissao, nmEmitente = e.nmEmitente, nrEmitenteCNPJCPF = e.nrEmitenteCNPJCPF }).First();
                            string  dtEmissao = item.dtEmissao.ToString().Replace('/', '-'); //DateTime.ParseExact(item.dtEmissao + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture).ToString("yyyyMMdd HH:mm:ss.fff");
                            nmArquivo = "PDFs - " + dtEmissao + " - " + item.nmEmitente + " - " + item.nrEmitenteCNPJCPF + ".zip";

                            if (arquivo.Length > 0)
                            {
                                result         = Request.CreateResponse(HttpStatusCode.OK);
                                result.Content = new StreamContent(new MemoryStream(arquivo));
                                result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                                result.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
                                //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                                result.Content.Headers.ContentDisposition.FileName = nmArquivo;
                                result.Content.Headers.Add("x-filename", nmArquivo);
                            }
                            log.codResposta = (int)HttpStatusCode.OK;
                            Bibliotecas.LogAcaoUsuario.Save(log, _db);
                            return(result);
                        }
                        else
                        {
                            log.codResposta = (int)HttpStatusCode.NotFound;
                            Bibliotecas.LogAcaoUsuario.Save(log, _db);
                            throw new HttpResponseException(HttpStatusCode.NotFound);
                        }
                    }
                    else
                    {
                        log.codResposta = (int)HttpStatusCode.Unauthorized;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }
                catch (Exception e)
                {
                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                    log.msgErro     = e.Message;
                    Bibliotecas.LogAcaoUsuario.Save(log);
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
        }
Esempio n. 5
0
        // POST /Upload/token/tipo
        public HttpResponseMessage Post(string token, int tipo)
        {
            // Abre nova conexão
            using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext())
            {
                tbLogAcessoUsuario log = new tbLogAcessoUsuario();
                try
                {
                    log = Bibliotecas.LogAcaoUsuario.New(token, JsonConvert.SerializeObject(new { tipo = tipo }), "Post", _db);

                    HttpResponseMessage retorno = new HttpResponseMessage();
                    if (Permissoes.Autenticado(token, _db))
                    {
                        Dictionary <string, string> queryString = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
                        if (queryString != null)
                        {
                            // Remove os dois
                            queryString.Remove("token");
                            queryString.Remove("tipo");
                        }
                        object resp       = null;
                        TIPO   tipoUpload = (TIPO)tipo;
                        switch (tipoUpload)
                        {
                        case TIPO.TITULO:
                            GatewayTitulosErp.Patch(token, log, _db);
                            log.codResposta = (int)HttpStatusCode.OK;
                            break;

                        case TIPO.EXTRATO:
                            resp            = GatewayTbExtrato.Patch(token, queryString, log, _db);
                            log.codResposta = (int)HttpStatusCode.OK;
                            break;

                        case TIPO.NFE:
                            Mensagem mensagemN = GatewayTbManifesto.Patch(token, queryString, _db);
                            log.codResposta = mensagemN.cdMensagem;
                            if (mensagemN.cdMensagem != 200)
                            {
                                log.msgErro = mensagemN.dsMensagem;
                            }
                            resp = mensagemN;
                            break;

                        case TIPO.CERTIFICADODIGITAL:
                            Mensagem mensagemC = GatewayTbEmpresa.Patch(token, queryString, _db);
                            log.codResposta = mensagemC.cdMensagem;
                            if (mensagemC.cdMensagem != 200)
                            {
                                log.msgErro = mensagemC.dsMensagem;
                            }
                            resp = mensagemC;
                            break;

                        default:
                            return(Request.CreateResponse(HttpStatusCode.BadRequest));
                        }
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        if (resp != null)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, resp));
                        }
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        log.codResposta = (int)HttpStatusCode.Unauthorized;
                        Bibliotecas.LogAcaoUsuario.Save(log, _db);
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }
                catch (Exception e)
                {
                    log.codResposta = (int)HttpStatusCode.InternalServerError;
                    log.msgErro     = e.Message;
                    Bibliotecas.LogAcaoUsuario.Save(log);
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
                }
            }
        }