Beispiel #1
0
        public async Task Corfirmar(ConfirmarAnuncio confirmar)
        {
            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext ctx = new DynamoDBContext(client))
                {
                    AnuncioDBModel registro = await ctx.LoadAsync <AnuncioDBModel>(confirmar.Id);

                    if (registro == null)
                    {
                        throw new KeyNotFoundException($"O registro ID: {confirmar.Id} nao foi encontrado.");
                    }

                    if (confirmar.Status == StatusAnuncio.Ativo)
                    {
                        registro.Status = StatusAnuncio.Ativo;
                        await ctx.SaveAsync(registro);
                    }
                    else
                    {
                        await ctx.DeleteAsync(registro);
                    }
                }
            }
        }
        public async Task <bool> Confirmar(ConfirmarAnuncioModelRequest confirmar)
        {
            ConfirmarAnuncio entradaAPI  = _mapper.Map <ConfirmarAnuncio>(confirmar);
            string           jsonEntrada = JsonSerializer.Serialize(entradaAPI);

            HttpResponseMessage respostaAPI = await _client.PutAsync($"{_client.BaseAddress}/confirmar", new StringContent(jsonEntrada)).ConfigureAwait(false);


            return(respostaAPI.StatusCode == System.Net.HttpStatusCode.OK);
        }
        private async Task DispararMensagemConfirmar(ConfirmarAnuncio anuncio)
        {
            AnuncioDBModel anuncioCompleto = await _storage.GetById(anuncio.Id);

            using (AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient())
            {
                AnuncioConfirmado msgObj = new AnuncioConfirmado
                {
                    Id     = anuncio.Id,
                    Titulo = anuncioCompleto.Titulo
                };
                string msgJson = JsonSerializer.Serialize(msgObj);
                await snsClient.PublishAsync(_configs.GetValue <string>("MensageriaId"), msgJson);
            }
        }
        public async Task <IActionResult> Confirmar(ConfirmarAnuncio anuncio)
        {
            try
            {
                await _storage.Corfirmar(anuncio);
                await DispararMensagemConfirmar(anuncio);
            }
            catch (KeyNotFoundException knfex)
            {
                return(new NotFoundResult());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }

            return(new OkResult());
        }