Пример #1
0
        public async Task <IActionResult> GetMissing(TimeclockEntryQueryDto dto)
        {
            //ensure the entry belongs to the current user and that the current user is still in the specified patrol
            if (User.PatrolIds().Any(x => x == dto.PatrolId) &&
                (dto.UserId == User.UserId() ||
                 User.RoleInPatrol(dto.PatrolId).CanMaintainTimeClock()))   //or the user is an admin
            {
                var entries = await _timeEntryRepository.GetMissingShiftTime(dto.PatrolId, dto.UserId, dto.From, dto.To);

                return(Ok(entries));
            }
            else
            {
                return(Forbid());
            }
        }
Пример #2
0
        public async Task <IActionResult> GetDays(TimeclockEntryQueryDto dto)
        {
            //ensure the entry belongs to the current user and that the current user is still in the specified patrol
            if (User.PatrolIds().Any(x => x == dto.PatrolId) &&
                (dto.UserId == User.UserId() ||
                 User.RoleInPatrol(dto.PatrolId).CanMaintainTimeClock()))    //or the user is an admin
            {
                var entries = await _timeEntryRepository.GetTimeEntries(dto.PatrolId, dto.UserId, dto.From, dto.To);

                var groups = entries
                             .GroupBy(x => new { x.TimeEntry.ClockIn.Year, x.TimeEntry.ClockIn.Month, x.TimeEntry.ClockIn.Day, x.User.Id })
                             .Select(x =>
                                     new CurrentTimeEntryDto()
                {
                    TimeEntry = new TimeEntry()
                    {
                        ClockIn = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day, 0, 0, 0, DateTimeKind.Utc),
                        //actual worked
                        DurationSeconds = x.GroupBy(y => y.TimeEntry.Id).Select(y => y.First()).Sum(y => y.TimeEntry.DurationSeconds)
                    },
                    TimeEntryScheduledShiftAssignment = new TimeEntryScheduledShiftAssignment()
                    {
                        //worked in shift
                        DurationSeconds = x.Where(y => y.TimeEntryScheduledShiftAssignment != null).GroupBy(y => y.TimeEntryScheduledShiftAssignment.Id).Select(y => y.First()).Sum(y => y.TimeEntryScheduledShiftAssignment.DurationSeconds)
                    },
                    ScheduledShift = new ScheduledShift()
                    {
                        //scheduled duration in the day
                        DurationSeconds = x.Where(y => y.ScheduledShift != null).GroupBy(y => y.ScheduledShift.Id).Select(y => y.First()).Sum(y => y.ScheduledShift.DurationSeconds)
                    },
                    User = x.First().User
                });;

                return(Ok(groups));
            }
            else
            {
                return(Forbid());
            }
        }