/// <summary> /// Callback for when the Add Activity button is clicked. /// </summary> /// <param name="sender">Object that triggered the event.</param> /// <param name="e">Arguments for the click event.</param> private async void AddActivityButton_Clicked(object sender, EventArgs e) { // Check if the maximum number of entries for the day is // already reached if (this.entries.Count >= MAX_ENTRIES_PER_DAY) { ToastController.ShortToast("Cannot add any more records for the day!"); return; } // Create a new record book entry and insert it into the // database to obtain a unique Id ActivityRecordEntry entry = new ActivityRecordEntry() { HorseId = HorseManager.GetInstance().ActiveHorse.Id, Date = date }; await AppDatabase.GetInstance().Save <ActivityRecordEntry>(entry); // Add a new record view to the stack this.entries.Add(entry); ActivityRecordView view = new ActivityRecordView(entry); this.ActivityRecordStack.Children.Add(view); }
/// <summary> /// Method for when the page appears. /// </summary> protected override async void OnAppearing() { // Invoke the base OnAppearing method base.OnAppearing(); // Set the horse/date display at the page bottom this.SelectedDateLabel.Text = RecordBookTabbedPage.SelectedDate.ToString("MMM. dd, yyyy"); this.SelectedHorseLabel.Text = HorseManager.GetInstance().ActiveHorse.Name; // Get all of the records for the page this.entries.Clear(); this.entries = await RecordBookEntry.GetInRange <ActivityRecordEntry>(HorseManager.GetInstance().ActiveHorse.Id, this.date, this.date.AddDays(1)); // Clear all of the contents from the activity record stack this.ActivityRecordStack.Children.Clear(); // Render all of the entries on the screen foreach (ActivityRecordEntry entry in this.entries) { // Add a new record frame for each activity Device.BeginInvokeOnMainThread(() => { ActivityRecordView view = new ActivityRecordView(entry); this.ActivityRecordStack.Children.Add(view); }); } }