コード例 #1
0
        public override async Task <Reviewable[]> SearchReviewablesAsync(string searchText, int pageOffset, int pageLimit)
        {
            Reviewable[]        reviewables = null;
            HttpResponseMessage response    = await client.GetAsync(getUrlForSearch(searchText, pageOffset, pageLimit));

            if (response.IsSuccessStatusCode)
            {
                var reviewableString = await response.Content.ReadAsStringAsync();

                OMDBJSONSearchResponse search = JsonConvert.DeserializeObject <OMDBJSONSearchResponse>(reviewableString);

                if (search.Response)
                {
                    reviewables = search.reviewables.Select(r => {
                        var reviewable           = new Reviewable();
                        reviewable.Title         = r.title;
                        reviewable.Type          = r.type;
                        reviewable.TitleImageUrl = r.image;
                        reviewable.TpId          = r.imdbID;
                        reviewable.TpName        = getThirdPartyName();
                        return(reviewable);
                    }).ToArray();
                }
            }

            return(reviewables);
        }
コード例 #2
0
        public override async Task <Reviewable> GetReviewableByIDAsync(string id)
        {
            Reviewable          reviewable = null;
            HttpResponseMessage response   = await client.GetAsync(getUrlForId(id));

            if (response.IsSuccessStatusCode)
            {
                var reviewableString = await response.Content.ReadAsStringAsync();

                OMDBJSONResponse reviewableJSON = JsonConvert.DeserializeObject <OMDBJSONResponse>(reviewableString);

                reviewable               = new Reviewable();
                reviewable.Title         = reviewableJSON.title;
                reviewable.Type          = reviewableJSON.type;
                reviewable.TitleImageUrl = reviewableJSON.poster;
                reviewable.TpId          = reviewableJSON.imdbID;
                reviewable.TpName        = getThirdPartyName();
                reviewable.Description   = reviewableJSON.plot;

                using (var context = new RevojiDataContext())
                {
                    var rev = context.Reviewables.Where(r => r.TpId == reviewable.TpId && r.TpName == getThirdPartyName()).FirstOrDefault();
                    if (rev != null)
                    {
                        reviewable.ID = rev.Id;
                    }
                }
            }

            return(reviewable);
        }
コード例 #3
0
        private Reviewable getReviewable(BarcodeJSONResponse product)
        {
            var reviewable = new Reviewable();

            reviewable.Title         = product.product_name;
            reviewable.TitleImageUrl = product.images.First();
            reviewable.TpId          = product.barcode_number;
            reviewable.TpName        = getThirdPartyName();
            reviewable.Type          = product.category.Split('>').Last().Trim();
            reviewable.Description   = product.description;
            return(reviewable);
        }
コード例 #4
0
        public override async Task <Reviewable> GetReviewableByIDAsync(string id)
        {
            Reviewable          reviewable = null;
            HttpResponseMessage response   = await client.GetAsync(getUrlForId(id));

            if (response.IsSuccessStatusCode)
            {
                var reviewableString = await response.Content.ReadAsStringAsync();

                BarcodeJSONSearchResponse reviewableJSON = JsonConvert.DeserializeObject <BarcodeJSONSearchResponse>(reviewableString);
                var product = reviewableJSON.reviewables.First();
                reviewable = getReviewable(product);
            }
            return(reviewable);
        }
コード例 #5
0
        private async Task <ItemReviewViewModel> BuildItemReviewViewModelAsync(Review review)
        {
            // generate a dictionary with song and album ids and names
            // this will serve as a lookup
            var albumLookup = await _context.Albums.ToDictionaryAsync(a => a.Id, a => a.Name);

            var songLookup = await _context.Songs.ToDictionaryAsync(s => s.Id, s => s.Name);

            int reviewableId = review.ReviewableId;

            // reload reviewable if null
            if (review.Reviewable == null)
            {
                Reviewable reviewable = _context.Set <Reviewable>()
                                        .FirstOrDefault(r => r.Id == review.ReviewableId);

                // if reviewable is song, load song and includeables
                if (reviewable is Song)
                {
                    reviewable = _context.Songs
                                 // include album
                                 .Include(s => s.Album)
                                 // include artist
                                 .Include(s => s.Artist)
                                 .FirstOrDefault(s => s.Id == reviewableId);
                }
                // if reviewable is album, load album and includeables
                else
                {
                    reviewable = _context.Albums
                                 .Include(a => a.Artist)
                                 .FirstOrDefault(a => a.Id == reviewableId);
                }

                review.Reviewable = reviewable;
            }

            if (review.Reviewable is Song)
            {
                Song song = review.Reviewable as Song;

                string reviewableName = $"Song \"{songLookup[reviewableId]}\"";
                if (song.Album != null)
                {
                    reviewableName += $" in \"{song.Album.Name}\"";
                }
                if (song.Artist != null)
                {
                    reviewableName += $" by {song.Artist.UserName}";
                }

                string reviewAuthorUsername = (await _userManager.FindByIdAsync(review.AuthorId)).UserName;

                return(new ItemReviewViewModel()
                {
                    Id = review.ReviewId,
                    Subject = review.Subject,
                    Rating = review.Rating,
                    Content = review.Content,
                    AuthorId = review.AuthorId,
                    AuthorUserName = reviewAuthorUsername,
                    ReviewableIsAlbum = false,
                    ReviewableId = reviewableId,
                    ReviewableName = reviewableName
                });
            }
            else if (review.Reviewable is Album)
            {
                Album album = review.Reviewable as Album;

                string reviewableName = $"Album \"{albumLookup[reviewableId]}\"";
                if (album.Artist != null)
                {
                    reviewableName += $" by {album.Artist.UserName}";
                }

                return(new ItemReviewViewModel()
                {
                    Id = review.ReviewId,
                    Subject = review.Subject,
                    Rating = review.Rating,
                    Content = review.Content,
                    AuthorId = review.AuthorId,
                    AuthorUserName = review.Author.UserName,
                    ReviewableIsAlbum = true,
                    ReviewableId = reviewableId,
                    ReviewableName = reviewableName
                });
            }
            else
            {
                throw new Exception("Reviewable is null.");
            }
        }