Example #1
0
        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"
                            }
                        }
                    });
                }
            }
        }
Example #2
0
        private async Task GetTagsFromDB()
        {
            // Check connection
            if (_googleSheet.Service == null)
            {
                await _googleSheet.Connect();
            }

            List <BeansTag> tags = new List <BeansTag>();

            string range = "Tags!A:B";

            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)
                {
                    BeansTag thisTag = new BeansTag();

                    if (row.Count > 0)
                    {
                        thisTag.Id = Convert.ToInt32(row[0].ToString());
                    }

                    if (row.Count > 1)
                    {
                        thisTag.Name = row[1].ToString();
                    }

                    tags.Add(thisTag);
                }
            }
            else
            {
                // No data found
            }

            _tags = tags;
        }