コード例 #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);
                    }
                }
            }
        }
コード例 #2
0
        public async Task <AnuncioDBModel> GetById(string id)
        {
            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext ctx = new DynamoDBContext(client))
                {
                    AnuncioDBModel registro = await ctx.LoadAsync <AnuncioDBModel>(id);

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

                    return(registro);
                }
            }
        }
コード例 #3
0
        public async Task <string> Adicionar(AdvertModel anuncio)
        {
            AnuncioDBModel dbModel = _mapper.Map <AnuncioDBModel>(anuncio);

            dbModel.Id       = new Guid().ToString();
            dbModel.CriadoEm = DateTime.UtcNow;
            dbModel.Status   = StatusAnuncio.Pendente;

            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext ctx = new DynamoDBContext(client))
                {
                    await ctx.SaveAsync(dbModel);
                }
            }

            return(dbModel.Id);
        }