Exemplo n.º 1
0
 /// <summary>
 /// Creates an employee session.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>The response for creating the new session.</returns>
 private CreateEmployeeSessionDataResponse CreateEmployeeSession(CreateEmployeeSessionDataRequest request)
 {
     return(this.CreateEmployeeSession(
                request.RequestContext,
                request.AlllowMultipleTerminalSessions,
                request.RequestContext.GetPrincipal().ChannelId,
                request.RequestContext.GetTerminal().TerminalId,
                request.RequestContext.GetPrincipal().UserId,
                request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId));
 }
            /// <summary>
            /// Associates the employee <paramref name="staffId"/> with the current terminal in <paramref name="context"/> on the local database.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="employee">The employee.</param>
            /// <returns>The employee object associated to <paramref name="staffId"/>.</returns>
            /// <remarks>If employee cannot hold multiple sessions on different terminals <see cref="UserAuthorizationException"/> is thrown.</remarks>
            private static Employee CreateEmployeeSessionLocalDatabase(RequestContext context, Employee employee)
            {
                // tries to creates a new entry on the DB that associates the user to the terminal
                CreateEmployeeSessionDataRequest createSessionRequest = new CreateEmployeeSessionDataRequest(employee.Permissions.AllowMultipleLogins);
                string existingSessionTerminalId = context.Execute <CreateEmployeeSessionDataResponse>(createSessionRequest).ExistingSessionTerminalId;
                bool   employeeHasSessionOpenOnAnotherTerminal = !string.IsNullOrWhiteSpace(existingSessionTerminalId);

                // check if the session was created for the employee
                if (employeeHasSessionOpenOnAnotherTerminal && !employee.Permissions.AllowMultipleLogins)
                {
                    string message = string.Format(
                        "Employee has an open session on terminal {0} and is not allowed to have open sessions on multiple terminals at once.",
                        existingSessionTerminalId);
                    throw new UserAuthorizationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_UserLogonAnotherTerminal, message);
                }

                return(employee);
            }