예제 #1
0
        public async Task <Unit> Handle(TossCreateCommand command, CancellationToken cancellationToken)
        {
            TossEntity toss;

            if (!command.SponsoredDisplayedCount.HasValue)
            {
                toss = new TossEntity(
                    command.Content,
                    _httpContextAccessor.HttpContext.User.Identity.Name,
                    DateTimeOffset.Now);
            }
            else
            {
                toss = new SponsoredTossEntity(
                    command.Content,
                    _httpContextAccessor.HttpContext.User.Identity.Name,
                    DateTimeOffset.Now,
                    command.SponsoredDisplayedCount.Value);
            }
            toss.Id = await _dbTemplate.Insert(toss);

            if (command.SponsoredDisplayedCount.HasValue)
            {
                ApplicationUser applicationUser = (await userManager.GetUserAsync(_httpContextAccessor.HttpContext.User));
                var             paymentResult   = await stripeClient.Charge(command.StripeChargeToken, command.SponsoredDisplayedCount.Value *TossCreateCommand.CtsCostPerDisplay, "Payment for sponsored Toss #" + toss.Id, applicationUser.Email);

                if (!paymentResult)
                {
                    await _dbTemplate.Delete(toss.Id);
                }
            }
            return(Unit.Value);
        }
예제 #2
0
        public async Task <Unit> Handle(TossCreateCommand command, CancellationToken cancellationToken)
        {
            TossEntity toss;
            var        user = _httpContextAccessor.HttpContext.User;

            if (!command.SponsoredDisplayedCount.HasValue)
            {
                toss = new TossEntity(
                    command.Content,
                    user.UserId(),
                    DateTimeOffset.Now);
            }
            else
            {
                toss = new SponsoredTossEntity(
                    command.Content,
                    user.UserId(),
                    DateTimeOffset.Now,
                    command.SponsoredDisplayedCount.Value);
            }
            toss.UserName = user.Identity.Name;
            toss.Id       = await _dbTemplate.Insert(toss);

            if (command.SponsoredDisplayedCount.HasValue)
            {
                ApplicationUser applicationUser = (await userManager.GetUserAsync(user));
                var             paymentResult   = await stripeClient.Charge(command.StripeChargeToken, command.SponsoredDisplayedCount.Value *TossCreateCommand.CtsCostPerDisplay, "Payment for sponsored Toss #" + toss.Id, applicationUser.Email);

                if (!paymentResult)
                {
                    await _dbTemplate.Delete(toss.Id);

                    throw new InvalidOperationException("Payment error on sponsored Toss ");
                }
            }
            await mediator.Publish(new TossCreated(toss.Id));

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteTossCommand request, CancellationToken cancellationToken)
        {
            await cosmosDBTemplate.Delete(request.TossId);

            return(Unit.Value);
        }