public void Buy(object sender, EventArgs e) { var found = items.FirstOrDefault(x => x.Name.Equals(Item.Text)); int i = items.IndexOf(found); if (i != -1) { if (isQuantityValid()) { DisplayAlert("Error", "Please, enter quantity above zero.", "OK"); return; } int quantity = Int32.Parse(Quantity.Text); //Check if the quantity available is in stock if (items[i].Quantity >= quantity) { //Update the observable collection Item nwitm = new Item(items[i].Name, items[i].Price, items[i].Quantity - quantity); items[i] = nwitm; //Log the purchase (works) HistoryItem hi = new HistoryItem(DateTime.Now, items[i].Name, quantity, Double.Parse(Total.Text)); App.Database.SaveItemAsync(hi);//suspicious //Reset the text fields Clear(sender, e); } else { //Item.Text = "Incorrect quantity, try again."; DisplayAlert("Error", "Requested Quantity not available.", "OK"); } } else { DisplayAlert("Error", "Please, select an item you want to buy.", "OK"); } }
async void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e) { HistoryItem selectedItem = e.SelectedItem as HistoryItem; await Navigation.PushAsync(new HistoryDetailPage(selectedItem.ID)); }
public Task <int> DeleteItemAsync(HistoryItem item) { return(Database.DeleteAsync(item)); }
async void OnListViewItemTapped(object sender, ItemTappedEventArgs e) { HistoryItem tappedItem = e.Item as HistoryItem; await Navigation.PushAsync(new HistoryDetailPage(tappedItem.ID)); }