Example #1
0
        public async Task <SimilarItemViewModel> GetSimilarItems(string movieItemId)
        {
            SimilarItemViewModel results = null;

            try
            {
                //RELATED_ITEMS -- itemId required
                var relateditemsrequest = new GetRecommendationsRequest
                {
                    CampaignArn = AwsParameterStoreClient.GetSimsArn(), //sims-arn
                    ItemId      = movieItemId,
                    NumResults  = 10
                };

                var relateditemsrequestresponse = await AmazonPersonalizeRuntimeClient.GetRecommendationsAsync(relateditemsrequest);

                var relateditemsrequestrecommendedItems = relateditemsrequestresponse.ItemList;

                var json = JsonConvert.SerializeObject(relateditemsrequestrecommendedItems);

                Logger.LogInformation("GetSimilarItems for movie:" + movieItemId + ": " + json);

                results = new SimilarItemViewModel
                {
                    //selected movie
                    Movie = await _storageService.GetMovieData(movieItemId)
                };


                List <string> itemIds = relateditemsrequestrecommendedItems.Select(s => s.ItemId).ToList();

                results.SimilarItems.Movies = await _storageService.GetMovieData(itemIds.ToArray());

                return(results);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 public SimilarViewPageModel()
 {
     SimilarItemViewModel = new SimilarItemViewModel();
     MostPopularItems     = new MostPopularItems();
 }