public void loadData() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(Amazon.RegionEndpoint.USEast2); Table table = Table.LoadTable(client, "Users"); string email = TxtUserEmail.Text; string password = TxtPassword.Password; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { MessageBox.Show("Fields can't be empty!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { Document doc = table.GetItem(email); string emailInput = doc.Values.ElementAt(1); string userPasword = doc.Values.ElementAt(0); string result = emailInput; string pass = userPasword; if (email == result & password == pass) { bookShelf = new BookShelf(); this.bookShelf.UserEmail = emailInput; HomePage homePage = new HomePage(this.bookShelf); homePage.Show(); this.Close(); } else { MessageBox.Show("Incorrect Email or Password entered!"); } } }
private Product GetItem(int id) { AmazonDynamoDBClient client = dynamoDBClient.Value; Amazon.DynamoDBv2.DocumentModel.Table table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(client, "Product"); Document record = table.GetItem(id.ToString()); Product p = new Product(); p.Id = id; p.Name = record["Name"]; p.Price = record["Price"].AsDecimal(); p.Category = record["Category"]; return(p); }
public bool userExists() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(Amazon.RegionEndpoint.USEast2); Table table = Table.LoadTable(client, "Users"); string email = TxtUserEmail.Text; Document doc = table.GetItem(email); if (doc == null) { userExist = false; } else { userExist = true; } return(userExist); }
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); } }