Untitled

 avatar
unknown
plain_text
2 months ago
1.5 kB
2
Indexable
private async void OnTimeInClicked(object sender, EventArgs e)
{
    if (!_isTimeInButtonEnabled)
    {
        return;
    }

    try
    {
        _isTimeInButtonEnabled = false;

        var instructor = (Instructors)BindingContext;
        if (instructor == null)
        {
            Debug.WriteLine("Instructor context is null.");
            return;
        }

        string subjectCode = // Retrieve the subject code for the action.
        
        var hasEntryForToday = await _firebaseHelper.HasTimeEntryForTodayAsync(instructor.ID, subjectCode);
        if (hasEntryForToday)
        {
            await DisplayAlert("Error", "You already have a time entry for this subject today.", "OK");
            return;
        }

        TimeEntry timeEntry = new TimeEntry
        {
            instructorId = instructor.ID,
            FirstName = instructor.FirstName,
            LastName = instructor.LastName,
            TimeIn = DateTime.Now,
            SubjectCode = subjectCode
        };

        string key = await _firebaseHelper.AddTimeInAsync(timeEntry);

        if (!string.IsNullOrEmpty(key))
        {
            // Additional UI updates
        }
        else
        {
            Debug.WriteLine("Failed to add time entry to Firebase.");
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine($"Exception occurred: {ex.Message}");
    }
    finally
    {
        _isTimeInButtonEnabled = true;
    }
}
Leave a Comment