/// <summary>
            /// Executes the create shift staging workflow.
            /// </summary>
            /// <param name="request">The new Shift request.</param>
            /// <returns>The new Shift response.</returns>
            protected override ChangeShiftStatusResponse Process(ChangeShiftStatusRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShiftTerminalId, "request.ShiftTerminalId");

                if (this.Context.GetTerminal() != null)
                {
                    request.TerminalId = this.Context.GetTerminal().TerminalId;
                }

                EmployeePermissions permissions = EmployeePermissionHelper.GetEmployeePermissions(this.Context, this.Context.GetPrincipal().UserId);
                bool includeSharedShifts        = permissions.HasManagerPrivileges || permissions.AllowManageSharedShift || permissions.AllowUseSharedShift;
                var  staffId    = this.Context.GetPrincipal().UserId;
                var  terminalId = request.ShiftTerminalId;
                var  shifts     = ShiftDataDataServiceHelper.GetShifts(
                    this.Context,
                    this.Context.GetPrincipal().ChannelId,
                    terminalId,
                    request.ShiftId,
                    includeSharedShifts);

                Shift shift = ShiftDataDataServiceHelper.FilterShifts(shifts, terminalId, staffId).FirstOrDefault();

                if (shift == null)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, "There is no shift with the given identifier.");
                }

                ShiftTransitionHelper shiftTransitionHelper = new ShiftTransitionHelper(this.Context, request);

                // Validate if the change of shift status can be performed
                shiftTransitionHelper.TransitShiftStatus(shift);

                shift.StatusDateTime = this.Context.GetNowInChannelTimeZone();

                UpdateShiftStagingTableDataRequest dataServiceRequest = new UpdateShiftStagingTableDataRequest(shift);

                request.RequestContext.Runtime.Execute <NullResponse>(dataServiceRequest, this.Context);

                this.SaveTransactionLog(shift, request.TransactionId);

                if (request.ToStatus == ShiftStatus.Closed)
                {
                    this.PurgeSalesTransactionData(request.RequestContext);
                }

                return(new ChangeShiftStatusResponse(shift));
            }
            /// <summary>
            /// Executes the resume shift workflow.
            /// </summary>
            /// <param name="request">The new shift request.</param>
            /// <returns>The resume shift response.</returns>
            protected override ResumeShiftResponse Process(ResumeShiftRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShiftTerminalId, "request.ShiftTerminalId");

                if (this.Context.GetTerminal() != null)
                {
                    request.TerminalId = this.Context.GetTerminal().TerminalId;
                }

                bool includeSharedShifts = this.Permissions.HasManagerPrivileges || this.Permissions.AllowManageSharedShift || this.Permissions.AllowUseSharedShift;
                var  staffId             = this.Context.GetPrincipal().UserId;
                var  terminalId          = request.ShiftTerminalId;
                var  shifts = ShiftDataDataServiceHelper.GetShifts(
                    this.Context,
                    this.Context.GetPrincipal().ChannelId,
                    terminalId,
                    request.ShiftId,
                    includeSharedShifts);

                Shift shift = ShiftDataDataServiceHelper.FilterShifts(shifts, terminalId, staffId).FirstOrDefault();

                this.ValidateCanResumeShift(request, shift);

                shift.CashDrawer        = request.CashDrawer;
                shift.CurrentStaffId    = this.Context.GetPrincipal().UserId;
                shift.CurrentTerminalId = request.TerminalId;
                shift.Status            = ShiftStatus.Open;
                shift.StatusDateTime    = this.Context.GetNowInChannelTimeZone();

                UpdateShiftStagingTableDataRequest dataServiceRequest = new UpdateShiftStagingTableDataRequest(shift);

                request.RequestContext.Runtime.Execute <NullResponse>(dataServiceRequest, this.Context);

                return(new ResumeShiftResponse(shift));
            }