Example #1
0
        public bool MakeToSendEmail(string key, BusinessValue value, BusinessController bc)
        {
            bool result = false;
            string template = string.Empty;

            try
            {
                if ((email.destinatarios.Count > 0) && (!string.IsNullOrEmpty(key)))
                {
                    informacoes.Clear();
                    OnLoadInformation(value);

                    if (controller.Template.TryGetValue(key, out template))
                    {
                        List<string> listKeys = informacoes.Keys.ToList();
                        for (int i = 0; i < listKeys.Count; i++)
                        {
                            if (template.Contains(listKeys[i]))
                            {
                                template = template.Replace(listKeys[i], informacoes[listKeys[i]]);
                            }
                        }

                        email.assunto = informacoes[ASSUNTO_KEY];
                        email.conteudo = template;

                        SendEmail();

                        if (bc.GetType().GetInterface(typeof(IBuildPdfEmail).Name) != null)
                        {
                            foreach (var destinatario in email.destinatarios)
                            {
                                ((IBuildPdfEmail)bc).montaPdfEmail(value, destinatario, new StreamReader(SalusUtility.BagInfo().Context.Server.MapPath(templates[key])), email.assunto, template);    
                            }
                        }
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                SalusUtility.BagInfo().MessageManager.AddMessageError(e.Message);
                result = false;
            }
            finally 
            {
                
                clearEmail();
            }

            return result;
        }