/// <summary>
        /// Invoked when a filter is selected using the ComboBox in snapped view state.
        /// </summary>
        /// <param name="sender">The ComboBox instance.</param>
        /// <param name="e">Event data describing how the selected filter was changed.</param>
        void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Determine what filter was selected
            var selectedFilter = e.AddedItems.FirstOrDefault() as Filter;

            if (selectedFilter != null)
            {
                // Mirror the results into the corresponding Filter object to allow the
                // RadioButton representation used when not snapped to reflect the change
                selectedFilter.Active = true;

                // TODO: Respond to the change in active filter by setting this.DefaultViewModel["Results"]
                //       to a collection of items with bindable Image, Title, Subtitle, and Description properties

                DefaultViewModel["Results"] = null; // clear previous result
                DefaultViewModel["Results"] = new ObservableCollection <SearchResult>();
                var searchText = DefaultViewModel["QueryText"] as string;
                if (!String.IsNullOrEmpty(searchText))
                {
                    NetflixCatalog catalog = new NetflixCatalog(netflixServiceUri);
                    var            query   = catalog.Titles.Where(t => t.Name.Contains(searchText)).Select(t => t);

                    var queryResults = new DataServiceCollection <Title>();
                    queryResults.LoadCompleted +=
                        (o, args) =>
                    {
                        if (queryResults.Continuation != null)
                        {
                            queryResults.LoadNextPartialSetAsync();
                        }
                        else
                        {
                            DefaultViewModel["Results"] = queryResults.Select(t =>
                                                                              new
                            {
                                Title       = t.Name,
                                Subtitle    = t.ShortName,
                                Description = t.ShortSynopsis,
                                Image       = t.BoxArt.MediumUrl
                            }).ToList();
                            // ensure that results are found
                            object      results;
                            ICollection resultsCollection;
                            if (this.DefaultViewModel.TryGetValue("Results", out results) &&
                                (resultsCollection = results as ICollection) != null &&
                                resultsCollection.Count != 0)
                            {
                                VisualStateManager.GoToState(this, "ResultsFound", true);
                            }
                        }
                    };
                    queryResults.LoadAsync(query);
                }
            }

            // Display informational text when there are no search results.
            VisualStateManager.GoToState(this, "NoResultsFound", true);
        }
예제 #2
0
        public override void Process(ServicePipelineArgs args)
        {
            // validate args
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.Request");
            Assert.ArgumentNotNull(args.Request.RequestContext, "args.Request.RequestContext");
            Assert.ArgumentNotNull(args.Result, "args.Result");
            GetShippingOptionsRequest request = args.Request as GetShippingOptionsRequest;
            GetShippingOptionsResult  result  = args.Result as GetShippingOptionsResult;

            Assert.IsNotNull(request, "The parameter args.Request was not of the expected type.  Expected {0}.  Actual {1}.", typeof(GetShippingOptionsRequest).Name, args.Request.GetType().Name);
            Assert.IsNotNull(result, "The parameter args.Result was not of the expected type.  Expected {0}.  Actual {1}.", typeof(GetShippingOptionsResult).Name, args.Result.GetType().Name);

            try
            {
                Assert.ArgumentNotNull(request.Cart, "request.Cart");
                Assert.IsTrue(request.Cart.Lines.Count > 0, "request.Cart.Lines");
                string cartId = request.Cart.ExternalId;
                List <CartFulfillment> cartFulfillments = Proxy.Execute(this.GetContainer(request.Cart.ShopName, request.Cart.UserId, request.Cart.CustomerId, "", args.Request.CurrencyCode, new DateTime?()).GetCartWithFulfillmentOptions(cartId).Expand("FulfillmentOptions")).ToList();
                DataServiceCollection <FulfillmentOption> fulfillmentOptions = cartFulfillments.FirstOrDefault(k => k.TargetId == cartId)?.FulfillmentOptions;
                if (fulfillmentOptions == null || !fulfillmentOptions.Any())
                {
                    result.Success = false;
                    return;
                }
                List <ShippingOption>     shippingOptions        = fulfillmentOptions.Select(this.TranslateShippingOption).ToList();
                List <LineShippingOption> lineShippingOptionList = new List <LineShippingOption>();

                foreach (CartLine cartLine in request.Cart.Lines)
                {
                    CartLine line = cartLine;
                    DataServiceCollection <FulfillmentOption> lineFulfillmentOptions = cartFulfillments.FirstOrDefault(k => k.TargetId == line.ExternalCartLineId)?.FulfillmentOptions;
                    if (!lineFulfillmentOptions.Any())
                    {
                        result.Success = false;
                        return;
                    }
                    List <ShippingOption> lineShippingOptions = lineFulfillmentOptions.Select(this.TranslateShippingOption).ToList();
                    LineShippingOption    lineShippingOption  = this.EntityFactory.Create <LineShippingOption>("LineShippingOption");
                    lineShippingOption.LineId          = line.ExternalCartLineId;
                    lineShippingOption.ShippingOptions = lineShippingOptions;
                    lineShippingOptionList.Add(lineShippingOption);
                }

                result.ShippingOptions         = shippingOptions.AsReadOnly();
                result.LineShippingPreferences = lineShippingOptionList.AsReadOnly();
            }
            catch (ArgumentException ex)
            {
                result.Success = false;
                result.SystemMessages.Add(new SystemMessage(ex.Message));
            }
            base.Process(args);
        }
 public static IEnumerable <ReadingViewModel> CreateReadingsViewModels(DataServiceCollection <Reading> readings)
 {
     return(readings.Select(reading => new ReadingViewModel(reading))
            .ToList());
 }