예제 #1
0
        public async Task <ActionResult <ShiftDayResult> > GetShiftDay(int id)
        {
            var result = new ShiftDayResult();

            var shiftDay = await _shiftsService.GetShiftDayByIdAsync(id);

            result.ShiftDayId = id;
            result.ShiftId    = shiftDay.ShiftId;
            result.ShiftName  = shiftDay.Shift.Name;
            result.ShitDay    = shiftDay.Day;
            result.Start      = shiftDay.Start;
            result.End        = shiftDay.End;
            result.ShiftType  = shiftDay.Shift.AssignmentType;

            var needs = await _shiftsService.GetShiftDayNeedsAsync(id);

            var personnelRoles = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

            var signups = await _shiftsService.GetShiftSignpsForShiftDayAsync(id);

            result.SignedUp = await _shiftsService.IsUserSignedUpForShiftDayAsync(shiftDay, UserId);

            result.Signups = new List <ShiftDaySignupResult>();
            foreach (var signup in signups)
            {
                if (!signup.Denied)
                {
                    var signupResult = new ShiftDaySignupResult();
                    signupResult.UserId = signup.UserId;
                    signupResult.Roles  = personnelRoles[signup.UserId].Select(x => x.PersonnelRoleId).ToList();

                    result.Signups.Add(signupResult);
                }
            }

            if (needs != null && needs.Any())
            {
                result.Needs = new List <ShiftDayGroupNeedsResult>();
                foreach (var need in needs.Keys)
                {
                    var dayNeed = new ShiftDayGroupNeedsResult();
                    dayNeed.GroupId = need;

                    dayNeed.GroupNeeds = new List <ShiftDayGroupRoleNeedsResult>();
                    foreach (var dNeed in needs[need])
                    {
                        var groupNeed = new ShiftDayGroupRoleNeedsResult();
                        groupNeed.RoleId = dNeed.Key;
                        groupNeed.Needed = dNeed.Value;

                        dayNeed.GroupNeeds.Add(groupNeed);
                    }

                    result.Needs.Add(dayNeed);
                }
            }

            return(Ok(result));
        }