Ejemplo n.º 1
0
        public ActionResult Create(EmailTemplateEditModel model)
        {
            if (!ModelState.IsValid)
            {
                var templateMacros = _emailTemplateService.GetMacrosForNotificationTypeId(model.NotificationTypeId);

                model.TemplateMacros = templateMacros.Select(tm => tm.IdentifierName).OrderBy(t => t);
                return(View(model));
            }

            try
            {
                if (model.Id > 0)
                {
                    model = _emailTemplateService.Save(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                }
                else
                {
                    model = _emailTemplateService.SaveNewTemplate(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                }

                model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Template Created successfully!");
                ModelState.Clear();
            }
            catch (Exception ex)
            {
                var templateMacros = _emailTemplateService.GetMacrosForNotificationTypeId(model.NotificationTypeId);
                model.TemplateMacros = templateMacros.Select(tm => tm.IdentifierName).OrderBy(t => t);

                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage(string.Concat("System Failure! Message: ", ex.Message));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public EmailTemplateEditModel SaveNewTemplate(EmailTemplateEditModel model, long orgRoleUserId)
        {
            if (model.TemplateType == (long)TemplateType.Sms)
            {
                model.Body = ConvertToPlainText(model.Body).Trim();
            }

            var templateMacros = GetMacrosForNotificationTypeId(model.NotificationTypeId);
            var list           = new List <EmailTemplateMacro>();

            var emailTemplate = _emailTemplateEditModelFactory.Create(model, orgRoleUserId, templateMacros);

            emailTemplate = _emailTemplateRepository.Save(emailTemplate);
            var sequence = 1;

            templateMacros = templateMacros.OrderBy(x => x.Sequence);

            foreach (var templateMacro in templateMacros)
            {
                list.Add(new EmailTemplateMacro
                {
                    EmailTemplateId = (int)emailTemplate.Id,
                    TemplateMacroId = templateMacro.Id,
                    Sequence        = sequence++,
                    ParameterValue  = templateMacro.ParameterValue
                });
            }

            _emailTemplateMacroRepository.SaveEmailTemplateMacros(list);

            return(GetModel(emailTemplate.Id));
        }
Ejemplo n.º 3
0
 public EmailTemplate Edit(EmailTemplateEditModel model, EmailTemplate inDb, long modifiedByOrgRoleUserId)
 {
     inDb.Body    = ReplaceMacroswithCodeString(model.Body, model.Id);
     inDb.Subject = model.Subject;
     inDb.DataRecorderMetaData.DateModified         = DateTime.Now;
     inDb.DataRecorderMetaData.DataRecorderModifier = modifiedByOrgRoleUserId > 0 ? new OrganizationRoleUser(modifiedByOrgRoleUserId) : null;
     return(inDb);
 }
Ejemplo n.º 4
0
        public EmailTemplateEditModel Complete(EmailTemplateEditModel model)
        {
            var templateMacros = _templateMacroRepository.GetbyEmailTemplateId(model.Id);

            model.TemplateMacros = templateMacros.Select(tm => tm.IdentifierName).OrderBy(t => t);

            return(model);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Edit(int id)
        {
            var emailTemplate = await _GetEmailTemplate(id);

            var model = new EmailTemplateEditModel {
                EmailTemplate = emailTemplate
            };

            return(View(model));
        }
Ejemplo n.º 6
0
        public EmailTemplateEditModel CreateNewTemplate(long notificationTypeId)
        {
            var templateMacros = GetMacrosForNotificationTypeId(notificationTypeId);

            var model = new EmailTemplateEditModel
            {
                TemplateMacros     = templateMacros.Select(tm => tm.IdentifierName).OrderBy(t => t),
                TemplateType       = (long)TemplateType.Email,
                NotificationTypeId = notificationTypeId,
            };

            return(model);
        }
Ejemplo n.º 7
0
        public EmailTemplate Create(EmailTemplateEditModel model, long orgRoleUserId, IEnumerable <TemplateMacro> templateMacros)
        {
            var emailTemplate = new EmailTemplate
            {
                Body    = templateMacros.Aggregate(model.Body, (current, templateMacro) => current.Replace(templateMacro.IdentifierUiString, templateMacro.CodeString)),
                Subject = model.Subject,
                DataRecorderMetaData = new DataRecorderMetaData(new OrganizationRoleUser(orgRoleUserId), DateTime.Now, null),
                Alias              = model.Subject.Replace(" ", ""),
                TemplateType       = model.TemplateType,
                NotificationTypeId = model.NotificationTypeId,
                IsEditable         = true
            };

            return(emailTemplate);
        }
Ejemplo n.º 8
0
        public EmailTemplateEditModel Save(EmailTemplateEditModel model, long orgRoleUserId)
        {
            var inDb = _emailTemplateRepository.GetById(model.Id);

            if (model.TemplateType == (long)TemplateType.Sms)
            {
                model.Body = ConvertToPlainText(model.Body).Trim();
            }

            var emailTemplate = _emailTemplateEditModelFactory.Edit(model, inDb, orgRoleUserId);

            if (model.IsEditable)
            {
                _emailTemplateRepository.Save(emailTemplate);
            }
            return(GetModel(emailTemplate.Id));
        }
Ejemplo n.º 9
0
        public EmailTemplateEditModel Edit(EmailTemplate template)
        {
            var templateMacros = _templateMacroRepository.GetbyEmailTemplateId(template.Id);

            var model = new EmailTemplateEditModel
            {
                Id                 = template.Id,
                Alias              = template.Alias,
                Body               = ReplaceCodeStringwithMacros(template.Body, templateMacros),
                Subject            = template.Subject,
                TemplateMacros     = templateMacros.Select(tm => tm.IdentifierName).OrderBy(t => t),
                TemplateType       = template.TemplateType,
                NotificationTypeId = template.NotificationTypeId,
                IsEditable         = template.IsEditable
            };

            return(model);
        }
Ejemplo n.º 10
0
        public ActionResult Edit(EmailTemplateEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(_emailTemplateService.CompleteModel(model)));
            }

            try
            {
                model = _emailTemplateService.Save(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Template updated successfully!");
            }
            catch (Exception ex)
            {
                model = _emailTemplateService.CompleteModel(model);
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage(string.Concat("System Failure! Message: ", ex.Message));
            }

            return(View(model));
        }
Ejemplo n.º 11
0
 public EmailTemplateEditModel CompleteModel(EmailTemplateEditModel model)
 {
     return(_emailTemplateEditModelFactory.Complete(model));
 }