Ejemplo n.º 1
0
        public IActionResult WelcomeEmail()
        {
            var data = TempData.Peek <DelegateRegistrationByCentreData>() !;

            var model = new WelcomeEmailViewModel(data);

            return(View(model));
        }
Ejemplo n.º 2
0
        public void Should_properly_format_an_email_using_the_view_engine()
        {
            var controller = new EmailController();

            var viewModel = new WelcomeEmailViewModel();

            controller.GenerateEmail(viewModel);
        }
 public void SetWelcomeEmail(WelcomeEmailViewModel model)
 {
     if (model.ShouldSendEmail)
     {
         WelcomeEmailDate = new DateTime(model.Year !.Value, model.Month !.Value, model.Day !.Value);
         PasswordHash     = null;
     }
     else
     {
         WelcomeEmailDate = null;
     }
 }
        public void SetWelcomeEmail_with_ShouldSendEmail_false_sets_data_correctly()
        {
            // Given
            var model = new WelcomeEmailViewModel {
                ShouldSendEmail = false, Day = 7, Month = 7, Year = 2200
            };
            var data = new DelegateRegistrationByCentreData();

            // When
            data.SetWelcomeEmail(model);

            // Then
            data.ShouldSendEmail.Should().BeFalse();
            data.WelcomeEmailDate.Should().BeNull();
        }
Ejemplo n.º 5
0
        public IActionResult WelcomeEmail(WelcomeEmailViewModel model)
        {
            var data = TempData.Peek <DelegateRegistrationByCentreData>() !;

            model.ClearDateIfNotSendEmail();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            data.SetWelcomeEmail(model);
            TempData.Set(data);

            return(RedirectToAction(data.ShouldSendEmail ? "Summary" : "Password"));
        }
Ejemplo n.º 6
0
        public void WelcomeEmailPost_with_ShouldSendEmail_false_updates_tempdata_correctly()
        {
            // Given
            controller.TempData.Set(new DelegateRegistrationByCentreData());
            var model = new WelcomeEmailViewModel {
                ShouldSendEmail = false, Day = 7, Month = 7, Year = 2200
            };

            // When
            controller.WelcomeEmail(model);

            // Then
            var data = controller.TempData.Peek <DelegateRegistrationByCentreData>() !;

            data.ShouldSendEmail.Should().BeFalse();
            data.WelcomeEmailDate.Should().BeNull();
        }
        public void SetWelcomeEmail_with_ShouldSendEmail_true_sets_data_correctly()
        {
            // Given
            var date  = new DateTime(2200, 7, 7);
            var model = new WelcomeEmailViewModel
            {
                ShouldSendEmail = true, Day = date.Day, Month = date.Month, Year = date.Year
            };
            var data = new DelegateRegistrationByCentreData();

            // When
            data.SetWelcomeEmail(model);

            // Then
            data.ShouldSendEmail.Should().BeTrue();
            data.WelcomeEmailDate.Should().Be(date);
            data.IsPasswordSet.Should().BeFalse();
            data.PasswordHash.Should().BeNull();
        }
Ejemplo n.º 8
0
        public async Task <int> SendWelcomeEmail(WelcomeEmailViewModel viewModel, string receivers)
        {
            var emailContent = await _razorLightEngine.CompileRenderAsync(_appSettings.WelcomeEmailTemplate, viewModel);

            var emailLogs = new List <EmailLog>();

            if (_appSettings.Environment != "prod")
            {
                emailLogs.Add(new EmailLog
                {
                    ListingId   = 0,
                    FromAddress = _appSettings.DefaultEmailAddress,
                    ToAddress   = receivers,
                    Subject     = _appSettings.BookingEmailSubject,
                    Content     = emailContent,
                    CreatedDate = DateTime.Now,
                    Status      = true
                });
            }
            else
            {
                await ElasticEmailClient.Send(_appSettings.WelcomeEmailSubject, _appSettings.DefaultEmailAddress,
                                              _appSettings.DefaultEmailName,
                                              to : receivers, bodyHtml : emailContent)
                .ContinueWith(x => emailLogs.Add(new EmailLog
                {
                    ListingId     = 0,
                    FromAddress   = _appSettings.DefaultEmailAddress,
                    ToAddress     = receivers,
                    Subject       = _appSettings.BookingEmailSubject,
                    Content       = emailContent,
                    CreatedDate   = DateTime.Now,
                    MessageId     = x.Result.MessageID,
                    TransactionId = x.Result.TransactionID,
                    Status        = true
                }));
            }

            return(await _emailLogRepository.LogEmail(emailLogs));
        }
Ejemplo n.º 9
0
        public void WelcomeEmailPost_with_ShouldSendEmail_true_updates_tempdata_correctly()
        {
            // Given
            controller.TempData.Set(new DelegateRegistrationByCentreData {
                PasswordHash = "hash"
            });
            var date  = new DateTime(2200, 7, 7);
            var model = new WelcomeEmailViewModel
            {
                ShouldSendEmail = true, Day = date.Day, Month = date.Month, Year = date.Year
            };

            // When
            controller.WelcomeEmail(model);

            // Then
            var data = controller.TempData.Peek <DelegateRegistrationByCentreData>() !;

            data.ShouldSendEmail.Should().BeTrue();
            data.WelcomeEmailDate.Should().Be(date);
            data.IsPasswordSet.Should().BeFalse();
            data.PasswordHash.Should().BeNull();
        }