Example #1
0
        public HttpResponseMessage Atualizar(PlataformaEdicaoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Plataforma p = new Plataforma();
                    p.IdPlataforma = model.IdPlataforma;
                    p.Nome         = model.Nome;
                    p.Modelo       = model.Modelo;

                    PlataformaRepository rep = new PlataformaRepository();
                    rep.Update(p);

                    return(Request.CreateResponse(HttpStatusCode.OK, "Plataforma atualizada com sucesso."));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Ocorreu um ou mais erros de validação nos campos enviados."));
            }
        }
Example #2
0
        public HttpResponseMessage ConsultarPorId(int id)
        {
            try
            {
                PlataformaRepository rep = new PlataformaRepository();
                Plataforma           p   = rep.FindById(id);

                if (p != null)
                {
                    PlataformaConsultaViewModel model = new PlataformaConsultaViewModel();

                    model.IdPlataforma = p.IdPlataforma;
                    model.Nome         = p.Nome;
                    model.Modelo       = p.Modelo;

                    return(Request.CreateResponse(HttpStatusCode.OK, model));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Plataforma não localizada."));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
            }
        }
Example #3
0
        public async Task PostPedidosAsync(Encomenda encomenda, PlataformaRepository plataformaRepository)
        {
            RestClientFactory restClientFactory = new RestClientFactory(this._config);

            try
            {
                IRestResponse response = await restClientFactory.RestAPI("newOrder", Method.POST, encomenda);

                if (response.IsSuccessful)
                {
                    await plataformaRepository.CommitPedidosAsync(encomenda.Pedido, encomenda.DocFiscalNFe.NfeNumero, GerarTrackingUrl(encomenda));

                    string retorno = $"OrderId: {encomenda.Pedido} - Incluido.";
                    Console.WriteLine(retorno);
                }
                else
                {
                    await GerarLog(encomenda, response.Content);
                }
            }
            catch (Exception e)
            {
                await GerarLog(encomenda, e.Message);
            }
        }
Example #4
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                PlataformaRepository rep = new PlataformaRepository();
                Plataforma           p   = rep.FindById(id);

                if (p != null)
                {
                    rep.Delete(p);

                    return(Request.CreateResponse(HttpStatusCode.OK, "Plataforma excluída com sucesso."));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Plataforma não localizada."));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
            }
        }
Example #5
0
        public HttpResponseMessage Consultar()
        {
            try
            {
                List <PlataformaConsultaViewModel> lista = new List <PlataformaConsultaViewModel>();
                PlataformaRepository rep = new PlataformaRepository();

                foreach (Plataforma p in rep.FindAll())
                {
                    PlataformaConsultaViewModel model = new PlataformaConsultaViewModel();
                    model.IdPlataforma = p.IdPlataforma;
                    model.Nome         = p.Nome;
                    model.Modelo       = p.Modelo;

                    lista.Add(model);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, lista));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
            }
        }
Example #6
0
        public async Task ProcessaEncomendasAsync()
        {
            using (var conn = dbConnectionFactory.Create())
            {
                var  plataformaRepository = new PlataformaRepository(conn, this._config);
                var  logService           = new LogService();
                bool geraLog     = _config.GetValue <bool>("GeraArquivoLog");
                var  listPedidos = await plataformaRepository.GetPedidosAsync();

                var totalPedidos = listPedidos.Count;

                Console.WriteLine($"-------------------------------------------------------------------------------------------------------");
                Console.WriteLine($"Processando Encomendas - ({totalPedidos})  - {DateTime.Now}");
                Console.WriteLine($"-------------------------------------------------------------------------------------------------------");

                if (listPedidos.Count > 0)
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    foreach (var pedido in listPedidos)
                    {
                        try
                        {
                            bool status = await plataformaRepository.CheckPedidoAsync(pedido.Pedido);

                            //teste();
                            //Console.WriteLine(GerarTrackingUrl(pedido));
                            if (status)
                            {
                                await PostPedidosAsync(pedido, plataformaRepository);
                            }
                            else
                            {
                                Console.WriteLine($"Pedido já cadastrado - OrderId: {pedido.Pedido}");
                            }
                        }
                        catch (Exception e)
                        {
                            string retorno = $"Erro OrderId: {pedido.Pedido} - ({e.Message}) - {DateTime.Now}.";
                            Console.WriteLine(retorno);

                            await plataformaRepository.PedidoLogAsync(pedido.Pedido, retorno);

                            if (geraLog)
                            {
                                string fileName = $"{pedido.Pedido}";
                                var    log      = new RetornoLog();
                                log.acao     = $"PostEncomendaPlataforma";
                                log.message  = retorno;
                                log.request  = pedido;
                                log.response = e.Message;

                                await logService.LogGerarArquivoAsync(fileName, "Plataforma", log);
                            }
                        }
                    }

                    sw.Stop();

                    Console.WriteLine($"Processamento de Pedidos da Plataforma Concluido com Sucesso. Total ({totalPedidos}) - {DateTime.Now} - ({sw.ElapsedMilliseconds / 1000}s)");
                }
            }
        }