Untitled

 avatar
unknown
plain_text
2 months ago
1.2 kB
2
Indexable
protected override async void OnAppearing()
{
    base.OnAppearing();

    try
    {
        // Fetch today's entry for the specific subject and instructor
        var timeEntry = await _firebaseHelper.GetTodaysTimeEntryAsync(
            _currentInstructors.ID, 
            SubjectCodeLabel.Text
        );

        if (timeEntry != null)
        {
            // Entry exists for today
            TimeInLabel.Text = $"Time In: {timeEntry.TimeIn:g}";
            TimeOutLabel.Text = timeEntry.TimeOut.HasValue
                ? $"Time Out: {timeEntry.TimeOut.Value:g}"
                : "Time Out: Not yet logged";

            // Disable Time In button until tomorrow
            TimeInButton.IsEnabled = false;
        }
        else
        {
            // No entry exists for today
            TimeInLabel.Text = "Time In: No entry today";
            TimeOutLabel.Text = "Time Out: No entry today";

            // Enable Time In button
            TimeInButton.IsEnabled = true;
        }
    }
    catch (Exception ex)
    {
        await DisplayAlert("Error", $"An error occurred: {ex.Message}", "OK");
    }
}
Leave a Comment