Example #1
0
        public async Task Execute(ConsultarAnuncioInput consultarAnuncioInput)
        {
            if (consultarAnuncioInput.Id == 0)
            {
                _outputHandler.NotFound($"Codigo do anuncio inválido.");
                return;
            }

            IAnuncio anuncio     = null;
            string   anuncioJson = _cache.GetString($"Anuncio:{consultarAnuncioInput.Id}");

            if (anuncioJson == null)
            {
                anuncio = await _anuncioRepository.Get(consultarAnuncioInput.Id);
            }

            if (anuncio == null)
            {
                _outputHandler.NotFound($"Anuncio não encontrado.");
                return;
            }

            if (anuncioJson == null)
            {
                anuncioJson = JsonConvert.SerializeObject(anuncio);
                DistributedCacheEntryOptions opcoesCache = new DistributedCacheEntryOptions();
                opcoesCache.SetAbsoluteExpiration(TimeSpan.FromMinutes(5));
                _cache.SetString($"Anuncio:{anuncio.ID}", anuncioJson, opcoesCache);
            }

            ConsultarAnuncioOutput consultarAnuncioOutput = new ConsultarAnuncioOutput(anuncio);

            _outputHandler.Default(consultarAnuncioOutput);
        }
Example #2
0
        public void Default(ConsultarAnuncioOutput consultarAnuncioOutput)
        {
            var anuncio = new AnuncioModel
            {
                ID            = consultarAnuncioOutput.Anuncio.ID,
                Marca         = consultarAnuncioOutput.Anuncio.Marca,
                Modelo        = consultarAnuncioOutput.Anuncio.Modelo,
                Versao        = consultarAnuncioOutput.Anuncio.Versao,
                Ano           = consultarAnuncioOutput.Anuncio.Ano,
                Quilometragem = consultarAnuncioOutput.Anuncio.Quilometragem,
                Observacao    = consultarAnuncioOutput.Anuncio.Observacao
            };

            var consultarAnuncioResponse = new ConsultarAnuncioResponse(anuncio);

            ViewModel = new OkObjectResult(consultarAnuncioResponse);
        }