Beispiel #1
0
        public List <ShiftDayResult> GetTodaysShifts()
        {
            var result = new List <ShiftDayResult>();
            var days   = _shiftsService.GetShiftDaysForDay(DateTime.UtcNow, DepartmentId);

            foreach (var shiftDay in days)
            {
                var dayResult = new ShiftDayResult();

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

                var needs          = _shiftsService.GetShiftDayNeeds(shiftDay.ShiftDayId);
                var personnelRoles = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId);
                var signups        = _shiftsService.GetShiftSignpsForShiftDay(shiftDay.ShiftDayId);

                dayResult.SignedUp = _shiftsService.IsUserSignedUpForShiftDay(shiftDay, UserId);

                dayResult.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();

                        dayResult.Signups.Add(signupResult);
                    }
                }

                if (needs != null && needs.Any())
                {
                    dayResult.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);
                        }

                        dayResult.Needs.Add(dayNeed);
                    }
                }

                result.Add(dayResult);
            }

            return(result);
        }
Beispiel #2
0
        public void PopulateQueue()
        {
            if (!_isLocked)
            {
                _isLocked = true;

                _shiftsService      = Bootstrapper.GetKernel().Resolve <IShiftsService>();
                _userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>();

                var t1 = new Task(() =>
                {
                    try
                    {
                        var shifts = _shiftsService.GetShiftsStartingNextDay(DateTime.UtcNow);

                        foreach (var shift in shifts)
                        {
                            var qi = new ShiftNotifierQueueItem();

                            if (shift.Personnel != null && shift.Personnel.Any())
                            {
                                qi.Profiles = _userProfileService.GetSelectedUserProfiles(shift.Personnel.Select(x => x.UserId).ToList());
                            }

                            qi.Day = shift.GetShiftDayforDateTime(DateTime.UtcNow.AddDays(1));
                            if (qi.Day != null)
                            {
                                if (qi.Profiles == null)
                                {
                                    qi.Profiles = new List <UserProfile>();
                                }

                                qi.Signups = _shiftsService.GetShiftSignpsForShiftDay(qi.Day.ShiftDayId);

                                if (qi.Signups != null && qi.Signups.Any())
                                {
                                    qi.Profiles.AddRange(_userProfileService.GetSelectedUserProfiles(qi.Signups.Select(x => x.UserId).ToList()));

                                    var users = new List <string>();
                                    foreach (var signup in qi.Signups)
                                    {
                                        if (signup.Trade != null)
                                        {
                                            if (!String.IsNullOrWhiteSpace(signup.Trade.UserId))
                                            {
                                                users.Add(signup.Trade.UserId);
                                            }
                                            else if (signup.Trade.TargetShiftSignup != null)
                                            {
                                                users.Add(signup.Trade.TargetShiftSignup.UserId);
                                            }
                                        }
                                    }

                                    if (users.Any())
                                    {
                                        qi.Profiles.AddRange(_userProfileService.GetSelectedUserProfiles(users));
                                    }
                                }
                            }

                            qi.Shift = shift;

                            _queue.Enqueue(qi);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException(ex);
                    }
                    finally
                    {
                        _isLocked = false;
                        _cleared  = false;

                        _shiftsService      = null;
                        _userProfileService = null;
                    }
                });

                t1.Start();
            }
        }