예제 #1
0
        public async Task <SaveResult> GenerateRegistrationNotificationEmail(
            MemberStagingViewModel model,
            string messageTemplateDiscr)
        {
            SaveResult saveResult = new SaveResult();

            var mailTemplate = await _messageTemplateBL.GetEntityByName(messageTemplateDiscr);

            string messageBody = model.IsFinalised ? model.Comments : string.Empty;

            List <QueuedEmail> msqList = new List <QueuedEmail>();


            if (model.NotificationRoles != null && MessageTemplateConst.RegistrationNotification.Equals(messageTemplateDiscr))
            {
                foreach (var recipient in model.NotificationRoles)
                {
                    BuildEmailQueue(mailTemplate,
                                    messageBody,
                                    msqList,
                                    recipient.Email,
                                    recipient.FullName,
                                    model.RequestUrl,
                                    model.SessionUserId);
                }
            }
            else
            {
                BuildEmailQueue(mailTemplate,
                                model.Comments,
                                msqList,
                                model.Email,
                                model.FullName,
                                model.RequestUrl,
                                model.SessionUserId);
            }

            if (msqList.Any())
            {
                try
                {
                    _context.QueuedEmail.AddRange(msqList);
                    _context.SaveChanges();
                    saveResult.IsSuccess = true;
                }
                catch (DbUpdateException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                saveResult.IsSuccess = true;
            }
            return(saveResult);
        }
예제 #2
0
        public async Task <IEnumerable <UserViewModel> > GetMessageTemplateNotificationUser()
        {
            var messageTemplate = await _messageTemplateBL.GetEntityByName(MessageTemplateConst.RegistrationNotification);

            List <ApplicationUser> notificationRoles = new List <ApplicationUser>();

            if (messageTemplate.ApplicationRoleMessageTemplates.Any())
            {
                foreach (var item in messageTemplate.ApplicationRoleMessageTemplates)
                {
                    notificationRoles.AddRange(await GetUserFromRoleAsync(item.ApplicationRole.Name));
                }
            }

            return(notificationRoles.Select(a => new UserViewModel
            {
                Id = a.Id,
                Email = a.Email,
                FirstName = a.FirstName,
                Surname = a.Surname,
                FullName = a.FullName
            }).GroupBy(a => new { a.Id, a.Email, a.FirstName, a.Surname, a.FullName })
                   .Select(a => new UserViewModel
            {
                Id = a.Key.Id,
                Email = a.Key.Email,
                FirstName = a.Key.FirstName,
                Surname = a.Key.Surname,
                FullName = a.Key.FullName
            }));
        }