Beispiel #1
0
            private GlobalCustomer GetCustomer(string emailAddress)
            {
                CustomerSearchCriteria criteria = new CustomerSearchCriteria {
                    Keyword = emailAddress
                };
                var searchCustomerRequest  = new CustomersSearchServiceRequest(criteria, QueryResultSettings.AllRecords);
                var searchCustomerResponse = this.Context.Execute <CustomersSearchServiceResponse>(searchCustomerRequest);
                var matchedSearchResults   = searchCustomerResponse.Customers.Results.Where(c => emailAddress.Equals(c.Email, System.StringComparison.OrdinalIgnoreCase));

                GlobalCustomer foundCustomer = matchedSearchResults.FirstOrDefault();

                return(foundCustomer);
            }
            /// <summary>
            /// Executes the workflow to retrieve customer information.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The response.</returns>
            protected override CustomersSearchResponse Process(CustomersSearchRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.Criteria, "request.Criteria");

                var serviceRequest = new CustomersSearchServiceRequest(
                    request.Criteria,
                    request.QueryResultSettings);

                CustomersSearchServiceResponse serviceResponse = this.Context.Execute <CustomersSearchServiceResponse>(serviceRequest);

                // If no Customers were found then attempt search by barcode.
                if (serviceResponse.Customers.Results.Count == 0 && !string.IsNullOrWhiteSpace(request.Criteria.Keyword))
                {
                    var scanInfo = new ScanInfo()
                    {
                        ScannedText = request.Criteria.Keyword
                    };
                    var barcodeRequest = new GetBarcodeRequest(scanInfo);
                    GetBarcodeResponse getBarcodeResponse = this.Context.Runtime.Execute <GetBarcodeResponse>(barcodeRequest, this.Context);
                    Barcode            barcode            = getBarcodeResponse.Barcode;

                    // If barcode was a customer barcode then use result of barcode search to search for customer again.
                    if (barcode != null && barcode.Mask.MaskType == BarcodeMaskType.Customer)
                    {
                        request.Criteria.Keyword = barcode.CustomerId;
                        var customerServiceRequest = new CustomersSearchServiceRequest(
                            request.Criteria,
                            request.QueryResultSettings);

                        serviceResponse = this.Context.Execute <CustomersSearchServiceResponse>(customerServiceRequest);
                    }
                }

                return(new CustomersSearchResponse(serviceResponse.Customers));
            }