Exemple #1
0
        public async Task HandleEventAsync(GiftCardConsumedEto eventData)
        {
            if (!eventData.GiftCardTemplateName.StartsWith("Gift:"))
            {
                return;
            }

            var giftName = eventData.GiftCardTemplateExtraProperties.GetOrDefault("GiftName").As <string>();

            if (giftName.IsNullOrWhiteSpace())
            {
                throw new GiftCardGiftNameNotDefinedException(eventData.GiftCardTemplateName);
            }

            if (!eventData.ConsumptionUserId.HasValue)
            {
                throw new GiftCardConsumptionUserIdEmptyException(eventData.GiftCardCode);
            }

            var gift = await _giftRepository.GetAsync(giftName);

            await _userGiftRepository.InsertAsync(new UserGift(_guidGenerator.Create(),
                                                               eventData.ConsumptionUserId.Value, gift.Id));
        }
Exemple #2
0
 public async Task <GiftDto> GetByNameAsync(string name)
 {
     return(ObjectMapper.Map <Gift, GiftDto>(await _repository.GetAsync(name)));
 }