public void HandleEvent(ProductReviewApprovedEvent productReviewEvent) { if (!_rewardPointsSettingsForProductReviews.IsEnabled) { return; } if (productReviewEvent.ProductReview.Customer == null) { return; } //reward user only for the first approving if (_genericAttributeService.GetAttribute <bool>(productReviewEvent.ProductReview, "CustomerAwardedForProductReview", productReviewEvent.ProductReview.StoreId)) { return; } //check whether delay is set var activationDate = GetRewardPointsActivationDate(_rewardPointsSettingsForProductReviews); //get message for the current customer var languageId = _genericAttributeService.GetAttribute <int>(productReviewEvent.ProductReview.Customer, NopCustomerDefaults.LanguageIdAttribute, productReviewEvent.ProductReview.StoreId); var message = _rewardPointsSettingsForProductReviews.GetLocalizedSetting(settings => settings.Message, languageId, productReviewEvent.ProductReview.StoreId); var productName = _localizationService.GetLocalized(productReviewEvent.ProductReview.Product, product => product.Name, languageId); //add reward points for approved product review _rewardPointService.AddRewardPointsHistoryEntry(productReviewEvent.ProductReview.Customer, _rewardPointsSettingsForProductReviews.Points, productReviewEvent.ProductReview.StoreId, string.Format(message, productName), activatingDate: activationDate); //mark that customer was already awarded for the review _genericAttributeService.SaveAttribute(productReviewEvent.ProductReview, "CustomerAwardedForProductReview", true, productReviewEvent.ProductReview.StoreId); }
/// <summary> /// Implementation of <see cref="IProductCommands.ApproveProductReview(Guid, Guid)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="reviewId">The review id</param> /// <returns></returns> public virtual async Task ApproveProductReview(Guid productId, Guid reviewId) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } if (reviewId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(reviewId)); } var product = await Repository.GetByKeyAsync <Product>(productId); product.ApproveReview(reviewId); await Repository.SaveChangesAsync(); var @event = new ProductReviewApprovedEvent(productId, reviewId); EventBus.RaiseEvent(@event); } catch { throw; } }
public void Handle(ProductReviewApprovedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ProductReviewApprovedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); Guid reviewId = Guid.NewGuid(); var @event = new ProductReviewApprovedEvent(productId, reviewId); Assert.Equal(productId, @event.ProductId); Assert.Equal(reviewId, @event.ReviewId); Assert.Equal(productId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType); }
public async Task ApproveProductReview(Guid productId, Guid reviewId) { try { var product = await Repository.GetByKeyAsync <Product>(productId); product.ApproveReview(reviewId); await Repository.SaveChangesAsync(); var @event = new ProductReviewApprovedEvent(productId, reviewId); EventBus.RaiseEvent(@event); } catch { throw; } }