public virtual NotaFiscalEntity GetNotaFiscalByChave(string chave, int ambiente)
 {
     using (var context = new NFeContext())
     {
         return(context.NotaFiscal.FirstOrDefault(n => n.Chave == chave && n.Ambiente == ambiente));
     }
 }
 public NotaFiscalEntity GetPrimeiraNotaEmitidaEmContingencia(DateTime dataHoraContingencia, DateTime now)
 {
     using (var context = new NFeContext())
     {
         return(context.NotaFiscal.Where(n => n.Status == 3 && n.DataEmissao >= dataHoraContingencia)
                .OrderBy(n => n.DataEmissao).FirstOrDefault());
     }
 }
 public IEnumerable <NotaFiscalEntity> GetNotasFiscaisPorMesAno(DateTime mesAno, bool isProducao)
 {
     using (var context = new NFeContext())
     {
         return(context.NotaFiscal.Where(n =>
                                         n.DataEmissao.Month.Equals(mesAno.Month) && n.DataEmissao.Year == mesAno.Year &&
                                         n.IsProducao == isProducao).ToList());
     }
 }
 public List <NotaFiscalEntity> GetNotasContingencia()
 {
     using (var context = new NFeContext())
     {
         var config = context.Configuracao.FirstOrDefault();
         return(context.NotaFiscal
                .Where(n => n.Status == (int)Status.CONTINGENCIA && n.IsProducao == config.IsProducao).ToList());
     }
 }
 public List <NotaFiscalEntity> GetNotasPendentes()
 {
     using (var context = new NFeContext())
     {
         var config = context.Configuracao.FirstOrDefault();
         return(context.NotaFiscal
                .Where(n => n.Status == (int)Status.PENDENTE && n.IsProducao == config.IsProducao).ToList());
     }
 }
 public NotaFiscalEntity GetNota(string numero, string serie, string modelo)
 {
     using (var context = new NFeContext())
     {
         var config = context.Configuracao.FirstOrDefault();
         return(context.NotaFiscal.FirstOrDefault(c =>
                                                  c.Numero.Equals(numero) && c.Serie.Equals(serie) && c.Modelo.Equals(modelo) &&
                                                  c.IsProducao == config.IsProducao));
     }
 }
 public IEnumerable <NotaFiscalEntity> GetNotasFiscaisPorPeriodo(DateTime periodoInicial, DateTime periodoFinal)
 {
     using (var context = new NFeContext())
     {
         var config = context.Configuracao.FirstOrDefault();
         return(context.NotaFiscal.Where(n =>
                                         n.DataEmissao >= periodoInicial && n.DataEmissao <= periodoFinal &&
                                         n.IsProducao == config.IsProducao &&
                                         n.Status == (int)Status.ENVIADA).ToList());
     }
 }
 public void ExcluirNota(string numero, string serie, string modelo)
 {
     using (var context = new NFeContext())
     {
         var config = context.Configuracao.FirstOrDefault();
         var nota   = context.NotaFiscal.First(c =>
                                               c.Numero.Equals(numero) && c.Serie.Equals(serie) && c.Modelo.Equals(modelo) &&
                                               c.IsProducao == config.IsProducao);
         context.NotaFiscal.Remove(nota);
         context.SaveChanges();
     }
 }
        public List <NotaFiscalEntity> Take(int quantity)
        {
            using (var context = new NFeContext())
            {
                var config = context.Configuracao.FirstOrDefault();

                if (config == null)
                {
                    return(null);
                }

                return(context.NotaFiscal.Where(n => n.IsProducao == config.IsProducao).Take(quantity).ToList());
            }
        }
        public NotaFiscalEntity GetNotaFiscalById(int idNotaFiscalDb, bool isLoadXmlData)
        {
            using (var context = new NFeContext())
            {
                var notaTo = context.NotaFiscal.FirstOrDefault(n => n.Id == idNotaFiscalDb);

                if (isLoadXmlData)
                {
                    notaTo.LoadXml();
                }

                return(notaTo);
            }
        }
        public int Salvar(NotaFiscalEntity notafiscal)
        {
            using (var context = new NFeContext())
            {
                if (notafiscal.Id == 0)
                {
                    context.Entry(notafiscal).State = EntityState.Added;
                }
                else
                {
                    context.Entry(notafiscal).State = EntityState.Modified;
                }

                context.SaveChanges();
                return(notafiscal.Id);
            }
        }
        public IEnumerable <NotaFiscalEntity> Take(int pageSize, int page)
        {
            int skip = (page - 1) * pageSize;

            using (var context = new NFeContext())
            {
                var config = context.Configuracao.FirstOrDefault();

                if (config == null)
                {
                    return(null);
                }

                return(context.NotaFiscal
                       .Where(n => n.IsProducao == config.IsProducao).OrderByDescending(n => n.Id)
                       .Skip(skip)
                       .Take(pageSize)
                       .ToList());
            }
        }
        public async Task DoWork(CancellationToken stoppingToken)
        {
            var host = Environment.GetEnvironmentVariable("QUEUEHOST");

            Console.WriteLine("Host do RabbitMQ" + host);
            ConnectionFactory factory = new ConnectionFactory()
            {
                HostName = host, Port = 5672, UserName = "******", Password = "******"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())

                    while (!stoppingToken.IsCancellationRequested)

                    {
                        executionCount++;
                        _logger.LogInformation("Service is working. Count: {Count}", executionCount);

                        channel.QueueDeclare(queue: "NFeQueue",
                                             durable: false,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        var consumer = new EventingBasicConsumer(channel);
                        consumer.Received += (model, ea) =>
                        {
                            var body    = ea.Body;
                            var message = Encoding.UTF8.GetString(body.ToArray());

                            Console.WriteLine("Received {0}", message);
                            var nfe = JsonSerializer.Deserialize <NFe>(message);

                            using (var db = new NFeContext()){
                                //db.Database.EnsureCreated();
                                //db.NFes.Attach(nfe);
                                //db.Entry(nfe).State = EntityState.Modified;

                                var entity = db.NFes.FirstOrDefault(item => item.DocumentId == nfe.DocumentId);
                                if (entity != null)
                                {
                                    entity.Status             = nfe.Status;
                                    entity.EntidadeId         = nfe.EntidadeId;
                                    entity.Ambiente           = nfe.Ambiente;
                                    entity.Modalidade         = nfe.Modalidade;
                                    entity.DataRecepcao       = nfe.DataRecepcao;
                                    entity.StatusDistribuicao = nfe.StatusDistribuicao;
                                    entity.CorrelationId      = nfe.CorrelationId;
                                    entity.Xml = nfe.Xml;
                                }
                                else
                                {
                                    db.NFes.Add(nfe);
                                }
                                db.SaveChanges();
                            }
                        };
                        channel.BasicConsume(queue: "NFeQueue",
                                             autoAck: true,
                                             consumer: consumer);

                        await Task.Delay(3000, stoppingToken);
                    }
        }
Esempio n. 14
0
 public EstadoRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 15
0
 public ConfiguracaoRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 16
0
 public InvoiceRepository(NFeContext context)
 {
     _context = context;
 }
Esempio n. 17
0
 public EventoRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 18
0
 public NotaInutilizadaRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 19
0
 public ProductRepository(NFeContext context)
 {
     _context = context;
 }
Esempio n. 20
0
 public ProdutoRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 21
0
 public NFeRepository(NFeContext ctx)
 {
     context = ctx;
 }
Esempio n. 22
0
 public ShippingCompanyRepository(NFeContext context)
 {
     _context = context;
 }
Esempio n. 23
0
 public NFesController(NFeContext context)
 {
     _context = context;
 }
Esempio n. 24
0
 public TransportadoraRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 25
0
 public IssuerRepository(NFeContext context)
 {
     _context = context;
 }
Esempio n. 26
0
 public AddresseReposiotory(NFeContext context)
 {
     _context = context;
 }
 public DestinatarioRepository()
 {
     _context = new NFeContext();
 }
Esempio n. 28
0
 public EmitenteRepository()
 {
     _context = new NFeContext();
 }
 public CertificadoRepository()
 {
     _context = new NFeContext();
 }
 public HistoricoEnvioContabilidadeRepository()
 {
     _context = new NFeContext();
 }