private async void TagChanged(object sender, EventArgs e) { BeansTransaction transaction = _view.SelectedTransaction; BeansTag tag = _view.SelectedTag; if (transaction != null && tag.Name != null) { // The tag we get back is missing the id. Go and find it. var tags = await Utils.BeansDatabase.GetTags(); tag.Id = tags.FirstOrDefault(thisTag => thisTag.Name == tag.Name).Id; // Update the relationship with the new tag var thisRelationship = _relationships.FirstOrDefault(relationship => relationship.TransactionName == transaction.Name); if (thisRelationship != null) { thisRelationship.Tags = new List <BeansTag> { tag }; } else { _relationships.Add(new BeansTransactionTagRelationship { TransactionName = transaction.Name, Tags = new List <BeansTag> { new BeansTag { Id = 0, Name = "Unknown" } } }); } } }
private void SelectedTransactionChanged(object sender, EventArgs e) { // Update the tags combobox to select the correct one BeansTransaction transaction = _view.SelectedTransaction; transaction = Utils.BeansDatabase.PopulateTags(transaction); _view.SelectedTag = transaction.Tags.FirstOrDefault(); }
public BeansTransaction PopulateTags(BeansTransaction transaction) { var thisRelationship = _relationships.Where(relationship => relationship.TransactionName == transaction.Name).FirstOrDefault(); if (thisRelationship != null) { transaction.Tags = thisRelationship.Tags; } else { transaction.Tags = new List <BeansTag> { new BeansTag { Id = 0, Name = "Unknown" } }; } return(transaction); }
private async Task GetTransactionsFromDB(DateTime?startDate = null, DateTime?endDate = null) { // Check connection if (_googleSheet.Service == null) { await _googleSheet.Connect(); } List <BeansTransaction> transactions = new List <BeansTransaction>(); string range = "Transactions!A:D"; SpreadsheetsResource.ValuesResource.GetRequest request = _googleSheet.Service.Spreadsheets.Values.Get(_googleSheet.SpreadsheetId, range); ValueRange response = request.ExecuteAsync().Result; IList <IList <Object> > values = response.Values; if (values != null && values.Count > 0) { foreach (var row in values) { BeansTransaction thisTransaction = new BeansTransaction(); if (row.Count > 0) { thisTransaction.Date = DateTime.Parse(row[0].ToString()); } if (row.Count > 1) { var name = row[1].ToString(); if (name.Contains("UBER ")) { name = "UBER"; } thisTransaction.Name = name; } if (row.Count > 2) { string amountCell = row[2].ToString(); if (!string.IsNullOrEmpty(amountCell)) { thisTransaction.Amount = Convert.ToDecimal(row[2].ToString()); } } if (row.Count > 3) { thisTransaction.Notes = row[3].ToString(); } // Ensure this transaction falls between the start/end dates (not great, I know) if (startDate != null && endDate != null) { if (thisTransaction.Date >= startDate && thisTransaction.Date <= endDate) { transactions.Add(thisTransaction); } } else { transactions.Add(thisTransaction); } } // Populate all of the Tags transactions = PopulateTags(transactions); } else { // No data found } _transactions = transactions; }