public IEnumerable <TimeEntriesResponseDto> UpsertTimeEntry(IEnumerable <CreateTimeEntryDto> timeEntries, int userId) { List <TimeEntriesResponseDto> response = new List <TimeEntriesResponseDto>(); foreach (var timeEntry in timeEntries) { var criterias = new TimeEntryQuerySearch { UserId = userId, FromDateInclusive = timeEntry.Date, ToDateInclusive = timeEntry.Date, TaskId = timeEntry.TaskId }; if (GetTimeEntry(criterias) == null) { response.Add(_storage.CreateTimeEntry(timeEntry, userId)); } else { response.Add(_storage.UpdateTimeEntry(timeEntry, userId)); } } return(response); }
public IEnumerable <TimeEntriesResponseDto> UpsertTimeEntry(IEnumerable <CreateTimeEntryDto> timeEntries, int userId, DateTime startDate) { List <TimeEntriesResponseDto> response = new List <TimeEntriesResponseDto>(); foreach (var timeEntry in timeEntries) { var criterias = new TimeEntryQuerySearch { UserId = userId, FromDateInclusive = timeEntry.Date, ToDateInclusive = timeEntry.Date, TaskId = timeEntry.TaskId }; if (timeEntry.TaskId == _flexTask) { var availableHours = _flexHourStorage.GetAvailableHours(userId, startDate, timeEntry.Date); if (timeEntry.Value > availableHours.AvailableHoursBeforeCompensation) { throw new Exception("Not enough available hours to flex"); } } if (GetTimeEntry(criterias) == null) { response.Add(_timeEntryStorage.CreateTimeEntry(timeEntry, userId)); } else { response.Add(_timeEntryStorage.UpdateTimeEntry(timeEntry, userId)); } } return(response); }