public async Task <IActionResult> GetAsync() { try { // COGNITO SERVICE //AWSCredentials credentials = new CognitoAWSCredentials(cognitoID,RegionEndpoint.USEast1); //var client = new AmazonDynamoDBClient(credentials,RegionEndpoint.USEast1); // IAM SERVICE - Local //var credentials = new BasicAWSCredentials(AWSAccessKeyId, AWSSecretAccessKey); //var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1); // This approach works when you are depending on a role var client = new AmazonDynamoDBClient(RegionEndpoint.USEast1); ScanFilter scanFilter = new ScanFilter(); ScanOperationConfig soc = new ScanOperationConfig() { Filter = scanFilter }; DynamoDBContext context = new DynamoDBContext(client); AsyncSearch <lreb> search = context.FromScanAsync <lreb>(soc, null); List <lreb> documentList = new List <lreb>(); do { documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken)); } while (!search.IsDone); return(Ok(documentList)); } catch (Exception e) { return(StatusCode(500, e)); } }
public async Task <IActionResult> Get(string firstName, string lastName, string secondLastName, string curp) { var credentials = new BasicAWSCredentials(AWSAccessKeyId, AWSSecretAccessKey); var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USWest2); ScanFilter scanFilter = new ScanFilter(); scanFilter.AddCondition("FirstName", ScanOperator.Equal, firstName); scanFilter.AddCondition("LastName", ScanOperator.Equal, lastName); scanFilter.AddCondition("SecondLastName", ScanOperator.Equal, secondLastName); scanFilter.AddCondition("CURP", ScanOperator.Equal, curp); ScanOperationConfig soc = new ScanOperationConfig() { // AttributesToGet = new List { "Id", "Title", "ISBN", "Price" }, Filter = scanFilter }; DynamoDBContext context = new DynamoDBContext(client); AsyncSearch <EmployeesPTU> search = context.FromScanAsync <EmployeesPTU>(soc, null); List <EmployeesPTU> documentList = new List <EmployeesPTU>(); do { documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken)); } while (!search.IsDone); return(Ok(documentList)); }
//****** Adapted from p.52 of https://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/aws-xamarin-dg.pdf#setup public async Task <string> ScanAllAsync() { _result = ""; int count = 1; //string recordNumber; //string firstLine; //string savedTimeStampLine; var search = _context.FromScanAsync <Item>(new ScanOperationConfig() { ConsistentRead = true }); var searchResponse = await search.GetRemainingAsync(); searchResponse.ForEach((s) => { //recordNumber = count.ToString() + "."; //****** For indenting each line of the scan result. //Adapted from https://stackoverflow.com/questions/23846117/is-there-built-in-method-to-add-character-multiple-times-to-a-string. //firstLine = recordNumber + "Id = ".PadLeft(4 + "Id = ".Length, ' ') + s.Id + "\n"; //savedTimeStampLine = "SavedTimeStamp = ".PadLeft(4 + "SavedTimeStamp = ".Length, ' ') + s.SavedTimeStamp + "\n"; //****** _result += count + ". " + "\nId = " + s.Id + ",\nSavedTimeStamp = " + s.SavedTimeStamp + ",\nName = " + s.Name + ",\nEmail = " + s.Email + ",\nPassword = "******"\n\n"; //_result += firstLine + savedTimeStampLine; count++; }); return(_result); }
public static Task <List <T> > ScanItemAsync <T>() { var search = Context.FromScanAsync <T>(new ScanOperationConfig { ConsistentRead = true }); return(search.GetRemainingAsync()); }
public async Task <IEnumerable <T> > GetAll() { ScanFilter scanFilter = new ScanFilter(); scanFilter.AddCondition("Id", ScanOperator.NotEqual, 0); ScanOperationConfig soc = new ScanOperationConfig { Filter = scanFilter }; AsyncSearch <T> search = _context.FromScanAsync <T>(soc); return(await search.GetRemainingAsync()); }
public virtual IEnumerable <TEntity> GetAll() { List <TEntity> result; using (var client = new AmazonDynamoDBClient(_fcaSecrets.AwsCredentials, _fcaSecrets.AwsRegion)) using (var context = new DynamoDBContext(client)) { var scanConfig = new ScanOperationConfig(); result = context.FromScanAsync <TEntity>(scanConfig, _fcaSecrets.DefaultDbOperationConfig).GetRemainingAsync().Result; } return(result); }
public async void listCartItems(List <ShoppingCart> dataCartItems, GridLayout grdShoppingCart) { dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <ShoppingCart> listCartItems = dynContext.FromScanAsync <ShoppingCart>(new ScanOperationConfig() { ConsistentRead = true }); dataCartItems = await listCartItems.GetRemainingAsync(); var theCart = from aCartItem in dataCartItems where aCartItem.CustomerFname == strCustFName && aCartItem.CustomerLname == strCustLName && aCartItem.CheckedOut == false select aCartItem; grdShoppingCart.RemoveAllViews(); foreach (ShoppingCart cartItem in theCart) { CheckBox tvCartItem = new CheckBox(this); string strCartItemDesc = cartItem.ProductDescription; double dblCartItemUnitPrice = cartItem.UnitPrice; int iCartItemQuant = cartItem.Quantity; double dblCartItemTotalCost = cartItem.TotalCost; tvCartItem.Text = string.Format("{0} qty. {1} @ ${2} = {3}", strCartItemDesc, iCartItemQuant, dblCartItemUnitPrice, dblCartItemTotalCost); tvCartItem.SetTextSize(Android.Util.ComplexUnitType.Dip, 10f); tvCartItem.SetTextColor(Android.Graphics.Color.Black); tvCartItem.SetBackgroundColor(Android.Graphics.Color.White); tvCartItem.SetPadding(20, 5, 20, 5); tvCartItem.TextAlignment = TextAlignment.ViewStart; tvCartItem.SetWidth(1200); tvCartItem.SetBackgroundResource(Resource.Drawable.StoreName); grdShoppingCart.AddView(tvCartItem); } dblTotalPurchase = dataCartItems.Sum <ShoppingCart>(x => x.TotalCost); }
public static async Task <WeatherRecord[]> ReadWeatherTable() { var client = new AmazonDynamoDBClient(); DynamoDBContext dbcontext = new DynamoDBContext(client); var search = dbcontext.FromScanAsync <WeatherRecord>(new Amazon.DynamoDBv2.DocumentModel.ScanOperationConfig() { ConsistentRead = true }); var searchResponse = await search.GetRemainingAsync(); // Console.WriteLine($"Count: {searchResponse.ToArray().Length}"); // foreach (WeatherRecord r in searchResponse.ToArray()) // { // Console.WriteLine($"Date: {r.Date}\nSummary: {r.Summary}"); // } return(searchResponse.ToArray()); }
public async Task ScanByConditions() { Console.WriteLine("Grab all items where name starts with 'Mi': "); List <Profile> profiles = await _context.ScanAsync <Profile>(new[] { new ScanCondition(nameof(Profile.Name), ScanOperator.BeginsWith, "Mi") }).GetRemainingAsync(); IterateList(profiles); Console.WriteLine("\n\nGrab all items where email in ('*****@*****.**','*****@*****.**','*****@*****.**'): "); ScanFilter scanFilter = new ScanFilter(); scanFilter.AddCondition(nameof(Profile.Email), ScanOperator.In, "*****@*****.**", "*****@*****.**", "*****@*****.**"); profiles = await _context.FromScanAsync <Profile>(new ScanOperationConfig { Filter = scanFilter }).GetRemainingAsync(); IterateList(profiles); }
public static List <Goal> GetByEmail(string email) { List <Goal> goals; AsyncSearch <Goal> query = context.QueryAsync <Goal>(email, QueryOperator.GreaterThan, new string[] { " " }); Task <List <Goal> > taskQuery = query.GetNextSetAsync(default(CancellationToken)); taskQuery.Wait(); goals = taskQuery.Result; foreach (var goal in goals) { ScanOperationConfig config = new ScanOperationConfig(); config.ConsistentRead = true; config.Filter = new ScanFilter(); config.Filter.AddCondition("GoalName", ScanOperator.Equal, goal.GoalName); var search = context.FromScanAsync <Goal>(config); Task <List <Goal> > taskScan = search.GetRemainingAsync(); taskScan.Wait(); goal.Members = taskScan.Result.Count; } return(goals); }
public async Task <List <Coupon> > Get() { CreateTable(); ScanFilter scanFilter = new ScanFilter(); //scanFilter.AddCondition("StoreName", ScanOperator.Equal, storeName); ScanOperationConfig soc = new ScanOperationConfig() { Filter = scanFilter }; DynamoDBContext context = new DynamoDBContext(dynamoDBClient); AsyncSearch <Coupon> search = context.FromScanAsync <Coupon>(soc, null); List <Coupon> documentList = new List <Coupon>(); do { documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken)); } while (!search.IsDone); return(documentList); }
public async Task <IEnumerable <Book> > Get() { var result = new List <Book>(); ScanFilter filter = new ScanFilter(); filter.AddCondition("Title", ScanOperator.IsNotNull); ScanOperationConfig scanConfig = new ScanOperationConfig { Limit = 10, Filter = filter }; var queryResult = context.FromScanAsync <Book>(scanConfig); do { result.AddRange(await queryResult.GetNextSetAsync()); }while (!queryResult.IsDone && result.Count < 10); return(result); }
public async Task <List <Book> > GetBooksAsync() { ScanFilter scanFilter = new ScanFilter(); scanFilter.AddCondition("Id", ScanOperator.NotEqual, 0); ScanOperationConfig soc = new ScanOperationConfig() { // AttributesToGet = new List { "Id", "Title", "ISBN", "Price" }, Filter = scanFilter }; DynamoDBContext context = new DynamoDBContext(dynamoDBClient); AsyncSearch <Book> search = context.FromScanAsync <Book>(soc, null); List <Book> documentList = new List <Book>(); do { documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken)); } while (!search.IsDone); return(documentList); }
public async Task <List <T> > SearchByTags <T>(string[] tags) { using (var context = new DynamoDBContext(_client)) { var expression = new StringBuilder(""); var expressionAttributeValues = new Dictionary <string, DynamoDBEntry>(); var index = 1; foreach (var tag in tags) { var valueVariable = ":val" + index.ToString(); if (expression.Length > 1) { expression.Append(" OR "); } expression.Append($"contains(Tags, {valueVariable})"); expressionAttributeValues.Add(valueVariable, tag); index++; } var opConfig = new ScanOperationConfig() { FilterExpression = new Expression() { ExpressionStatement = expression.ToString(), ExpressionAttributeValues = expressionAttributeValues }, IndexName = "Network_Global_Index_01" }; var queryOperation = context.FromScanAsync <T>(opConfig); return(await queryOperation.GetRemainingAsync()); } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.ItemsLayout); strUserZip = this.Intent.GetStringExtra("UserZipCode"); strSelectedStore = this.Intent.GetStringExtra("SelectedStore"); if (this.Intent.GetStringExtra("CustomerFName") != "") { strCustFName = this.Intent.GetStringExtra("CustomerFName"); strCustLName = this.Intent.GetStringExtra("CustomerLName"); } GridLayout grdItems = FindViewById <GridLayout>(Resource.Id.grdItems); ImageButton imgAddItem = FindViewById <ImageButton>(Resource.Id.imgAddItem); TextView tvSelectedItemName = FindViewById <TextView>(Resource.Id.tvSelectedItemName); Button btnViewWebSearch = FindViewById <Button>(Resource.Id.btnViewWebSearch); Button btnToShoppingCart = FindViewById <Button>(Resource.Id.btnToShoppingCart); Button btnBack = FindViewById <Button>(Resource.Id.btnBack); dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <ItemCategories> listItems = dynContext.FromScanAsync <ItemCategories>(new ScanOperationConfig() { ConsistentRead = true }); List <ItemCategories> dataItems = await listItems.GetRemainingAsync(); var theItems = from anItem in dataItems where anItem.CategoryName != "none" select anItem; this.listTheItems(dataItems, tvSelectedItemName, grdItems); strSelectedItem = ""; tvSelectedItemName.Text = ""; btnViewWebSearch.Click += (sender, e) => { Uri uriSearch = new Uri(string.Format("http://www.google.com/search?q={0}+{1}+product+categories+{2}", strUserZip, strSelectedStore, strSelectedItem)); WebView webSearchItems = new WebView(this); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriSearch); request.Method = "GET"; request.AllowWriteStreamBuffering = false; request.ContentType = "application/json"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); string responseText = reader.ReadToEnd(); string returnString = response.StatusCode.ToString(); // editText1.Text = responseText; // Toast.MakeText(this, responseText, ToastLength.Long).Show(); webSearchItems.LoadUrl(uriSearch.ToString()); }; btnToShoppingCart.Click += (sender, e) => { if (strSelectedStore.Trim() == "") { var dlgBlankStore = new AlertDialog.Builder(this); dlgBlankStore.SetMessage("Please select an item category!"); dlgBlankStore.SetNeutralButton("OK", delegate { }); dlgBlankStore.Show(); } else { Intent intentCart = new Intent(this, typeof(ShoppingCartActivity)); intentCart.PutExtra("CustomerFName", strCustFName); intentCart.PutExtra("CustomerLName", strCustLName); intentCart.PutExtra("SelectedStore", strSelectedStore); intentCart.PutExtra("ProductType", strSelectedItem); intentCart.PutExtra("UserZipCode", strUserZip); StartActivity(intentCart); } }; btnBack.Click += (sender, e) => { Intent intentStores = new Intent(this, typeof(StoresActivity)); intentStores.PutExtra("UserZipCode", strUserZip); StartActivity(intentStores); }; imgAddItem.Click += (sender, e) => { var dlgAddNewItem = new AlertDialog.Builder(this); dlgAddNewItem.SetTitle("ADD A NEW ITEM"); dlgAddNewItem.SetMessage("Please Enter a Product Type"); EditText edtNewItemName = new EditText(this); //edtNewItemName.SetWidth(600); // grdNewStoreInfo.AddView(edtNewStoreName); dlgAddNewItem.SetView(edtNewItemName); dlgAddNewItem.SetPositiveButton("OK", delegate { string strNewItemName = edtNewItemName.Text; var reqScanItems = new ScanRequest { TableName = "ItemCategories" }; var respScanItems = dynDBClient.ScanAsync(reqScanItems); int iItemCount = respScanItems.Result.Count; Table tblTheItems = Table.LoadTable(dynDBClient, "ItemCategories"); Document docNewItem = new Document(); docNewItem["IcID"] = iItemCount.ToString(); docNewItem["CategoryName"] = strNewItemName; tblTheItems.PutItemAsync(docNewItem); this.listTheItems(dataItems, tvSelectedItemName, grdItems); }); dlgAddNewItem.SetNegativeButton("CANCEL", delegate { }); dlgAddNewItem.Show(); }; }
public void listTheItems(List <ItemCategories> dataItems, TextView tvSelectedItemName, GridLayout grdItems) { dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <ItemCategories> listItems = dynContext.FromScanAsync <ItemCategories>(new ScanOperationConfig() { ConsistentRead = true }); var theItems = from anItem in dataItems where anItem.CategoryName != "none" select anItem; grdItems.RemoveAllViews(); foreach (ItemCategories theItem in theItems) { TextView tvItem = new TextView(this) { Id = View.GenerateViewId() }; tvItem.Text = theItem.CategoryName; strSelectedItem = tvItem.Text; tvItem.SetTextColor(Android.Graphics.Color.Black); tvItem.SetBackgroundColor(Android.Graphics.Color.White); tvItem.SetPadding(20, 5, 20, 5); tvItem.TextAlignment = TextAlignment.ViewStart; tvItem.SetWidth(1200); tvItem.SetBackgroundResource(Resource.Drawable.StoreName); tvItem.Click += (sender, e) => { strSelectedItem = tvItem.Text; tvSelectedItemName.Text = strSelectedItem; Uri uriSearch = new Uri(string.Format("http://www.google.com/search?q={0}+{1}+product+categories+{2}", strUserZip, strSelectedStore, strSelectedItem)); WebView webSearchItems = new WebView(this); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriSearch); request.Method = "GET"; request.AllowWriteStreamBuffering = false; request.ContentType = "application/json"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); string responseText = reader.ReadToEnd(); string returnString = response.StatusCode.ToString(); // editText1.Text = responseText; // Toast.MakeText(this, responseText, ToastLength.Long).Show(); webSearchItems.LoadUrl(uriSearch.ToString()); }; grdItems.AddView(tvItem); } }
public async Task <List <T> > GetAll <T>() where T : IAwsDbItem { var iterator = _context.FromScanAsync <T>(new ScanOperationConfig()); return(await iterator.GetRemainingAsync()); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.StoresLayout); strUserZip = Intent.GetStringExtra("UserZipCode"); GridLayout grdStores = FindViewById <GridLayout>(Resource.Id.grdStores); ImageButton imgAddStore = FindViewById <ImageButton>(Resource.Id.imgAddStore); Button btnToItems = FindViewById <Button>(Resource.Id.btnToItems); Button btnViewWebSite = FindViewById <Button>(Resource.Id.btnViewWebSite); TextView tvSelectedStoreName = FindViewById <TextView>(Resource.Id.tvSelectedStoreName); dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <RetailStores> listStores = dynContext.FromScanAsync <RetailStores>(new ScanOperationConfig() { ConsistentRead = true }); List <RetailStores> dataStores = await listStores.GetRemainingAsync(); this.listTheStores(dataStores, tvSelectedStoreName, grdStores); strSelectedStore = ""; btnViewWebSite.Click += (sender, e) => { Uri uriSearch = new Uri(string.Format("http://www.google.com/search?q=list+stores+near+{0}+{1} ", strUserZip, strSelectedStore)); WebView webStores = new WebView(this); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriSearch); request.Method = "GET"; request.AllowWriteStreamBuffering = false; request.ContentType = "application/json"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); string responseText = reader.ReadToEnd(); string returnString = response.StatusCode.ToString(); // editText1.Text = responseText; // Toast.MakeText(this, responseText, ToastLength.Long).Show(); webStores.LoadUrl(uriSearch.ToString()); }; btnToItems.Click += (sender, e) => { Intent intentItems = new Intent(this, typeof(ItemsActivity)); intentItems.PutExtra("UserZipCode", strUserZip); intentItems.PutExtra("SelectedStore", strSelectedStore); var dlgToItemsScreen = new AlertDialog.Builder(this); if (strSelectedStore.Trim() == "") { dlgToItemsScreen.SetMessage("PLEASE SELECT A STORE!"); dlgToItemsScreen.SetNeutralButton("OK", delegate { }); } else { dlgToItemsScreen.SetTitle(string.Format("{0} in or near {1}", strSelectedStore, strUserZip)); dlgToItemsScreen.SetMessage(string.Format("This will take you to the Items screen based on your search\nfor {0} in/near your area, is this OK?", strSelectedStore, strUserZip)); dlgToItemsScreen.SetPositiveButton("OK", delegate { StartActivity(intentItems); }); dlgToItemsScreen.SetNegativeButton("CANCEL", delegate { }); } dlgToItemsScreen.Show(); }; imgAddStore.Click += (sender, e) => { var dlgAddNewStore = new AlertDialog.Builder(this); dlgAddNewStore.SetTitle("ADD A NEW STORE"); dlgAddNewStore.SetMessage("Please Enter a Name for a Store"); GridLayout grdNewStoreInfo = new GridLayout(this); grdNewStoreInfo.RowCount = 4; grdNewStoreInfo.ColumnCount = 1; EditText edtNewStoreName = new EditText(this); edtNewStoreName.SetWidth(600); grdNewStoreInfo.AddView(edtNewStoreName); //dlgAddNewStore.SetView(edtNewStoreName); TextView tvStoreURL = new TextView(this); tvStoreURL.SetTextColor(Android.Graphics.Color.White); tvStoreURL.Text = "Store URL (web address if known, otherwise we'll search):"; grdNewStoreInfo.AddView(tvStoreURL); // dlgAddNewStore.SetView(tvStoreURL); EditText edtStoreURL = new EditText(this); edtStoreURL.SetWidth(600); grdNewStoreInfo.AddView(edtStoreURL); // dlgAddNewStore.SetView(edtStoreURL); dlgAddNewStore.SetView(grdNewStoreInfo); dlgAddNewStore.SetPositiveButton("OK", delegate { string strNewStoreName = edtNewStoreName.Text; string strNewStoreURL = edtStoreURL.Text; var reqScanStores = new ScanRequest { TableName = "RetailStores" }; var respScanStores = dynDBClient.ScanAsync(reqScanStores); int iStoreCount = respScanStores.Result.Count; Table tblTheStores = Table.LoadTable(dynDBClient, "RetailStores"); Document docNewStore = new Document(); docNewStore["StoreID"] = iStoreCount.ToString(); docNewStore["StoreName"] = strNewStoreName; if (strNewStoreURL != "") { docNewStore["StoreURL"] = string.Concat("www.", strNewStoreName, ".com"); } tblTheStores.PutItemAsync(docNewStore); //this.listTheStores(dataStores,tvSelectedStoreName,grdStores); }); dlgAddNewStore.SetNegativeButton("CANCEL", delegate { }); dlgAddNewStore.Show(); }; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.Deliverylayout); EditText edtCustName = FindViewById <EditText>(Resource.Id.edtCustName); EditText edtCustAddress = FindViewById <EditText>(Resource.Id.edtCustAddress); EditText edtCustPhone = FindViewById <EditText>(Resource.Id.edtCustPhone); EditText edtCustZip = FindViewById <EditText>(Resource.Id.edtCustZip); EditText edtCustCity = FindViewById <EditText>(Resource.Id.edtCustCity); EditText edtCustState = FindViewById <EditText>(Resource.Id.edtCustState); Button btnDeliver = FindViewById <Button>(Resource.Id.btnDeliver); Button btnHome = FindViewById <Button>(Resource.Id.btnHome); DatePicker datePicker1 = FindViewById <DatePicker>(Resource.Id.datePicker1); TimePicker timePicker1 = FindViewById <TimePicker>(Resource.Id.timePicker1); string strCustName = edtCustName.Text; string strCustAddress = edtCustAddress.Text; string strCustPhone = edtCustPhone.Text; string strCustCity = edtCustCity.Text; string strCustState = edtCustName.Text; string strCustZip = edtCustZip.Text; string strDeliveryDate = datePicker1.DateTime.ToString("MM/dd/yyyy"); string strDeliveryTime = string.Format("{0}:{1}", timePicker1.CurrentHour, timePicker1.CurrentMinute); //Toast.MakeText(this, strDeliveryDate + " " + strDeliveryTime, ToastLength.Long).Show(); dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <DeliveryCreditCard> listCreditCardItems = dynContext.FromScanAsync <DeliveryCreditCard>(new ScanOperationConfig() { ConsistentRead = true }); List <DeliveryCreditCard> lstDataNewCharges = await listCreditCardItems.GetRemainingAsync(); AsyncSearch <Delivery> listPastDeliveries = dynContext.FromScanAsync <Delivery>(new ScanOperationConfig() { ConsistentRead = true }); List <Delivery> lstDataPastDeliveries = await listPastDeliveries.GetRemainingAsync(); int iPastDelivCount = lstDataPastDeliveries.Count; string strNotifyID = "0"; var currentCharges = from aCharge in lstDataNewCharges where aCharge.NewCharge == true select aCharge; btnHome.Click += (sender, e) => { var intentHomeScreen = new Intent(this, typeof(GoShoppingActivity)); StartActivity(intentHomeScreen); }; btnDeliver.Click += (sender, e) => { var dlgAddressOK = new AlertDialog.Builder(this); dlgAddressOK.SetMessage("Are you sure you want to deliver to this address?"); dlgAddressOK.SetPositiveButton("OK", delegate { strCustName = edtCustName.Text; strCustAddress = edtCustAddress.Text; strCustPhone = edtCustPhone.Text; strCustCity = edtCustCity.Text; strCustState = edtCustState.Text; strCustZip = edtCustZip.Text; strDeliveryDate = datePicker1.DateTime.ToString("MM/dd/yyyy"); strDeliveryTime = string.Format("{0}:{1}", timePicker1.CurrentHour, timePicker1.CurrentMinute); foreach (DeliveryCreditCard aCharge in currentCharges) { Table tblCreditCard = Table.LoadTable(dynDBClient, "CreditCard"); Table tblDelivery = Table.LoadTable(dynDBClient, "Delivery"); Document docDelivery = new Document(); Document docCreditCard = new Document(); docDelivery["DeliveryItemID"] = (++iPastDelivCount).ToString(); docDelivery["CustomerName"] = strCustName; docDelivery["CustomerAddress"] = strCustAddress; docDelivery["CustomerCity"] = strCustCity; docDelivery["CustomerState"] = strCustState; docDelivery["CustomerPhone"] = strCustPhone; docDelivery["NotifyID"] = strNotifyID; docDelivery["CustomerZip"] = strCustZip; docDelivery["CreditCardNum"] = aCharge.CardNumber; docDelivery["ProductDescription"] = aCharge.ItemDescription; docDelivery["DeliveryDate"] = strDeliveryDate; docDelivery["DeliveryTime"] = strDeliveryTime; docDelivery["Cost"] = aCharge.Amount; tblDelivery.PutItemAsync(docDelivery); docCreditCard["ChargeID"] = aCharge.ChargeID; docCreditCard["NewCharge"] = 0; tblCreditCard.UpdateItemAsync(docCreditCard); } Toast.MakeText(this, "Your order placed successfully, the delivery person will receive notification.", ToastLength.Long); }); dlgAddressOK.SetNegativeButton("NO", delegate { }); dlgAddressOK.Show(); }; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.DeliveryNotification); dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; EditText edtDeliveryMessage = FindViewById <EditText>(Resource.Id.edtDeliveryMessage); AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); GridLayout grdDeliveryNotification = FindViewById <GridLayout>(Resource.Id.grdDeliveryNotification); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); Button btnHome = FindViewById <Button>(Resource.Id.btnHome); AsyncSearch <DeliveryNotification> listDeliveries = dynContext.FromScanAsync <DeliveryNotification>(new ScanOperationConfig() { ConsistentRead = true }); List <DeliveryNotification> lstDataDeliveries = await listDeliveries.GetRemainingAsync(); AsyncSearch <CreditCardNotification> listCCNotification = dynContext.FromScanAsync <CreditCardNotification>(new ScanOperationConfig() { ConsistentRead = true }); List <CreditCardNotification> lstDataCCNotification = await listCCNotification.GetRemainingAsync(); var theDeliveries = from aDelivery in lstDataDeliveries where aDelivery.NotifyID == 0 select aDelivery; int newDeliveryCount = 0; foreach (DeliveryNotification deliv in lstDataDeliveries) { if (deliv.DeliveryItemID == 0) { break; } TextView tvSubject = new TextView(this); tvSubject.Text = string.Concat(deliv.CustomerName, " ", deliv.ProductDescription, " ", deliv.DeliveryDate); tvSubject.SetBackgroundResource(Resource.Drawable.StoreName); tvSubject.SetTextColor(Android.Graphics.Color.Black); if (deliv.NotifyID == 0) { ++newDeliveryCount; tvSubject.SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold); } tvSubject.Click += (sender, e) => { CreditCardNotification ccPurchaseQuery = lstDataCCNotification.Find(x => x.CardNumber == deliv.CreditCardNum && x.ItemDescription == deliv.ProductDescription && x.Amount == deliv.Cost); string strMerchant = ccPurchaseQuery.Merchant; string strCCNum = ccPurchaseQuery.CardNumber; StringBuilder sbMessage = new StringBuilder(); sbMessage.Append(deliv.CustomerName + " ordered " + deliv.ProductDescription + " from " + strMerchant); sbMessage.AppendLine(" for " + deliv.Cost.ToString() + " to be delivered at "); sbMessage.AppendLine(deliv.CustomerAddress + ", " + deliv.CustomerCity + ", " + deliv.CustomerState + ", " + deliv.CustomerZip); sbMessage.AppendLine(" on " + deliv.DeliveryDate + " time: " + deliv.DeliveryTime + ", CC#" + strCCNum); edtDeliveryMessage.Text = sbMessage.ToString(); // edtDeliveryMessage.Text = string.Format("{0} ordered {1} from {2} for {3} to be delivered at {4}, {5}, {6}, {7} on {8}, Time: {9) CC# {10}", deliv.CustomerName, deliv.ProductDescription,strMerchant,deliv.Cost, deliv.CustomerAddress, deliv.CustomerCity, deliv.CustomerState, deliv.CustomerZip,deliv.DeliveryDate, deliv.DeliveryTime,strCCNum); }; grdDeliveryNotification.AddView(tvSubject); } if (newDeliveryCount > 0) { var dlgNewDeliveryNote = new AlertDialog.Builder(this); dlgNewDeliveryNote.SetMessage("You have new orders to deliver."); dlgNewDeliveryNote.SetNeutralButton("OK", delegate { }); dlgNewDeliveryNote.Show(); } btnHome.Click += (sender, e) => { var intentHomeScreen = new Intent(this, typeof(GoShoppingActivity)); StartActivity(intentHomeScreen); }; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.ShoppingCartLayout); dbConfig.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamobdb/"; dbConfig.AuthenticationRegion = "dynamodb.us-east-1.amazonaws.com"; dbConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient dynDBClient = new AmazonDynamoDBClient("AKIAIMDIMZSEHYRAI6CQ", "6B2FRtd4JZiwq2iqiQJOmJPytboQ7EDOb08xovN3", dbConfig.RegionEndpoint); //dynDBClient.Config.ServiceURL= "https://console.aws.amazon.com/dynamodb/"; dynDBClient.Config.ServiceURL = "https://026821060357.signin.aws.amazon.com/console/dynamodb/"; dynDBClient.Config.RegionEndpoint = RegionEndpoint.USEast1; DynamoDBContext dynContext = new DynamoDBContext(dynDBClient); AsyncSearch <ShoppingCart> listDataCartItems = dynContext.FromScanAsync <ShoppingCart>(new ScanOperationConfig() { ConsistentRead = true }); List <ShoppingCart> dataCartItems = await listDataCartItems.GetRemainingAsync(); Button btnCheckout = FindViewById <Button>(Resource.Id.btnCheckout); Button btnBack = FindViewById <Button>(Resource.Id.btnBack); Button btnEnterOrder = FindViewById <Button>(Resource.Id.btnEnterOrder); GridLayout grdOrderEntry = FindViewById <GridLayout>(Resource.Id.grdOrderEntry); TextView tvCustName = FindViewById <TextView>(Resource.Id.tvCustName); EditText edtItemDescription = FindViewById <EditText>(Resource.Id.edtItemDescription); EditText edtPrice = FindViewById <EditText>(Resource.Id.edtPrice); EditText edtQuant = FindViewById <EditText>(Resource.Id.edtQuant); DateTime dtOrderDate = DateTime.Today; strOrderDate = dtOrderDate.ToString("MM/dd/yyyy"); strCustFName = this.Intent.GetStringExtra("CustomerFName"); strCustLName = this.Intent.GetStringExtra("CustomerLName"); strStoreName = this.Intent.GetStringExtra("SelectedStore"); strZipCode = this.Intent.GetStringExtra("UserZipCode"); strSelectItem = this.Intent.GetStringExtra("ProductType"); var dlgCustomerName = new AlertDialog.Builder(this); GridLayout grdShoppingCart = FindViewById <GridLayout>(Resource.Id.grdShoppingCart); GridLayout grdCustName = new GridLayout(this); grdCustName.RowCount = 2; grdCustName.ColumnCount = 2; TextView tvFName = new TextView(this); tvFName.Text = "First Name:"; grdCustName.AddView(tvFName); EditText edtFName = new EditText(this); grdCustName.AddView(edtFName); TextView tvLName = new TextView(this); tvLName.Text = "Last Name"; grdCustName.AddView(tvLName); EditText edtLName = new EditText(this); grdCustName.AddView(edtLName); dlgCustomerName.SetTitle("PLEASE ENTER YOUR NAME"); dlgCustomerName.SetView(grdCustName); dlgCustomerName.SetPositiveButton("OK", delegate { strCustFName = edtFName.Text; strCustLName = edtLName.Text; tvCustName.Text = string.Concat(strCustFName, " ", strCustLName); listCartItems(dataCartItems, grdShoppingCart); }); dlgCustomerName.SetNegativeButton("CANCEL", delegate { }); dlgCustomerName.Show(); var theCart = from aCartItem in dataCartItems where aCartItem.CustomerFname == strCustFName && aCartItem.CustomerLname == strCustLName && aCartItem.CheckedOut == false select aCartItem; TextView tvCustStore = FindViewById <TextView>(Resource.Id.tvCustStore); tvCustStore.Text = strStoreName; listCartItems(dataCartItems, grdShoppingCart); btnCheckout.Click += (sender, e) => { var dlgCheckout = new AlertDialog.Builder(this); dlgCheckout.SetMessage("Are you sure you want to check out your order?"); GridLayout grdPurchase = new GridLayout(this); grdPurchase.ColumnCount = 1; grdPurchase.RowCount = 10; RadioGroup rgCreditCards = new RadioGroup(this); RadioButton rbVisa = new RadioButton(this); rbVisa.Text = "VISA"; rgCreditCards.AddView(rbVisa); RadioButton rbMasterCard = new RadioButton(this); rbMasterCard.Text = "MASTER CARD"; rgCreditCards.AddView(rbMasterCard); RadioButton rbDiscover = new RadioButton(this); rbDiscover.Text = "DISCOVER"; rgCreditCards.AddView(rbDiscover); RadioButton rbAmEx = new RadioButton(this); rbAmEx.Text = "AMERICAN EXPRESS"; rgCreditCards.AddView(rbAmEx); grdPurchase.AddView(rgCreditCards); TextView tvCCPrompt = new TextView(this); tvCCPrompt.Text = "YOUR CREDIT CARD NUMBER:"; grdPurchase.AddView(tvCCPrompt); EditText edtCCNum = new EditText(this); grdPurchase.AddView(edtCCNum); TextView tvExpDate = new TextView(this); tvExpDate.Text = "EXPIRATION DATE (mmyy):"; EditText edtExpDate = new EditText(this); grdPurchase.AddView(tvExpDate); grdPurchase.AddView(edtExpDate); TextView tvVerifyCode = new TextView(this); tvVerifyCode.Text = "YOUR THREE-DIGIT VERIFICATION CODE:"; EditText edtVerifyCode = new EditText(this); grdPurchase.AddView(tvVerifyCode); grdPurchase.AddView(edtVerifyCode); dlgCheckout.SetView(grdPurchase); string strCCName = ""; bool boolCCSelected = false; //Toast.MakeText(this, grdPurchase.ChildCount.ToString(), ToastLength.Long).Show(); dlgCheckout.SetPositiveButton("OK", async delegate { // EditText edtTheNumber = (EditText)grdPurchase.GetChildAt(2); string strCCNum = edtCCNum.Text; string strExpDate = edtExpDate.Text; string strVerifyCode = edtVerifyCode.Text; string strExpDatePattern = @"^(0[1-9]|1[012])\d{2}$"; for (int iCCN = 0; iCCN < rgCreditCards.ChildCount; iCCN++) { RadioButton rbCC = (RadioButton)rgCreditCards.GetChildAt(iCCN); if (rbCC.Checked) { boolCCSelected = true; strCCName = rbCC.Text; break; } } if (!boolCCSelected) { Toast.MakeText(this, "PLEASE SELECT A CREDIT CARD", ToastLength.Long).Show(); } else if (strCCNum.Trim() == "") { Toast.MakeText(this, "PLEASE ENTER YOUR CREDIT INFORMATION", ToastLength.Long).Show(); } else if (Regex.IsMatch(strExpDate, strExpDatePattern) == false) { Toast.MakeText(this, "PLEASE ENTER YOUR EXPIRATION DATE IN FORM mmyy", ToastLength.Long).Show(); } else { AsyncSearch <CreditCard> listPurchases = dynContext.FromScanAsync <CreditCard>(new ScanOperationConfig() { ConsistentRead = true }); List <CreditCard> listDataPurchases = await listPurchases.GetRemainingAsync(); int iCountAllPurchases = listDataPurchases.Count; listDataCartItems = dynContext.FromScanAsync <ShoppingCart>(new ScanOperationConfig() { ConsistentRead = true }); dataCartItems = await listDataCartItems.GetRemainingAsync(); theCart = from aCartItem in dataCartItems where aCartItem.CustomerFname == strCustFName && aCartItem.CustomerLname == strCustLName && aCartItem.CheckedOut == false && aCartItem.OrderID != "0" select aCartItem; Table tblShoppingCart = Table.LoadTable(dynDBClient, "ShoppingCart"); Table tblCreditCard = Table.LoadTable(dynDBClient, "CreditCard"); foreach (ShoppingCart aCartItem in theCart) { Document docCartItem = new Document(); Document docPurchase = new Document(); docCartItem["OrderID"] = aCartItem.OrderID; docCartItem["CheckedOut"] = 1; docPurchase["ChargeID"] = (iCountAllPurchases++).ToString(); docPurchase["CardNumber"] = strCCNum; docPurchase["Amount"] = aCartItem.TotalCost; docPurchase["CardName"] = strCCName; docPurchase["CustomerName"] = string.Concat(strCustFName, " ", strCustLName); docPurchase["Expiration"] = strExpDate; docPurchase["ItemDescription"] = aCartItem.ProductDescription; docPurchase["Verification"] = strVerifyCode; docPurchase["Merchant"] = aCartItem.StoreName; docPurchase["PurchaseDate"] = strOrderDate; docPurchase["NewCharge"] = 1; await tblCreditCard.PutItemAsync(docPurchase); // await tblShoppingCart.UpdateItemAsync(docCartItem); await tblShoppingCart.DeleteItemAsync(docCartItem); } Intent intentDeliveryPickup = new Intent(this, typeof(DeliveryPickupActivity)); StartActivity(intentDeliveryPickup); } }); dlgCheckout.SetNegativeButton("NO", delegate { }); dlgCheckout.Show(); }; btnEnterOrder.Click += async(sender, e) => { AsyncSearch <ShoppingCart> listUpdateDataCartItems = dynContext.FromScanAsync <ShoppingCart>(new ScanOperationConfig() { ConsistentRead = true }); List <ShoppingCart> dataUpdateCartItems = await listUpdateDataCartItems.GetRemainingAsync(); int iOrderCount = dataUpdateCartItems.Count; string strDescription = edtItemDescription.Text.Trim(); string strPrice = edtPrice.Text.Trim(); string strQuant = edtQuant.Text.Trim(); if (strDescription == "") { Toast.MakeText(this, "PLEASE ENTER A PRODUCT DESCRIPTION", ToastLength.Long).Show(); return; } Double dblNum = 0.00; if (Double.TryParse(strPrice, out dblNum) == false) { Toast.MakeText(this, "PLEASE ENTER PRICE AS A REAL NUMBER", ToastLength.Long).Show(); return; } int iNum = 0; if (int.TryParse(strQuant, out iNum) == false) { Toast.MakeText(this, "PLEASE ENTER QUANTITY AS AN INTEGER NUMBER", ToastLength.Long).Show(); return; } else if (Convert.ToInt32(strQuant) <= 0) { Toast.MakeText(this, "PLEASE ENTER A POSITIVE NUMBER (>=1)", ToastLength.Long).Show(); return; } Table tblCart = Table.LoadTable(dynDBClient, "ShoppingCart"); Document docMerchandise = new Document(); double dblUnitPrice = Convert.ToDouble(strPrice); int iQuant = Convert.ToInt32(strQuant); double dblTotalCost = Convert.ToDouble(iQuant) * dblUnitPrice; docMerchandise["OrderID"] = iOrderCount.ToString(); docMerchandise["ProductDescription"] = strDescription; docMerchandise["CustomerFname"] = strCustFName; docMerchandise["CustomerLname"] = strCustLName; docMerchandise["StoreName"] = strStoreName; docMerchandise["UnitPrice"] = dblUnitPrice; docMerchandise["Quantity"] = iQuant; docMerchandise["TotalCost"] = dblTotalCost; docMerchandise["OrderDate"] = strOrderDate; docMerchandise["CheckedOut"] = 0; await tblCart.PutItemAsync(docMerchandise); listCartItems(dataCartItems, grdShoppingCart); // double dblRunningTotal += dblTotalCost; edtItemDescription.Text = ""; edtPrice.Text = ""; edtQuant.Text = ""; // dblTotalPurchase = dblRunningTotal; }; btnBack.Click += (sender, e) => { Intent intentItems = new Intent(this, typeof(ItemsActivity)); intentItems.PutExtra("CustomerFname", strCustFName); intentItems.PutExtra("CustomerLname", strCustLName); intentItems.PutExtra("SelectedStore", strStoreName); intentItems.PutExtra("UserZipCode", strZipCode); intentItems.PutExtra("OrderDate", strOrderDate); intentItems.PutExtra("ProductType", strSelectItem); StartActivity(intentItems); }; }