public ReviewsViewModel Get(string productCode) { return(_cache.ReadThrough(CachePrefix + productCode, () => { // Instantiate a reference for the product var product = Reference.Create($"product://{productCode}"); try { // Retrieve the rating statistics for the product var statistics = GetProductStatistics(product); // Retrieve the reviews for the product var reviews = GetProductReviews(product); // Return the data as a ReviewsViewModel return new ReviewsViewModel { Statistics = ViewModelAdapter.Adapt(statistics), Reviews = ViewModelAdapter.Adapt(reviews) }; } catch (SocialRepositoryException) { //DO SOMETHING } return new ReviewsViewModel(); }, (x) => new CacheEvictionPolicy(TimeSpan.FromMinutes(15), CacheTimeoutType.Absolute), ReadStrategy.Wait)); }
public List <UniqueCoupon> GetByPromotionId(int id) { try { return(_cache.ReadThrough(GetPromotionCacheKey(id), () => { var coupons = new List <UniqueCoupon>(); var connectionString = _connectionHandler.Commerce.ConnectionString; using (var connection = new SqlConnection(connectionString)) { connection.Open(); var command = new SqlCommand { Connection = connection, CommandType = CommandType.StoredProcedure, CommandText = "UniqueCoupons_GetByPromotionId" }; command.Parameters.Add(new SqlParameter("@PromotionId", id)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { coupons.Add(GetUniqueCoupon(reader)); } } } return coupons; }, x => GetCacheEvictionPolicy(x), ReadStrategy.Wait)); } catch (Exception exn) { _logger.Error(exn.Message, exn); } return(null); }