예제 #1
0
        protected async Task SendEmailAsync(Notification notification)
        {
            var locale        = notification.User.LocaleOrDefault();
            var fullBodyId    = "notifications.body." + notification.MessageId;
            var fullSubjectId = "notifications.subject." + notification.MessageId;
            var subsDict      = notification.MessageSubstitutions as Dictionary <string, object>;
            var subject       = await Translator.TranslateAsync(locale, "notifications", fullSubjectId, subsDict);

            var body = await Translator.TranslateAsync(locale, "notifications", fullBodyId, subsDict);

            notification.DateEmailSent = DateTime.UtcNow;
            await NotificationRepository.UpdateAsync(notification);

            var email = new Email
            {
                To              = notification.User.Email,
                Subject         = subject,
                ContentTemplate = "Notification.txt",
                ContentModel    = new
                {
                    Message = body
                }
            };
            var result = await EmailRepository.CreateAsync(email);
        }
예제 #2
0
        public async Task EmailManipulationWorks()
        {
            _contact.Emails = new[]
            {
                new EmailViewModel
                {
                    Category = EmailCategory.Personal,
                    Value    = "*****@*****.**"
                }
            };
            var data = await ContactService.CreateAsync(_contact);

            Assert.NotEqual(Guid.Empty, data.Id);

            var contactId = data.Id;
            var email     = new Email
            {
                Value     = "*****@*****.**",
                Category  = EmailCategory.Personal,
                IsPrimary = false
            };
            var emailSaved = await EmailRepository.CreateAsync(contactId, email);

            var wtEmail = await ContactService.GetByIdAsync(data.Id);

            Assert.Equal(2, wtEmail.Emails.Length);
            emailSaved.Value = "*****@*****.**";
            var emailUpdated = await EmailRepository.UpdateAsync(contactId, emailSaved);

            var wtEmail2 = await ContactService.GetByIdAsync(data.Id);

            Assert.Contains(wtEmail2.Emails, it => it.Value == emailSaved.Value);
            await EmailRepository.DeleteAsync(contactId, emailUpdated.Id);

            var afterDelete = await ContactService.GetByIdAsync(data.Id);

            Assert.Single(afterDelete.Emails);
        }
예제 #3
0
        protected async Task SendEmailAsync(Notification notification)
        {
            var locale  = notification.User.LocaleOrDefault;
            var subject = await Translator.TranslateAsync(locale, "notifications", "notifications.subject", null);

            var subsDict = notification.MessageSubstitutions as Dictionary <string, object>;
            var message  = await Translator.TranslateAsync(locale, "notifications", notification.MessageId, subsDict);

            notification.DateEmailSent = DateTime.UtcNow;
            await NotificationRepository.UpdateAsync(notification);

            var email = new Email
            {
                To              = notification.User.Email,
                Subject         = subject,
                ContentTemplate = "Notification",
                ContentModel    = new
                {
                    Message = message
                }
            };
            var result = EmailRepository.CreateAsync(email).Result;
        }