public async Task <IActionResult> CreateTestReviews() { StringBuilder sb = new StringBuilder(); Random rnd = new Random(); for (int i = 0; i < 10; i++) { LegacyReview review = new LegacyReview { Approved = true, Location = "nowhere", Locale = "nowhere", ProductId = rnd.Next(100, 99999).ToString(), Rating = rnd.Next(1, 5), ReviewerName = "Test Reviewer", ShopperId = "*****@*****.**", VerifiedPurchaser = true, Title = "Test Review", Text = "This is a test Review." }; LegacyReview result = await _productReviewsService.NewReviewLegacy(review); sb.AppendLine($"[{i}] {result.Id} {result.ProductId}"); } return(Json(sb.ToString())); }
private async Task <Review> ConvertLegacyReview(LegacyReview review) { Review newReview = new Review { Approved = review.Approved ?? false, Id = review.Id.ToString(), Location = review.Location, ProductId = review.ProductId, Rating = review.Rating, ReviewDateTime = review.ReviewDateTime, ReviewerName = review.ReviewerName, ShopperId = review.ShopperId, Sku = review.Sku, Text = review.Text, Title = review.Title, Locale = review.Locale, VerifiedPurchaser = review.VerifiedPurchaser ?? false }; return(newReview); }
public async Task <LegacyReview> NewReviewLegacy(LegacyReview review) { IDictionary <int, string> lookup = await _productReviewRepository.LoadLookupAsync(); int maxKeyValue = 0; if (lookup != null) { maxKeyValue = lookup.Keys.Max(); maxKeyValue++; } review.Id = maxKeyValue; Console.WriteLine($"MAX KEY VALUE = {maxKeyValue}"); IList <LegacyReview> reviews = await this._productReviewRepository.GetProductReviewsAsync(review.ProductId); if (reviews == null) { reviews = new List <LegacyReview>(); } reviews.Add(review); await this._productReviewRepository.SaveProductReviewsAsync(review.ProductId, reviews); try { lookup.Add(review.Id, review.ProductId); } catch (Exception ex) { Console.WriteLine($"NewReviewLegacy {ex.Message}"); } await _productReviewRepository.SaveLookupAsync(lookup); return(review); }
public async Task <bool> DeleteLegacyReview(int[] ids, string productId = null) { bool retval = true; IDictionary <int, string> lookup = await _productReviewRepository.LoadLookupAsync(); foreach (int id in ids) { if (string.IsNullOrEmpty(productId)) { lookup.TryGetValue(id, out productId); } if (!string.IsNullOrEmpty(productId)) { IList <LegacyReview> reviews = await this._productReviewRepository.GetProductReviewsAsync(productId); LegacyReview reviewToRemove = reviews.Where(r => r.Id == id).FirstOrDefault(); if (reviewToRemove != null && reviews.Remove(reviewToRemove)) { await this._productReviewRepository.SaveProductReviewsAsync(productId, reviews); } } else { retval = false; } // also remove the reference to the review from the loopup if (lookup != null && lookup.Keys.Contains(id)) { lookup.Remove(id); } } await _productReviewRepository.SaveLookupAsync(lookup); return(retval); }