private void GiveRedersToRefernces(List <String> refList, String readerId) { try { Console.WriteLine(readerId); foreach (String chkd_ref in refList) { string tableName = MyAWSConfigs.RefPersonsDBTableName; Table table = Table.LoadTable(client, tableName); Console.WriteLine("\n*** Executing UpdateMultipleAttributes() ***"); Console.WriteLine("\nUpdating multiple attributes...."); string partitionKey = chkd_ref; Document doc = new Document(); doc["id"] = partitionKey; // List of attribute updates. // The following replaces the existing authors list. Item item = table.GetItem(chkd_ref); Console.WriteLine(item["id"]); //Console.WriteLine(item["readerList"]); List <string> readersList = new List <string>(); if (item["readerList"] != null) { readersList = item["readerList"].AsListOfString(); var match = readersList.FirstOrDefault(stringToCheck => stringToCheck.Contains(readerId)); if (match != null) { readersList.Add(readerId); foreach (string i in readersList) { Console.WriteLine("reader !match >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated! not null"); } else { readersList.Add(readerId); foreach (string i in readersList) { Console.WriteLine("reader match >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated! not null"); } } else { foreach (string i in readersList) { Console.WriteLine("reader null >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); MessageBox.Show("Successfully Updated! null"); } } } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { //MessageBox.Show("Message : Unknown Error- Updating Refs", ex.Message); } finally { } }
private async void ButtonSubmit_Click(object sender, RoutedEventArgs e) { //MessageBox.Show("this is submit button"); String name = txtName.Text; //MessageBox.Show(name); try { bool isNameEmpty = string.IsNullOrEmpty(txtName.Text); bool isPhoneEmpty = string.IsNullOrEmpty(txtPhone.Text); bool isDescriptionEmpty = string.IsNullOrEmpty(txtDescription.Text); bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath); bool isFileIdEmpty = string.IsNullOrEmpty(txtId.Text); if (!isNameEmpty && !isDescriptionEmpty && !isPhoneEmpty) { string tableName = MyAWSConfigs.ReaderDBtableName; Table table = Table.LoadTable(client, tableName); ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", ""); controller.SetIndeterminate(); controller.SetCancelable(false); string partitionKey = txtId.Text; Console.WriteLine("oooooooooooooooooooooooooooooooo" + partitionKey); var item = new Document(); Document doc = new Document(); doc["id"] = partitionKey; doc["name"] = txtName.Text; doc["phone"] = txtPhone.Text; doc["description"] = txtDescription.Text; /////////////////////////////////////////////////// //#ToDo : Add readerList //item["readerList"] = readerList; UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; if (uploadFilePath != null) { string[] temp = uploadFilePath.Split('.'); string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; string filePath = BaseDirectoryPath + $"Resources\\Images\\{partitionKey}"; item = table.GetItem(partitionKey); string oldImage = item["aPropic"]; Console.WriteLine("><><><><><><><><><><>" + oldImage); //Delete old profile pic in local string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}"; DeleteOldPic(oldFilePath); //Delete old profile pic in s3Bucket controller.SetMessage("Deleting File"); await Task.Run(() => S3Bucket.DeleteFile(oldImage, MyAWSConfigs.RefImagesBucketName)); controller.SetMessage("Uploading file"); await Task.Run(() => Models.S3Bucket.UploadFile(uploadFilePath, partitionKey, Models.MyAWSConfigs.RefImagesBucketName)); } controller.SetMessage("Adding database record"); await Task.Run(() => table.UpdateItem(doc, config)); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated!"); await controller.CloseAsync(); await this.ShowMessageAsync("Success", "Person Updated !", MessageDialogStyle.Affirmative); } else { await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative); } } catch { await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative); } }