public virtual async Task ConsumeAsync(GiftCard giftCard, Guid?userId, ExtraPropertyDictionary extraProperties = null)
        {
            var template = await _giftCardTemplateRepository.GetAsync(giftCard.GiftCardTemplateId);

            giftCard.Consume(_clock, userId, extraProperties);

            await _repository.UpdateAsync(giftCard, true);

            _unitOfWorkManager.Current.OnCompleted(async() => await _distributedEventBus.PublishAsync(
                                                       new GiftCardConsumedEto
            {
                GiftCardTemplateName            = template.Name,
                GiftCardTemplateExtraProperties = template.ExtraProperties,
                GiftCardCode            = giftCard.Code,
                GiftCardExtraProperties = giftCard.ExtraProperties,
                ConsumptionUserId       = userId
            }));
        }
示例#2
0
        public virtual async Task ConsumeAsync(ConsumeGiftCardDto input)
        {
            var giftCard = await _giftCardManager.GetUsableAsync(input.Code, input.Password);

            var template = await _giftCardTemplateRepository.GetAsync(giftCard.GiftCardTemplateId);

            if (CurrentTenant.Id.HasValue && !template.TenantAllowed)
            {
                throw new GiftCardTemplateTenantNotAllowedException(template.Id);
            }

            if (!template.AnonymousConsumptionAllowed)
            {
                await AuthorizationService.CheckAsync(GiftCardManagementPermissions.GiftCards.Consume);
            }

            await _giftCardManager.ConsumeAsync(giftCard, CurrentUser.Id, input.ExtraProperties);
        }