Пример #1
0
        public async Task DeactivatePollAsync(string id)
        {
            var poll = await this._dbContext.LoadAsync <PollDefinition>(id);

            var activeRecord = new ActivePoll
            {
                Id            = id,
                ActivatedTime = DateTime.Now
            };

            await _dbContext.DeleteAsync <ActivePoll>(id);

            await UpdatePollStateAsync(id, PollDefinition.POLL_STATE_EXPIRED);
        }
Пример #2
0
        public async Task <IActionResult> Delete(string petId)
        {
            _logger.LogInformation("Iniciando Delete");

            Pets item = await _context.LoadAsync <Pets>(petId);

            if (item == null)
            {
                return(NotFound());
            }
            await _context.DeleteAsync <Pets>(petId);

            return(NoContent());
        }
        public async Task <IActionResult> Delete(string id, string projectName)
        {
            var context = new DynamoDBContext(_dynamoDbClient);

            // load project
            var projectModel = new ProjectModel {
                SolutionName = id, ProjectName = projectName
            };
            var project = await context.LoadAsync(projectModel);

            // delete project
            await context.DeleteAsync(project);

            return(RedirectToAction("Index"));
        }
        public IActionResult DeleteByIdBaseMaterials(int id)
        {
            DynamoDBContext aws_Context = new DynamoDBContext(client);

            try
            {
                aws_Context.DeleteAsync <BaseMaterials>(id);

                return(helpController.jsonResponseMessage(id, "Data is Deleted!", 0));
            }
            catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }
            return(null);
        }
        public async Task Delete(Guid id)
        {
            // Delete the book.
            await context.DeleteAsync <Book>(id);

            // Try to retrieve deleted book. It should return null.
            Book deletedBook = await context.LoadAsync <Book>(id, new DynamoDBContextConfig
            {
                ConsistentRead = true
            });

            if (deletedBook == null)
            {
                LambdaLogger.Log($"Book {id} is deleted");
            }
        }
 public virtual async Task RemoveAsync(string key)
 {
     try
     {
         using (var dBContext = new DynamoDBContext(dynamoDBClient, dynamoDBOptions.DynamoDBContextConfig))
         {
             logger.LogInformation("removing {key} persisted grant from DynamoDB database", key);
             await dBContext.DeleteAsync <Models.PersistedGrant>(key);
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex, "exception removing {key} persisted grant from database", key);
         throw;
     }
 }
Пример #7
0
        public async Task <bool> DeletePlayersAsync(Player player)
        {
            try
            {
                DynamoDBContext context = new DynamoDBContext(_dynamoDbClient);
                await context.DeleteAsync <Player>(player);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex);
                return(false);
            }
        }
Пример #8
0
        public async void DeleteContact()
        {
            var             client    = new AmazonDynamoDBClient();
            DynamoDBContext dbcontext = new DynamoDBContext(client);

            try
            {
                await dbcontext.DeleteAsync <Contact>(this.Email);

                Console.WriteLine($"Deleted {this.Email} successfully.");
            }
            catch (System.Exception)
            {
                Console.WriteLine($"Exception thrown while attempting to delete {this.Email}");
            }
        }
Пример #9
0
 private void DeleteObjectFromDB(DynamoDBContext context)
 {
     context.DeleteAsync <PlacedObject>(1, (res) =>
     {
         if (res.Exception == null)
         {
             context.LoadAsync <PlacedObject>(1, (result) =>
             {
                 PlacedObject deletedBook = result.Result;
                 if (deletedBook == null)
                 {
                     Debug.Log("Object Deleted");
                 }
             });
         }
     });
 }
Пример #10
0
        public async Task <HttpResponse> FunctionHandler(MessageKeys key, ILambdaContext context)
        {
            var message = new MessageDbDto
            {
                Id   = key.Id,
                Time = key.Time
            };
            await dbContext.DeleteAsync(message, new DynamoDBOperationConfig
            {
                OverrideTableName = Environment.GetEnvironmentVariable("MESSAGES_TABLE")
            });

            return(new HttpResponse
            {
                statusCode = HttpStatusCode.OK
            });
        }
Пример #11
0
        public async Task <bool> DeleteUser(string key)
        {
            //get user from key
            User deleteUser = await _context.LoadAsync <User>(key, new DynamoDBContextConfig
            {
                ConsistentRead = true
            });

            if (deleteUser != null)
            {
                await _context.DeleteAsync <User>(deleteUser);

                return(true);
            }

            return(false);
        }
Пример #12
0
        public async Task Confirm(ConfirmAdvertModel model)
        {
            using var client  = new AmazonDynamoDBClient();
            using var context = new DynamoDBContext(client);
            var record = await context.LoadAsync <AdvertDbModel>(model.Id) ??
                         throw new KeyNotFoundException($"A record with ID = {model.Id} was not found");

            if (model.Status == AdvertStatus.Active)
            {
                record.Status = AdvertStatus.Active;
                await context.SaveAsync(record);
            }
            else
            {
                await context.DeleteAsync(record);
            }
        }
Пример #13
0
            private static async Task TestCRUDOperations(DynamoDBContext context)
            {
                int  bookID = 1001; // Some unique value.
                Book myBook = new Book
                {
                    Id          = bookID,
                    Title       = "object persistence-AWS SDK for.NET SDK-Book 1001",
                    ISBN        = "111-1111111001",
                    BookAuthors = new List <string> {
                        "Author 1", "Author 2"
                    },
                };

                // Save the book.
                await context.SaveAsync(myBook);

                // Retrieve the book.
                Book bookRetrieved = await context.LoadAsync <Book>(bookID);

                // Update few properties.
                bookRetrieved.ISBN        = "222-2222221001";
                bookRetrieved.BookAuthors = new List <string> {
                    " Author 1", "Author x"
                };                                                                        // Replace existing authors list with this.
                await context.SaveAsync(bookRetrieved);

                // Retrieve the updated book. This time add the optional ConsistentRead parameter using DynamoDBContextConfig object.
                Book updatedBook = await context.LoadAsync <Book>(bookID, new DynamoDBContextConfig
                {
                    ConsistentRead = true
                });

                // Delete the book.
                await context.DeleteAsync <Book>(bookID);

                // Try to retrieve deleted book. It should return null.
                Book deletedBook = await context.LoadAsync <Book>(bookID, new DynamoDBContextConfig
                {
                    ConsistentRead = true
                });

                if (deletedBook == null)
                {
                    Console.WriteLine("Book is deleted");
                }
            }
Пример #14
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var dynamoContext = new DynamoDBContext(dynamoDb);
            var movie         = await _context.Movie.FindAsync(id);

            var userM = await _context.UserMovie
                        .FirstOrDefaultAsync(m => m.MovieId == id);

            // Delete comments for that movie
            await dynamoContext.DeleteAsync <Comments>(movie.Id);

            _context.Movie.Remove(movie);
            _context.UserMovie.Remove(userM);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #15
0
        public async Task ConfirmAsync(ConfirmAdvertModel model)
        {
            DynamoDBContext context = new DynamoDBContext(_client);
            var             record  = await context.LoadAsync <AdvertDbModel>(model.Id);

            if (record == null)
            {
                throw new KeyNotFoundException($"A record with ID={model.Id} was not found.");
            }
            if (model.Status == AdvertStatus.Active)
            {
                record.Status = AdvertStatus.Active;
                await context.SaveAsync(record);
            }
            else
            {
                await context.DeleteAsync(record);
            }
        }
Пример #16
0
        public async Task DeleteAsync(User userProperties)
        {
            try
            {
                var config = new DynamoDBContextConfig
                {
                    TableNamePrefix  = TablePrefix,
                    SkipVersionCheck = true,
                };
                var context = new DynamoDBContext(Client, config);

                await context.DeleteAsync(userProperties);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception deleting user properties." + ex.Message);
                throw;
            }
        }
Пример #17
0
        public async Task DeactivatePoll(string id)
        {
            await _dbContext.DeleteAsync <ActivePoll>(id);

            await UpdatePollStateAsync(id, PollDefinition.POLL_STATE_EXPIRED);

            var poll = await this._dbContext.LoadAsync <PollDefinition>(id);

            var message = new StringBuilder();

            message.AppendFormat("Poll {0} has expired, final results are:\n", poll.Title);
            foreach (var option in poll.Options.Values.OrderByDescending(x => x.Votes))
            {
                message.AppendFormat("\t{0}: {1} Votes\n", option.Text, option.Votes);
            }
            await this._snsClient.PublishAsync(poll.TopicArn,
                                               message.ToString(),
                                               string.Format("Poll {0} has expired", poll.Title));
        }
Пример #18
0
        /// <summary>
        /// Removes all async.
        ///
        /// subjectId && clientId && type
        ///
        /// see https://github.com/IdentityServer/IdentityServer4/blob/325ea0e67b1de2c836f26eb38436ff07177028d4/src/IdentityServer4/Stores/InMemory/InMemoryPersistedGrantStore.cs#L110
        ///
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="subjectId">Subject identifier.</param>
        /// <param name="clientId">Client identifier.</param>
        /// <param name="type">Type.</param>
        public async Task RemoveAllAsync(string subjectId, string clientId, string type)
        {
            if (string.IsNullOrEmpty(subjectId) || string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(type))
            {
                await Task.FromException(new ArgumentNullException($"PersistedGrantRepository.RemoveAllAsync subjectId:{subjectId} And/Or clientId:{clientId} And/Or type:{type} is null"));

                return;
            }

            List <ScanCondition> conditions = new List <ScanCondition>();

            conditions.Add(new ScanCondition(nameof(subjectId), ScanOperator.Equal, subjectId));
            conditions.Add(new ScanCondition(nameof(clientId), ScanOperator.Equal, clientId));
            conditions.Add(new ScanCondition(nameof(type), ScanOperator.Equal, type));

            try
            {
                using (var context = new DynamoDBContext(client, ddbConfig))
                {
                    var batch = context.ScanAsync <PersistedGrantDynamoDB>(conditions);
                    while (!batch.IsDone)
                    {
                        var dataset = await batch.GetNextSetAsync();

                        if (dataset.Any())
                        {
                            dataset.ForEach(async item => await context.DeleteAsync(item));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(default(EventId), ex, "PersistedGrantRepository.RemoveAllAsync failed with subjectId: {subjectId}, clientId: {clientId}", subjectId, clientId);
                await Task.FromException(ex);

                return;
            }

            await Task.CompletedTask;

            return;
        }
Пример #19
0
        public async Task <bool> DeletePackageAsync(AnnotationPackage package)
        {
            try
            {
                var successful = true;

                // Delete images on S3
                foreach (var image in package.Images)
                {
                    if (!await this.DeleteImageAsync(image).ConfigureAwait(false))
                    {
                        successful = false;
                    }
                }

                // Delete package from DynamoDB
                using (var context = new DynamoDBContext(this._dynamoDbClient))
                {
                    var dbConfig = new DynamoDBOperationConfig
                    {
                        OverrideTableName = this._dbTableName
                    };
                    await context.DeleteAsync(new AnnotationPackageDto
                    {
                        Id = package.ExternalId
                    }, dbConfig).ConfigureAwait(false);
                }

                // Delete local folder
                var path = Path.Combine(this._extractionFolder, package.PackageName);
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }

                return(successful);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public static async Task ExecuteAsync()
        {
            var credentials = new BasicAWSCredentials("AKIAZEFCLWDDRHQZKD7U", "0D4KlTb4COgrY8hupdQPnbBANTRwQP448I8nTxGw");



            AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, RegionEndpoint.SAEast1);

            using (DynamoDBContext context = new DynamoDBContext(client))
            {
                User user = new User()
                {
                    Active    = true,
                    Address   = "Rua Vicente Savi , n12",
                    Email     = "*****@*****.**",
                    FirstName = "wesley",
                    LastName  = "azevedo bezerra",
                    Interests = new List <string>
                    {
                        "Futebol",
                        "Video Game",
                        "Gastronomia",
                        "Viajens"
                    },
                    NumberOfChildren = 0
                };

                await context.SaveAsync(user);

                Console.WriteLine("User Saved");

                User loadUser = await context.LoadAsync <User>(user.Email);


                Console.WriteLine("Reading User");
                PrintUser(loadUser);

                await context.DeleteAsync <User>(user.Email);

                Console.WriteLine("User Delete");
            }
        }
        public async Task Confirm(ConfirmAdvertModel model)
        {
            using (var context = new DynamoDBContext(_amazonDynamoDB))
            {
                var record = await context.LoadAsync <AdvertDTO>(model.ID);

                if (record == null)
                {
                    throw new Exception("record not found");
                }
                if (record.Status == AdvertStatus.Success)
                {
                    await context.SaveAsync(record);
                }
                else
                {
                    await context.DeleteAsync(model.ID);
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Deletes a recipe from the database. Returns false if something went wrong, or
        /// true if it was deleted successfully.
        /// </summary>
        public async Task <bool> DeleteRecipe(Recipe recipe)
        {
            if (recipe == null)
            {
                return(false);
            }

            var context = new DynamoDBContext(_client);

            try
            {
                await context.DeleteAsync(recipe);

                return(true);
            }
            catch (AmazonDynamoDBException)
            {
                return(false);
            }
        }
Пример #23
0
        //we can't update sort key
        //https://stackoverflow.com/questions/55474664/dynamoddb-how-to-update-sort-key/55474827
        public async Task UpdateName(string countryId, string oldName, string newName)
        {
            Profile profile = await _context.LoadAsync <Profile>(countryId, oldName);

            if (profile != null)
            {
                await _context.DeleteAsync <Profile>(countryId, oldName);

                profile.Name = newName;
                await _context.SaveAsync <Profile>(profile);

                Console.WriteLine("Item updated");
                Console.WriteLine();
                await ScanAll();
            }
            else
            {
                Console.WriteLine("Item not found!");
            }
        }
Пример #24
0
        public async Task <bool> DeleteUser(object key, ILambdaContext context)
        {
            context.Logger.Log("DELETE USER: " + key);
            InitializeDB();

            //get user from key
            User deleteUser = await _context.LoadAsync <User>(key, new DynamoDBContextConfig
            {
                ConsistentRead = true
            });

            if (deleteUser != null)
            {
                await _context.DeleteAsync <User>(deleteUser);

                return(true);
            }

            return(false);
        }
Пример #25
0
        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);
        }
Пример #26
0
        public async Task Confirm(ConfirmAdvertisement confirm)
        {
            using var context = new DynamoDBContext(_client);
            var dbModel = await context.LoadAsync <AdvertisementDb>(confirm.Id);

            if (dbModel is null)
            {
                throw new KeyNotFoundException($"A record with ID={confirm.Id} has not been found");
            }
            if (confirm.Status == AdvertisementStatus.Active)
            {
                dbModel.FilePath = confirm.FilePath;
                dbModel.Status   = AdvertisementStatus.Active;
                await context.SaveAsync(dbModel);
            }
            else
            {
                await context.DeleteAsync(dbModel);
            }
        }
Пример #27
0
 private void DeleteBook()
 {
     this.displayMessage += "\n*** Delete book**\n";
     if (retrievedBook == null)
     {
         this.displayMessage += "\nCan't perform DeleteBook() before RetrieveBook()";
         return;
     }
     // Update the book.
     context.DeleteAsync <Book>(retrievedBook, (AmazonDynamoResult <VoidResponse> result) =>
     {
         if (result.Exception != null)
         {
             this.displayMessage += ("Delete error" + result.Exception.Message);
             Debug.LogException(result.Exception);
             return;
         }
         this.displayMessage += ("Delete Book{" + retrievedBook.Id + "} from DynamoDB Complete ! \n");
     }, null);
 }
        public virtual async Task RemoveAllAsync(PersistedGrantFilter filter)
        {
            try
            {
                var conditions = new List <ScanCondition>();
                if (!string.IsNullOrEmpty(filter.SubjectId))
                {
                    conditions.Add(new ScanCondition(nameof(filter.SubjectId), ScanOperator.Equal, filter.SubjectId));
                }
                if (!string.IsNullOrEmpty(filter.ClientId))
                {
                    conditions.Add(new ScanCondition(nameof(filter.ClientId), ScanOperator.Equal, filter.ClientId));
                }
                if (!string.IsNullOrEmpty(filter.SessionId))
                {
                    conditions.Add(new ScanCondition(nameof(filter.SessionId), ScanOperator.Equal, filter.SessionId));
                }
                if (!string.IsNullOrEmpty(filter.Type))
                {
                    conditions.Add(new ScanCondition(nameof(filter.Type), ScanOperator.Equal, filter.Type));
                }

                var data = new List <PersistedGrant>();
                using (var dBContext = new DynamoDBContext(dynamoDBClient, dynamoDBOptions.DynamoDBContextConfig))
                {
                    var result = await dBContext.ScanAsync <Models.PersistedGrant>(conditions).GetRemainingAsync();

                    logger.LogInformation("removing {grantKeysCount} persisted grants from DynamoDB database for subject {subjectId}, clientId {clientId}, grantType {type} and session {session}", result.Count(), filter.SubjectId, filter.ClientId, filter.Type, filter.SessionId);

                    foreach (var grant in result)
                    {
                        await dBContext.DeleteAsync <Models.PersistedGrant>(grant);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "exception removing persisted grants from database for subject {subjectId}, clientId {clientId}, grantType {type} and session {session}", filter.SubjectId, filter.ClientId, filter.Type, filter.SessionId);
                throw;
            }
        }
 public async Task ConfirmAsync(ConfirmAdvertModel confirmAdvert)
 {
     using (var client = new AmazonDynamoDBClient())
     {
         using (var context = new DynamoDBContext(client))
         {
             var record = await context.LoadAsync<AdvertForCreationDto>(confirmAdvert.Id);
             if (record == null) throw new KeyNotFoundException($"A record with ID={confirmAdvert.Id} was not found.");
             if (confirmAdvert.Status == AdvertStatus.Active)
             {
                 record.FilePath = confirmAdvert.FilePath;
                 record.Status = AdvertStatus.Active;
                 await context.SaveAsync(record);
             }
             else
             {
                 await context.DeleteAsync(record);
             }
         }
     }
 }
Пример #30
0
        public async Task Confirm(ConfirmAdvertModel model)
        {
            using (var client = new AmazonDynamoDBClient()){
                using (var context = new DynamoDBContext(client)){
                    var record = await context.LoadAsync <AdvertDBModel>(model.Id);

                    if (record == null)
                    {
                        throw new KeyNotFoundException("Record With" + model.Id + "Not found");
                    }
                    if (model.Status == AdvertStatus.Active)
                    {
                        record.Status = AdvertStatus.Active;
                        await context.SaveAsync(record);
                    }
                    else
                    {
                        await context.DeleteAsync(record);
                    }
                }
            }
        }
Пример #31
0
 public async Task DeleteAsync(Guid instanceId, CancellationToken cancellationToken = default(CancellationToken))
 {
     var context = new DynamoDBContext(Settings.AmazonDynamoDBClient);
     await
         context.DeleteAsync<TenTwentyAgency>(instanceId.ToString(), Settings.AgenciesRangeKeyValue,
             cancellationToken);
 }