Ejemplo n.º 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);
        }
Ejemplo n.º 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(),
                    now.Get());
            }
            else
            {
                toss = new SponsoredTossEntity(
                    command.Content,
                    user.UserId(),
                    now.Get(),
                    command.SponsoredDisplayedCount.Value);
            }
            toss.UserName = user.Identity.Name;
            var matchCollection = TossCreateCommand.TagRegex.Matches(toss.Content);

            toss.Tags   = matchCollection.Select(m => m.Groups[1].Value).ToList();
            toss.UserIp = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            await _session.StoreAsync(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)
                {
                    _session.Delete(toss.Id);
                    throw new InvalidOperationException("Payment error on sponsored Toss ");
                }
            }
            await mediator.Publish(new TossCreated(toss));

            return(Unit.Value);
        }
Ejemplo n.º 3
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);
        }