Beispiel #1
0
 public Guid Salvar(AnexoModel anexo)
 {
     using (var db = new MainContextFactory().CreateDbContext(null))
     {
         db.Anexos.Add(anexo);
         db.SaveChanges();
         return(anexo.Id);
     }
 }
Beispiel #2
0
        public EmailModel LoadData(EmailModel email)
        {
            #region ler-credenciais

            string _lineCred = "";

            StreamReader fileCred = new StreamReader("_root.txt");

            try{
                while ((_lineCred = fileCred.ReadLine()) != null)
                {
                    var _tempCred = _lineCred.Split(';');

                    if (_tempCred.Length != 5)
                    {
                        throw new Exception("Erro ao ler credenciais de root: Parametros inválidos (" + _lineCred.Count() + ")");
                    }

                    /* + Layout
                     *      + Email de credencial
                     *      + Password
                     *      + HostName de origem
                     *      + Email de envio
                     *      + Nome de origem
                     */

                    email.Credenciais.EmailEnvio = _tempCred[0].ToString();
                    email.Credenciais.Password   = _tempCred[1].ToString();
                    email.HostName                  = _tempCred[2].ToString();
                    email.Remetente.Email           = _tempCred[3].ToString();
                    email.Remetente.DsNomeRemetente = _tempCred[4].ToString();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler credenciais de root: " + ex.Message);
            }

            fileCred.Close();

            #endregion ler-credenciais

            #region ler-destinatarios

            int    _countDest = 0;
            string _lineDest  = "";

            StreamReader fileDest = new StreamReader("_EmailDest.txt");
            try
            {
                while ((_lineDest = fileDest.ReadLine()) != null)
                {
                    Destinatarios dest = new Destinatarios();

                    _countDest++;

                    dest.Email   = _lineDest.ToString();
                    dest.IdEmail = _countDest;

                    email.Destinatarios.Add(dest);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler arquivo: " + "(_EmailDest.txt)" + ex.Message);
            }

            fileDest.Close();

            #endregion ler-destinatarios

            #region ler_destinatarios-copia

            int    _countDestCopy = 0;
            string _lineDestCopy  = "";

            StreamReader fileDestCopy = new StreamReader("_EmailDestCopy.txt");

            try
            {
                while ((_lineDestCopy = fileDestCopy.ReadLine()) != null)
                {
                    Destinatarios destCopy = new Destinatarios();

                    _countDestCopy++;

                    destCopy.Email   = _lineDestCopy.ToString();
                    destCopy.IdEmail = _countDestCopy;

                    email.DestinatariosCopia.Add(destCopy);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler arquivo: (_EmailDestCopy.txt)" + ex.Message);
            }

            fileDestCopy.Close();

            #endregion ler_destinatarios-copia

            #region ler-titulo-body

            string _lineTitleBody = "";
            int    _aux           = 0;

            StreamReader fileTitleBody = new StreamReader("_TitleBody.txt");

            try
            {
                while ((_lineTitleBody = fileTitleBody.ReadLine()) != null)
                {
                    if (_aux == 0)
                    {
                        _aux         = 1;
                        email.Titulo = _lineTitleBody.ToString();
                    }
                    else
                    {
                        email.BodyMail.Add(_lineTitleBody.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler arquivo: (_TitleBody.txt) " + ex.Message);
            }

            #endregion ler-titulo-body

            #region ler-anexos

            int    _countAnexo = 0;
            string _lineAnexo  = "";

            StreamReader fileAnexo = new StreamReader("_anexo.txt");

            try
            {
                while ((_lineAnexo = fileAnexo.ReadLine()) != null)
                {
                    AnexoModel tempAnexo = new AnexoModel();

                    _countAnexo++;

                    tempAnexo.CaminhoAnexo = _lineAnexo.ToString();
                    tempAnexo.ContAnexo    = _countAnexo;

                    email.Anexo.Add(tempAnexo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler arquivo: (_anexo.txt) " + ex.Message);
            }
            fileAnexo.Close();

            #endregion ler-anexos

            return(email);
        }