private void HandleEvents(TextView _partyItemNameTextView, EditText _partyItemTakeAmountEditText, Button _partyItemTakeAmountButton, KeyValuePair <string, PartyItem> partyItem) { _partyItemTakeAmountButton.Click += async(s, e) => { try { var amount = Convert.ToInt32(_partyItemTakeAmountEditText.Text); if (!String.IsNullOrWhiteSpace(_partyItemNameTextView.Text) && amount > 0 && amount <= _party.Content.Items[partyItem.Key].Amount) { if (_partyRepository.UpdatePartyItem(this._party, partyItem, amount) == null) { throw new Exception(); } else { await _context.NotifyDataChanged(); } } else { throw new FormatException(); } } catch (Exception ex) { if (ex is FormatException) { ShowDialog("Invalid amount!"); } else { ShowDialog("Error occurred!"); } Debug.WriteLine("TakeAmount error: " + ex.Message); } }; }
public Task <Party> UpdatePartyItem(Party party, KeyValuePair <string, PartyItem> partyItem, int amountToSubstract) { return(_partyRepository.UpdatePartyItem(party, partyItem, amountToSubstract)); }