private void _updateOutsideActivityButton_Click(object sender, EventArgs e) { string toastMessage; // set isTracking and Done outsideActivity.Done = true; outsideActivity.Notes = _editOutsideActivityNotesEditText.Text; // determine the new duration of the activity newDuration = new TimeSpan(_editOutsideActivityDurationTimePicker.Hour, _editOutsideActivityDurationTimePicker.Minute, 0); // Set new start and end times if (DateTime.TryParse(_editOutsideActivityStartDateEditText.Text, out DateTime newStartDate)) { string newStartDateTime = newStartDate.ToShortDateString() + " " + _editOutsideActivityStartTimeEditText.Text; outsideActivity.StartTime = Convert.ToDateTime(newStartDateTime, CultureInfo.CurrentCulture); outsideActivity.EndTime = outsideActivity.StartTime.Add(newDuration); } // set durationMilliseconds outsideActivity.DurationMilliseconds = (long)newDuration.TotalMilliseconds; // update or add the outdoor activity if (outsideActivity.OutsideActivityId == 0) { _dataService.CreateOutsideActivity(outsideActivity); toastMessage = String.Format(CultureInfo.CurrentCulture, "Inserted {0} activity", outsideActivity.Name); } else { _dataService.UpdateOutsideActivity(outsideActivity); toastMessage = String.Format(CultureInfo.CurrentCulture, "Updated {0} activity", outsideActivity.Name); } // close this intent Toast.MakeText(Application.Context, toastMessage, ToastLength.Short).Show(); Finish(); }
private void _updateCurrentActivity() { //Finalize OutsideActivityDatabase entry - set end time, durationMilliseconds, Name, done flag //_currentOutsideActivity.StartTime = new DateTime(2020, 3, 11, 20, 12, 13); //_currentOutsideActivity.EndTime = new DateTime(2020, 3, 11, 22, 12, 13); //_currentOutsideActivity.DurationMilliseconds = 7200000; _currentOutsideActivity.EndTime = DateTime.Now; _currentOutsideActivity.DurationMilliseconds = ConvertChronometerToDuration(_currentActivityChronometer.Text.ToString(CultureInfo.CurrentCulture)); // Convert the duration of the activity to a TimeSpan if (!TimeSpan.TryParse(_currentActivityChronometer.Text.ToString(CultureInfo.CurrentCulture), out TimeSpan durationMillisecondsTimeSpan)) { // handle the validation error } else { durationMillisecondsTimeSpan = TimeSpan.Parse(_currentActivityChronometer.Text.ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentCulture); } // write to the db _dataService.UpdateOutsideActivity(_currentOutsideActivity); }