public async Task <bool> DeleteReviewAsync(int[] ids) { bool retval = true; IDictionary <int, string> lookup = await _productReviewRepository.LoadLookupAsync(); foreach (int id in ids) { if (lookup.TryGetValue(id, out var productId)) { IList <Review> reviews = await _productReviewRepository.GetProductReviewsAsync(productId); Review reviewToRemove = reviews.Where(r => r.Id == id).FirstOrDefault(); if (reviewToRemove != null && reviews.Remove(reviewToRemove)) { await _productReviewRepository.SaveProductReviewsAsync(productId, reviews); } } else { retval = false; } // also remove the reference to the review from the loopup lookup.Remove(id); } await _productReviewRepository.SaveLookupAsync(lookup); return(retval); }
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); }