Ejemplo n.º 1
0
            /// <summary>
            /// Validates the address as well as resolves the state from zip code, if needed.
            /// </summary>
            /// <param name="context">Instance of <see cref="RequestContext"/>.</param>
            /// <param name="addressToValidate">Address to be validated and resolved.</param>
            internal static void ValidateAndResolveAddress(RequestContext context, Address addressToValidate)
            {
                if (addressToValidate == null)
                {
                    // Nothing to validate.
                    return;
                }

                List <DataValidationFailure> validationFailures = new List <DataValidationFailure>();

                ShippingHelper.ValidateAndResolveAddress(context, addressToValidate, validationFailures);

                if (validationFailures.Any())
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_AggregateValidationError, validationFailures, "Failures when validating address.");
                }
            }
            /// <summary>
            /// Executes the workflow to fetch delivery options for given product and address.
            /// </summary>
            /// <param name="request">Instance of <see cref="GetProductDeliveryOptionsRequest"/>.</param>
            /// <returns>Instance of <see cref="GetProductDeliveryOptionsResponse"/>.</returns>
            protected override GetProductDeliveryOptionsResponse Process(GetProductDeliveryOptionsRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShippingAddress, "request.ShippingAddress");

                // Validate and resolve address
                ShippingHelper.ValidateAndResolveAddress(this.Context, request.ShippingAddress);

                // Get the delivery options
                var serviceRequest = new GetProductDeliveryOptionsServiceRequest(request.ShippingAddress, request.ItemId, request.InventoryDimensionId)
                {
                    QueryResultSettings = request.QueryResultSettings
                };
                var serviceResponse = this.Context.Execute <GetProductDeliveryOptionsServiceResponse>(serviceRequest);

                return(new GetProductDeliveryOptionsResponse(serviceResponse.DeliveryOptions));
            }