Exemplo n.º 1
0
        public async Task <Unit> Handle(SendRegistrationEmailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var startPoint = checkPointRepository.Get().OrderBy(x => x.Distance).FirstOrDefault();

                var emailModel = new RegistrationEmailModel
                {
                    LogoUrl = absoluteUrlHelper.Get("/images/AllInSkateChallengeBannerSmall.png"),
                    EmailConfirmationUrl = request.EmailConfirmationUrl,
                    SiteUrl             = absoluteUrlHelper.Get("/"),
                    LogMilesUrl         = absoluteUrlHelper.Get("/skater/skate-log"),
                    SponsorLogoUrl      = absoluteUrlHelper.Get("/images/SkateEverywhereLogo.png"),
                    StartingPostCard    = absoluteUrlHelper.Get(startPoint?.Image),
                    FromSkateEverywhere = request.FromSkateEverywhere
                };

                var emailBody = await viewToStringRenderer.RenderPartialToStringAsync("~/Views/Email/RegistrationEmail.cshtml", emailModel);

                await emailSender.SendEmailAsync(request.Email, "ALL IN Skate Challenge Registration", emailBody);
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Failed to progress updates when saving mileage entries", request);
            }

            return(Unit.Value);
        }
        public async Task <Unit> Handle(ResendRegistrationEmailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var user = await userManager.FindByIdAsync(request.UserId);

                if (user == null)
                {
                    throw new EntityNotFoundException(typeof(ApplicationUser), Guid.Parse(request.UserId));
                }

                var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                var callbackUrl = $"/Identity/Account/ConfirmEmail/?userId={request.UserId}&code={code}&returnUrl=%2F";
                callbackUrl = absoluteUrlHelper.Get(callbackUrl);

                var startPoint = checkPointRepository.Get().OrderBy(x => x.Distance).FirstOrDefault();

                var emailModel = new RegistrationEmailModel
                {
                    LogoUrl = absoluteUrlHelper.Get("/images/AllInSkateChallengeBannerSmall.png"),
                    EmailConfirmationUrl = callbackUrl,
                    SiteUrl             = absoluteUrlHelper.Get("/"),
                    LogMilesUrl         = absoluteUrlHelper.Get("/skater/skate-log"),
                    SponsorLogoUrl      = absoluteUrlHelper.Get("/images/SkateEverywhereLogo.png"),
                    StartingPostCard    = absoluteUrlHelper.Get(startPoint?.Image),
                    FromSkateEverywhere = false
                };

                var emailBody = await viewToStringRenderer.RenderPartialToStringAsync("~/Views/Email/RegistrationEmail.cshtml", emailModel);

                await emailSender.SendEmailAsync(user.Email, "ALL IN Skate Challenge Registration", emailBody);
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Failed to progress updates when saving mileage entries", request);
            }

            return(Unit.Value);
        }