public async Task <UpdateItemResponse> UpdateItems <T>(T tabelaInterna, string nomeTabela)
        {
            tableUpdate = Table.LoadTable(_dynamoDbClient, nomeTabela);
            DynamoDBContext db          = new DynamoDBContext(_dynamoDbClient);
            var             respostaGet = await _getItem.GetItems(tabelaInterna, nomeTabela);

            Document documentResponseGet   = Document.FromJson(respostaGet);
            Document documentRequestUpdate = db.ToDocument(tabelaInterna);

            //Variaveis internas
            List <String> keyUpdate = new List <string>();
            Dictionary <string, AttributeValueUpdate> valoresUpdate = new Dictionary <string, AttributeValueUpdate>();

            //Veriricar quais elementos deverão ser modificados para o update
            foreach (var i in documentResponseGet)
            {
                foreach (var j in documentRequestUpdate)
                {
                    if (i.Key == j.Key)
                    {
                        if (i.Value.ToString() != j.Value.ToString())
                        {
                            var valor = j.Value;
                            //valor
                            keyUpdate.Add(j.Key.ToString());
                        }
                    }
                }
            }

            chaveUpdate = tableUpdate.ToAttributeMap(documentRequestUpdate);

            foreach (var item in keyUpdate)
            {
                foreach (var chave in chaveUpdate)
                {
                    if (item == chave.Key)
                    {
                        AttributeValueUpdate valorUpdate = new AttributeValueUpdate(chave.Value, "PUT");
                        valoresUpdate.Add(chave.Key, valorUpdate);
                    }
                }
            }

            chaveUpdate = Utils.VerificarChaves(chaveUpdate, tableUpdate);

            var response = await _dynamoDbClient.UpdateItemAsync(nomeTabela, chaveUpdate, valoresUpdate, cancellationToken);

            db.Dispose();
            return(response);
        }
        private bool _disposedValue; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (_disposedValue)
            {
                return;
            }

            if (disposing)
            {
                _dynamoDBContext?.Dispose();
            }

            _disposedValue = true;
        }
        public async Task <bool> SaveUserChannelsAsync(UserChannels channels)
        {
            // context
            DynamoDBContext context = new DynamoDBContext(_dynamoDBClient);

            // save
            await context.SaveAsync(new UserChannels
            {
                UserId = channels.UserId,
                Queues = channels.Queues,
                Topics = channels.Topics
            });

            // dispose context
            context.Dispose();

            return(true);
        }
Exemple #4
0
        //public async Task AddNewEntry(int id, string replyDateTime, double price)
        //{
        //	var queryRequest = RequestBuilder(id, replyDateTime, price);

        //	await PutItemAsync(queryRequest);
        //}

        //private PutItemRequest RequestBuilder(int id, string replyDateTime, double price)
        //{
        //	var item = new Dictionary<string, AttributeValue>
        //	{
        //		{"Id", new AttributeValue {N = id.ToString()} },
        //		{"ReplyDateTime", new AttributeValue {S = replyDateTime.ToString()} },
        //		{"Price", new AttributeValue {N = price.ToString(CultureInfo.InvariantCulture)}}

        //	};

        //	return new PutItemRequest
        //	{
        //		TableName = "TempDynamoDB",
        //		Item = item
        //	};
        //}

        public async Task <PutItemResponse> PutItems <T> (T tabelaInterna, string nomeTabela)
        {
            //Identificar tabela
            table = Table.LoadTable(_dynamoClient, nomeTabela);
            //Criar contexto
            DynamoDBContext db = new DynamoDBContext(_dynamoClient);
            //Identificando campos do objeto genérico preenchidos
            Document documentRequest = db.ToDocument(tabelaInterna);

            //Mapeando os campos
            chave = table.ToAttributeMap(documentRequest);
            //Realizar o PUT
            PutItemResponse response = await _dynamoClient.PutItemAsync(nomeTabela, chave, cancellationToken);

            //
            db.Dispose();
            //Retornar resposta
            return(response);
        }
        public async Task <List <string> > GetTopicsFromUserIdAsync(string userId)
        {
            // context
            DynamoDBContext context = new DynamoDBContext(_dynamoDBClient);

            // conditions
            List <ScanCondition> conditions = new List <ScanCondition>
            {
                new ScanCondition("UserId", ScanOperator.Equal, userId)
            };

            // scan
            List <UserChannels> foundUserTopics = await context.ScanAsync <UserChannels>(conditions).GetRemainingAsync();

            // dispose context
            context.Dispose();

            return(foundUserTopics.First().Topics);
        }
        public async Task <string> GetUserIdFromUsernameAsync(string username)
        {
            // context
            DynamoDBContext context = new DynamoDBContext(_dynamoDBClient);

            // conditions
            List <ScanCondition> conditions = new List <ScanCondition>
            {
                new ScanCondition("Username", ScanOperator.Equal, username)
            };

            // scan
            List <ContainerUser> foundUsers = await context.ScanAsync <ContainerUser>(conditions).GetRemainingAsync();

            // dispose context
            context.Dispose();

            return(foundUsers.First().UserId);
        }
        public async Task <bool> DeleteChannelsFromUserIdAsync(string userId)
        {
            // context
            DynamoDBContext context = new DynamoDBContext(_dynamoDBClient);

            // creating an UserChannels object just for its UserId
            // DynamoDb will delete the record matching has this UserId
            UserChannels userChannels = new UserChannels
            {
                UserId = userId
            };

            // delete
            await context.DeleteAsync(userChannels);

            // dispose context
            context.Dispose();

            return(true);
        }
Exemple #8
0
 public void Dispose()
 {
     _context?.Dispose();
     _client?.Dispose();
 }
 protected override void Close()
 {
     base.Close();
     _dynamoDbContext?.Dispose();
     _amazonDynamoDbClient?.Dispose();
 }
Exemple #10
0
 public void Dispose()
 {
     dynamoDbContext.Dispose();
 }
 /// <inheritdoc />
 public void Dispose()
 {
     _Client?.Dispose();
     _Context?.Dispose();
 }