Esempio n. 1
0
            /// <summary>
            /// Gets the delivery options that are applicable to entire SalesTransaction i.e., common for all the sales lines.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The matching delivery options.</returns>
            private static GetOrderDeliveryOptionsServiceResponse GetOrderDeliveryOptions(GetOrderDeliveryOptionsServiceRequest request)
            {
                if (request.SalesTransaction == null)
                {
                    throw new NotSupportedException("Sales transaction on the request cannot be null.");
                }

                if (request.SalesTransaction.ShippingAddress == null)
                {
                    throw new NotSupportedException("The shipping address on the sales transaction cannot be null if order level delivery options are being fetched.");
                }

                // Consider active lines only. Ignore voided lines.
                var salesLines = request.SalesTransaction.ActiveSalesLines;

                foreach (SalesLine salesLine in salesLines)
                {
                    salesLine.ShippingAddress = request.SalesTransaction.ShippingAddress;
                }

                var dataServiceRequest = new GetLineDeliveryOptionsDataRequest(salesLines);

                dataServiceRequest.QueryResultSettings = QueryResultSettings.AllRecords;
                var dataServiceResponse = request.RequestContext.Execute <EntityDataServiceResponse <SalesLineDeliveryOption> >(dataServiceRequest);

                IEnumerable <DeliveryOption> deliveryOptions = null;

                if (dataServiceResponse != null)
                {
                    var salesLineDeliveryOptions = dataServiceResponse.PagedEntityCollection.Results;
                    deliveryOptions = GetCommonDeliveryOptions(salesLineDeliveryOptions);
                }

                // Raise notification if no common delivery options were found.
                if (deliveryOptions == null || !deliveryOptions.Any())
                {
                    var notification = new EmptyOrderDeliveryOptionSetNotification(request.SalesTransaction.Id);
                    request.RequestContext.Notify(notification);
                }

                return(new GetOrderDeliveryOptionsServiceResponse(deliveryOptions.AsPagedResult()));
            }
 private static void NotifyEmptyOrderDeliveryOptionSetNotification(EmptyOrderDeliveryOptionSetNotification notification)
 {
     throw new ConfigurationException(
               ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_UnableToFindDeliveryOptions,
               string.Format("No common delivery option found for the order. Order id: {0}", notification.OrderId));
 }