Ejemplo n.º 1
0
        public void PopulateQueue()
        {
            if (!_isLocked)
            {
                _isLocked = true;

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

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

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

                            if (shift.Personnel != null && shift.Personnel.Any())
                            {
                                qi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(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 = await _shiftsService.GetShiftSignpsForShiftDayAsync(qi.Day.ShiftDayId);

                                if (qi.Signups != null && qi.Signups.Any())
                                {
                                    qi.Profiles.AddRange(await _userProfileService.GetSelectedUserProfilesAsync(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(await _userProfileService.GetSelectedUserProfilesAsync(users));
                                    }
                                }
                            }

                            qi.Shift = shift;

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

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

                t1.Start();
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <List <ShiftDayResult> > > GetTodaysShifts()
        {
            var result = new List <ShiftDayResult>();
            var days   = await _shiftsService.GetShiftDaysForDayAsync(DateTime.UtcNow, DepartmentId);

            foreach (var shiftDay in days)
            {
                shiftDay.Shift = await _shiftsService.GetShiftByIdAsync(shiftDay.ShiftId);

                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 = await _shiftsService.GetShiftDayNeedsAsync(shiftDay.ShiftDayId);

                var personnelRoles = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

                var signups = await _shiftsService.GetShiftSignpsForShiftDayAsync(shiftDay.ShiftDayId);

                dayResult.SignedUp = await _shiftsService.IsUserSignedUpForShiftDayAsync(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(Ok(result));
        }