Exemple #1
0
        public static AmazonReview Construct(
            ProductData product,
            UserData user,
            AmazonReviewData data,
            AmazonTextData textData)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrEmpty(product.Id))
            {
                throw new ArgumentException(nameof(product.Id));
            }

            if (string.IsNullOrEmpty(user.Id))
            {
                throw new ArgumentException(nameof(user.Id));
            }

            AmazonReview review = new AmazonReview();

            review.Data     = data ?? throw new ArgumentNullException(nameof(data));
            review.Product  = product;
            review.User     = user;
            review.TextData = textData ?? throw new ArgumentNullException(nameof(textData));
            return(review);
        }
Exemple #2
0
        public static AmazonReview ContructNew(ProductData product, UserData user, AmazonReviewData data, AmazonTextData textData)
        {
            var review = Construct(product, user, data, textData);

            review.Data.Id        = $"{product.Id}:{user.Id}";
            review.Data.ProductId = product.Id;
            review.Data.UserId    = user.Id;
            review.TextData.Id    = review.Id;
            return(review);
        }
        private async Task <AmazonReview> GetAmazonReview(AmazonReviewData data)
        {
            var userTask    = LoadUser(data.UserId);
            var productTask = LoadProduct(data.ProductId);
            var textData    = await manager.Client.GetRecords <AmazonTextData>(GetAmazonDataKey(data.Id)).FirstAsync();

            await Task.WhenAll(userTask, productTask).ConfigureAwait(false);

            var review = AmazonReview.Construct(productTask.Result, userTask.Result, data, textData);

            return(review);
        }