/// <summary> /// Executes the workflow to do user authentication. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetEmployeePermissionsResponse Process(GetEmployeePermissionsRequest request) { ThrowIf.Null(request, "request"); GetEmployeesServiceRequest getEmployeeRequest = new GetEmployeesServiceRequest(request.StaffId, QueryResultSettings.SingleRecord); GetEmployeesServiceResponse employeeResponse = this.Context.Execute <GetEmployeesServiceResponse>(getEmployeeRequest); Employee employee = employeeResponse.Employees.SingleOrDefault(); if (employee == null) { return(new GetEmployeePermissionsResponse(employee)); } // Check if the requested Employee object is same as logged-on user. // If not, check staff have manager permission. // If the staff is not manager, do not return permissions if (!string.Equals(request.StaffId, this.Context.GetPrincipal().UserId)) { try { this.Context.Execute <Response>(new CheckAccessIsManagerServiceRequest()); } catch (UserAuthorizationException) { return(new GetEmployeePermissionsResponse(employee)); } } GetEmployeePermissionsDataRequest permissionsDataRequest = new GetEmployeePermissionsDataRequest(request.StaffId, new ColumnSet()); employee.Permissions = this.Context.Execute <SingleEntityDataServiceResponse <EmployeePermissions> >(permissionsDataRequest).Entity; return(new GetEmployeePermissionsResponse(employee)); }
/// <summary> /// Executes the workflow to get the currently logged in employee. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetCurrentEmployeeResponse Process(GetCurrentEmployeeRequest request) { ThrowIf.Null(request, "request"); // authorize employee will return employee and all permissions var staffRequest = new StaffAuthorizationServiceRequest( request.RequestContext.Runtime.CurrentPrincipal.UserId, RetailOperation.None); var response = this.Context.Execute <StaffAuthorizationServiceResponse>(staffRequest); // get the full employee object from the database. Employee employee = response.Employee; if (employee != null && !string.IsNullOrWhiteSpace(employee.StaffId)) { var employeePermission = employee.Permissions; QueryResultSettings settings = new QueryResultSettings(new PagingInfo(top: 1)); GetEmployeesServiceRequest employeeRequest = new GetEmployeesServiceRequest(employee.StaffId, settings); var employeeResponse = this.Context.Execute <GetEmployeesServiceResponse>(employeeRequest); if (employeeResponse != null) { employee = employeeResponse.Employees.SingleOrDefault(); // Set the employee permission as persisted during staff authorization call. employee.Permissions = employeePermission; } // Set the number of days to password expiry on the employee. int passwordExpiryIntervalInDays = 0; int passwordExpiryNotificationThreshold = 0; ChannelConfiguration channelConfiguration = this.Context.GetChannelConfiguration(); if (channelConfiguration != null) { passwordExpiryIntervalInDays = channelConfiguration.PasswordExpiryIntervalInDays; passwordExpiryNotificationThreshold = channelConfiguration.PasswordExpiryNotificationThresholdInDays; } employee.NumberOfDaysToPasswordExpiry = CalculateNumberOfDaysToPasswordExpiry(passwordExpiryIntervalInDays, passwordExpiryNotificationThreshold, employee.PasswordLastChangedDateTime); } return(new GetCurrentEmployeeResponse(employee)); }
/// <summary> /// Get employees using the request criteria. /// </summary> /// <param name="request">Request containing the criteria to retrieve employees for.</param> /// <returns>GetEmployeesServiceResponse object.</returns> private static GetEmployeesServiceResponse GetEmployees(GetEmployeesServiceRequest request) { if (!string.IsNullOrEmpty(request.StaffId)) { GetEmployeeDataRequest dataRequest = new GetEmployeeDataRequest(request.StaffId, QueryResultSettings.SingleRecord); Employee employee = request.RequestContext.Execute <SingleEntityDataServiceResponse <Employee> >(dataRequest).Entity; if (employee == null) { return(new GetEmployeesServiceResponse()); } return(new GetEmployeesServiceResponse(employee)); } else { EntityDataServiceRequest <Employee> dataRequest = new EntityDataServiceRequest <Employee>(request.QueryResultSettings); var employees = request.RequestContext.Execute <EntityDataServiceResponse <Employee> >(dataRequest).PagedEntityCollection; return(new GetEmployeesServiceResponse(employees)); } }