コード例 #1
0
        private OfertaViaVarejo ProccessCasasBahia(OfertaContainerModel model)
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("https://preco.api-casasbahia.com.br");
            var response  = client.GetStringAsync("V1/Skus/PrecoVenda/?idssku=" + model.SKU).Result;
            var resultApi = Newtonsoft.Json.JsonConvert.DeserializeObject <OfertaViaVarejoAPI>(response);
            var result    = new OfertaViaVarejo()
            {
                PrecoSku = resultApi.PrecoSkus.First()
            };

            result.Bandeira = "Casas Bahia";
            return(result);
        }
コード例 #2
0
        public IActionResult ProcessarOferta(OfertaContainerModel model)
        {
            var list          = new List <OfertaViaVarejo>();
            var currentOferta = new OfertaViaVarejo();

            if (model.Bandeira.ToLower() == "ponto frio")
            {
                currentOferta = ProccessPontoFrio(model);
                list.Add(ProccessExtra(model));
                list.Add(ProccessCasasBahia(model));
            }
            else if (model.Bandeira.ToLower() == "casas bahia")
            {
                currentOferta = ProccessCasasBahia(model);
                list.Add(ProccessExtra(model));
                list.Add(ProccessPontoFrio(model));
            }
            else if (model.Bandeira.ToLower() == "extra")
            {
                currentOferta = ProccessExtra(model);
                list.Add(ProccessPontoFrio(model));
                list.Add(ProccessCasasBahia(model));
            }
            OfertaCompareResultModel result = new OfertaCompareResultModel()
            {
                Ofertas = list
            };

            if (currentOferta.PrecoSku.PrecoVenda.Preco < model.PrecoFinal)
            {
                result.Mensagem = "Preço desatualizado";
            }

            result.OfertaValida = list.All(x => x.PrecoSku.PrecoVenda.Preco < currentOferta.PrecoSku.PrecoVenda.Preco);
            return(Ok(result));
        }