private async Task <bool> ManagerDeclineAsync(OpenShiftsChangeRequest openShiftRequest, string teamId)
        {
            // when a manager declines an open shift request, there is nothing we need do other than
            // delete the request from the request cache
            await _requestCacheService.DeleteRequestAsync(teamId, openShiftRequest.Id).ConfigureAwait(false);

            return(true);
        }
 private async Task AutoApproveRequestAsync(OpenShiftsChangeRequest openShiftRequest, string teamId, IDurableOrchestrationClient starter)
 {
     var deferredActionModel = new DeferredActionModel
     {
         ActionType   = DeferredActionModel.DeferredActionType.ApproveOpenShiftRequest,
         DelaySeconds = _teamOptions.DelayedActionSeconds,
         RequestId    = openShiftRequest.Id,
         TeamId       = teamId
     };
     await starter.StartNewAsync(nameof(DeferredActionOrchestrator), deferredActionModel).ConfigureAwait(false);
 }
        protected override async Task <bool> MapOpenShiftRequestIdentitiesAsync(OpenShiftsChangeRequest openShiftRequest)
        {
            var employee = await _cacheService.GetKeyAsync <EmployeeModel>(ApplicationConstants.TableNameEmployees, openShiftRequest.ManagerUserId).ConfigureAwait(false);

            if (employee != null)
            {
                openShiftRequest.WfmManagerId        = employee.WfmEmployeeId;
                openShiftRequest.WfmManagerLoginName = GetTargetLoginName(employee.WfmLoginName);
            }

            return(true);
        }
Beispiel #4
0
 protected override Task <bool> MapOpenShiftRequestIdentitiesAsync(OpenShiftsChangeRequest openShiftRequest)
 {
     // this method is never called so nothing to do
     return(Task.FromResult(true));
 }
Beispiel #5
0
 protected abstract Task <bool> MapOpenShiftRequestIdentitiesAsync(OpenShiftsChangeRequest openShiftRequest);
        private async Task <bool> ManagerApproveAsync(ShiftModel openShift, string newWfmShiftId, OpenShiftsChangeRequest openShiftRequest, ChangeRequest changeRequest, string teamId, string timeZoneInfoId, ILogger log)
        {
            try
            {
                var weekStartDate = openShift.StartDate.ApplyTimeZoneOffset(timeZoneInfoId).StartOfWeek(_teamOptions.StartDayOfWeek);
                var policy        = GetConflictRetryPolicy(_teamOptions.RetryMaxAttempts, _teamOptions.RetryIntervalSeconds);

                // as the manager has approved the request and it has been assigned successfully,
                // decrement the quantity
                openShift.Quantity--;

                // update the cache for the assignment
                await policy.ExecuteAsync(() => UpdateCachedOpenShiftsAsync(teamId, openShift, weekStartDate)).ConfigureAwait(false);

                // get the new shift created from the open shift in Teams
                var newShift = changeRequest.Requests
                               .Where(r => r.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
                               .Select(r => r.Body.ToObject <ShiftResponse>())
                               .First();

                // convert the open shift to a shift
                openShift.Quantity        = 1;
                openShift.WfmEmployeeId   = openShiftRequest.WfmSenderId;
                openShift.TeamsEmployeeId = openShiftRequest.SenderUserId;
                openShift.TeamsShiftId    = newShift.Id;
                openShift.WfmShiftId      = newWfmShiftId;

                // and add it to the week shifts cache
                await policy.ExecuteAsync(() => UpdateCachedShiftsAsync(teamId, openShift, weekStartDate)).ConfigureAwait(false);

                // finally, remove the request from cache as we have finished with it
                await _requestCacheService.DeleteRequestAsync(teamId, openShiftRequest.Id).ConfigureAwait(false);

                return(true);
            }
            catch (Exception ex)
            {
                // the employee cannot claim this shift, so log it and try the next
                log.LogOpenShiftAssignmentError(ex, openShiftRequest.WfmSenderId, openShift.WfmShiftId, teamId);
            }

            return(false);
        }