Exemple #1
0
        public async Task <ActionResult <List <ShiftResult> > > GetShifts()
        {
            var results = new List <ShiftResult>();

            var shifts = await _shiftsService.GetAllShiftsByDepartmentAsync(DepartmentId);

            foreach (var s in shifts)
            {
                var shiftData = await _shiftsService.PopulateShiftData(s, true, true, true, false, false);

                var shift = new ShiftResult();
                shift.Id    = shiftData.ShiftId;
                shift.Name  = shiftData.Name;
                shift.Code  = shiftData.Code;
                shift.Color = shiftData.Color;
                shift.SType = shiftData.ScheduleType;
                shift.AType = shiftData.AssignmentType;

                if (shiftData.Personnel != null)
                {
                    shift.PCount = shiftData.Personnel.Count;
                }

                if (shiftData.Groups != null)
                {
                    shift.GCount = shiftData.Groups.Count;
                }

                var nextDay = shiftData.GetNextShiftDayforDateTime(DateTime.UtcNow);

                if (nextDay != null)
                {
                    shift.NextDay   = nextDay.Day.ToString("O");
                    shift.NextDayId = nextDay.ShiftDayId;
                }

                if (s.Personnel != null && shiftData.Personnel.Any(x => x.UserId == UserId))
                {
                    shift.InShift = true;
                }

                results.Add(shift);
            }

            return(Ok(results));
        }