public void DeleteTimeEntry(int timeEntryId) { var timeEntry = new TimeEntry() { TimeEntryId = timeEntryId }; _context.Entry(timeEntry).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); }
public void TimeEntry_TotalTimeNonBillable() { var timeEntry = new TimeEntry() { TimeInUtc = new DateTime(2013, 10, 1, 0, 0, 0), TimeOutUtc = new DateTime(2013, 10, 1, 1, 0, 0) }; Assert.AreEqual(new TimeSpan(1, 0, 0), timeEntry.TotalTime); Assert.AreEqual(new TimeSpan(), timeEntry.TotalBillableTime); }
public void SaveTimeEntry(TimeEntry timeEntry) { // if there's a time entry that doesn't have a time out value // then update it to the new time entry's time in value var lastTimeEntry = (from te in _context.TimeEntries where te.TimeEntryId != timeEntry.TimeEntryId && te.TimeOutUtc == null && te.TimeInUtc < timeEntry.TimeInUtc orderby te.TimeInUtc descending select te).FirstOrDefault(); if (lastTimeEntry != null) lastTimeEntry.TimeOutUtc = timeEntry.TimeInUtc; if (timeEntry.TimeEntryId > 0) _context.Entry(timeEntry).State = System.Data.Entity.EntityState.Modified; else _context.TimeEntries.Add(timeEntry); _context.SaveChanges(); }
// TODO setup model level validations // TODO validate that if a date or time is provided that both are provided??? // TODO validate that the time out doesn't come before time in // TODO require the comment if the task requires a comment public void SetTimeEntry(TimeEntry timeEntry) { TimeEntryId = timeEntry.TimeEntryId; ProjectId = timeEntry.ProjectTask.ProjectId; ProjectTaskId = timeEntry.ProjectTaskId; Billable = timeEntry.Billable; var timeIn = _currentUser.User.ConvertUtcToLocalTime(timeEntry.TimeInUtc); TimeInDate = timeIn.Date; TimeInTime = new DateTime(timeIn.TimeOfDay.Ticks); var timeOutUtc = timeEntry.TimeOutUtc; if (timeOutUtc != null) { var timeOut = _currentUser.User.ConvertUtcToLocalTime(timeOutUtc.Value); TimeOutDate = timeOut.Date; TimeOutTime = new DateTime(timeOut.TimeOfDay.Ticks); } Comment = timeEntry.Comment; }