/// <summary> /// Gets all button grids. /// </summary> /// <param name="request">Request instance.</param> /// <returns>Response instance.</returns> private static GetButtonGridsServiceResponse GetButtonGrids(GetButtonGridsServiceRequest request) { // resolves the layout based on the principal (user, terminal, channel) and get the button grid ids for those var getTillLayoutRequest = new GetTillLayoutDataRequest(); TillLayout layout = request.RequestContext.Execute <SingleEntityDataServiceResponse <TillLayout> >(getTillLayoutRequest).Entity; if (layout == null) { throw new ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_LayoutNotFound, "Could not find layout associated with the request."); } // get all button grids var getButtonGridDataRequest = new GetButtonGridsDataRequest(QueryResultSettings.AllRecords); PagedResult <ButtonGrid> buttonGrids = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <ButtonGrid> >(getButtonGridDataRequest, request.RequestContext).PagedEntityCollection; // get all button grids that participate on the layout (top level) var topLevelButtonGridIdsPertainingToLayout = layout.ButtonGridZones.Select(buttonGridZone => buttonGridZone.ButtonGridId); // get filter only button grids pertaining to the layout var layoutFilteredButtonGrids = new ButtonGridFilter(topLevelButtonGridIdsPertainingToLayout, buttonGrids.Results).GetButtonGrids(); // paginate result according to client settings PagedResult <ButtonGrid> buttonGridPagedResult = new PagedResult <ButtonGrid>( layoutFilteredButtonGrids, request.QueryResultSettings.Paging, layoutFilteredButtonGrids.Count); return(new GetButtonGridsServiceResponse(buttonGridPagedResult)); }
/// <summary> /// Gets till layout by given parameters in request. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> private SingleEntityDataServiceResponse <TillLayout> GetTillLayout(GetTillLayoutDataRequest request) { var context = request.RequestContext; var tillLayoutDataManager = this.GetTillLayoutDataManagerInstance(context); string userId; long terminalId; long channelId; if (request.IsPrincipalSpecified) { userId = request.UserId; terminalId = request.TerminalId.Value; channelId = request.ChannelId.Value; } else { var principal = context.GetPrincipal(); channelId = principal.ChannelId; terminalId = principal.TerminalId; userId = principal.UserId; } var tillLayout = tillLayoutDataManager.GetTillLayout(channelId, terminalId, userId); return(new SingleEntityDataServiceResponse <TillLayout>(tillLayout)); }