Esempio n. 1
0
        public ActionResult <AvailableHoursDto> FetchAvailableHours()
        {
            var user = _userRetriever.RetrieveUser();

            var availableHours = _storage.GetAvailableHours(user.Id, user.StartDate, DateTime.Now.Date);

            return(Ok(new
            {
                AvailableHoursBeforeCompensation = availableHours.AvailableHoursBeforeCompensation,
                AvailableHoursAfterCompensation = availableHours.AvailableHoursAfterCompensation,
                Entries = availableHours.Entries.Select(entry => new
                {
                    Date = entry.Date.ToDateOnly(),
                    TaskId = entry.TaskId,
                    Hours = entry.Hours,
                    CompensationRate = entry.CompensationRate
                })
            }));
        }
Esempio n. 2
0
        public ActionResult <AvailableHoursDto> FetchAvailableHours()
        {
            var user = _userRetriever.RetrieveUser();

            var availableHours = _storage.GetAvailableHours(user.Id);

            return(Ok(new
            {
                TotalHours = availableHours.TotalHours,
                TotalHoursIncludingCompensationRate = availableHours.TotalHoursIncludingCompensationRate,
                Entries = availableHours.Entries.Select(entry => new
                {
                    Date = entry.Date.ToDateOnly(),
                    TaskId = entry.TaskId,
                    Hours = entry.Hours,
                    CompensationRate = entry.CompensationRate
                })
            }));
        }
Esempio n. 3
0
        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);
        }