Untitled
public async Task<string> TimeOutAsync(string instructorId) { var today = DateTime.Today; var timeEntry = (await _firebaseClient .Child("TimeEntries") .OrderBy("instructorId") .EqualTo(instructorId) .OnceAsync<TimeEntry>()) .FirstOrDefault(te => te.Object.TimeIn.Date == today && te.Object.TimeOut == null); if (timeEntry == null) { throw new InvalidOperationException("No active Time In record found for today."); } var timeOut = DateTime.Now; timeEntry.Object.TimeOut = timeOut; timeEntry.Object.HoursWorked = timeOut - timeEntry.Object.TimeIn; timeEntry.Object.SetFormattedHoursWorked(); await _firebaseClient.Child("TimeEntries").Child(timeEntry.Key).PutAsync(timeEntry.Object); return timeEntry.Key; }
Leave a Comment