Untitled
unknown
plain_text
a year ago
827 B
6
Indexable
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;
}
Editor is loading...
Leave a Comment