/// <summary> /// Executes the workflow associated with retrieving online channel by channel identifier. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetOnlineChannelResponse Process(GetOnlineChannelRequest request) { ThrowIf.Null(request, "request"); var getOnlineChannelByIdDataRequest = new GetOnlineChannelByIdDataRequest(request.ChannelId, new ColumnSet()); OnlineChannel channel = this.Context.Runtime.Execute <SingleEntityDataServiceResponse <OnlineChannel> >(getOnlineChannelByIdDataRequest, this.Context).Entity; if (channel == null) { string message = string.Format(CultureInfo.InvariantCulture, "Cannot load channel for ID '{0}'.", request.ChannelId); throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ValueOutOfRange, message); } var settings = QueryResultSettings.AllRecords; var getChannelProfileByChannelIdDataRequest = new GetChannelProfileByChannelIdDataRequest(request.ChannelId, QueryResultSettings.SingleRecord); channel.ChannelProfile = this.Context.Runtime.Execute <SingleEntityDataServiceResponse <ChannelProfile> >(getChannelProfileByChannelIdDataRequest, this.Context).Entity; var getChannelPropertiesByChannelIdDataRequest = new GetChannelPropertiesByChannelIdDataRequest(request.ChannelId, settings); channel.ChannelProperties = this.Context.Runtime.Execute <EntityDataServiceResponse <ChannelProperty> >(getChannelPropertiesByChannelIdDataRequest, this.Context).PagedEntityCollection.Results; var getChannelLanguagesByChannelIdDataRequest = new GetChannelLanguagesByChannelIdDataRequest(request.ChannelId, settings); channel.ChannelLanguages = this.Context.Runtime.Execute <EntityDataServiceResponse <ChannelLanguage> >(getChannelLanguagesByChannelIdDataRequest, this.Context).PagedEntityCollection.Results; var getOrgunitContactsDataRequest = new GetOrgUnitContactsDataRequest(new long[] { request.ChannelId }, settings); channel.Contacts = this.Context.Runtime.Execute <EntityDataServiceResponse <OrgUnitContact> >(getOrgunitContactsDataRequest, this.Context).PagedEntityCollection.Results; var response = new GetOnlineChannelResponse(channel); return(response); }
private EntityDataServiceResponse <OrgUnitContact> GetOrgUnitContacts(GetOrgUnitContactsDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.ChannelIds, "request.ChannelIds"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); var query = new SqlPagedQuery(request.QueryResultSettings) { From = OrgUnitContactsView, OrderBy = "CHANNELID" }; PagedResult <OrgUnitContact> results; IEnumerable <string> distinctChannelIds = request.ChannelIds.Distinct <long>().Select <long, string>(id => id.ToString()); using (StringIdTableType channelIdsTable = new StringIdTableType(distinctChannelIds, "CHANNELID")) { query.Parameters["@TVP_CHANNELID"] = channelIdsTable; using (var sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { results = sqlServerDatabaseContext.ReadEntity <OrgUnitContact>(query); } } return(new EntityDataServiceResponse <OrgUnitContact>(results)); }
/// <summary> /// Parse list of locations and extract store location and contact information. /// </summary> /// <param name="storeLocationsRecords">Parse collection of the <see cref="OrgUnitLocation"/>.</param> /// <param name="context">The request context.</param> /// <returns>Collection of the <see cref="OrgUnitLocation"/>.</returns> private PagedResult <OrgUnitLocation> ParseLocations(IEnumerable <OrgUnitLocation> storeLocationsRecords, RequestContext context) { Dictionary <long, OrgUnitLocation> storeLocationResults = new Dictionary <long, OrgUnitLocation>(); if (storeLocationsRecords != null && storeLocationsRecords.Any()) { // go over list of locations and extract store location and contact information. foreach (OrgUnitLocation currentStoreLocation in storeLocationsRecords) { if (!storeLocationResults.ContainsKey(currentStoreLocation.PostalAddressId)) { storeLocationResults.Add(currentStoreLocation.PostalAddressId, currentStoreLocation); } } IEnumerable <OrgUnitLocation> result = storeLocationResults.Values; var channelIds = result.Select <OrgUnitLocation, long>(orgUnitLocation => orgUnitLocation.ChannelId); var getOrgUnitContactsDataRequest = new GetOrgUnitContactsDataRequest(channelIds); IEnumerable <OrgUnitContact> contacts = context.Execute <EntityDataServiceResponse <OrgUnitContact> >(getOrgUnitContactsDataRequest).PagedEntityCollection.Results; // map the OrgUnitContacts to OrgUnitLocation result = result.GroupJoin <OrgUnitLocation, OrgUnitContact, long, OrgUnitLocation>( contacts, orgUnitLocation => orgUnitLocation.ChannelId, orgUnitContact => orgUnitContact.ChannelId, (orgUnitLocation, orgUnitContacts) => { foreach (OrgUnitContact storeContact in orgUnitContacts) { if (storeContact.Locator != null || storeContact.Description != null) { orgUnitLocation.Contacts.Add(storeContact); } } return(orgUnitLocation); }); } return(storeLocationResults.Values.ToArray().AsPagedResult()); }