public void Inserir(EmailModel model) { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@EM_NOME", model.Nome), new SqlParameter("@EM_P_ID", model.IdPessoa), }; db.ExecuteNonQuery("proc_insereEmail", parms); }
public EmailModel Busca(int idEmail) { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@EM_ID", idEmail) }; DataTable dt = db.ExecuteReader<SqlDataReader>("proc_buscaEmailById", parms); EmailModel _em = new EmailModel(); foreach (DataRow dr in dt.Rows) { _em.Id = Convert.ToInt32(dr["EM_ID"]); _em.Nome = dr["EM_NOME"].ToString(); _em.IdPessoa = Convert.ToInt32(dr["EM_P_ID"]); break; } return _em; }
public List<EmailModel> Lista(int idPessoa) { List<EmailModel> lista = new List<EmailModel>(); SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@EM_P_ID", idPessoa) }; DataTable dt = db.ExecuteReader<SqlDataReader>("proc_buscaEmail", parms); EmailModel _em; foreach (DataRow dr in dt.Rows) { _em = new EmailModel(); _em.Id = Convert.ToInt32(dr["EM_ID"]); _em.Nome = dr["EM_NOME"].ToString(); _em.IdPessoa = Convert.ToInt32(dr["EM_P_ID"]); lista.Add(_em); } return lista; }
public void SendSimpleEmail(EmailModel model) { var aboutUs = _aboutUsService.GetAboutUsInfo(); using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(aboutUs?.Email); foreach (var item in model.EmailAddress) { mail.To.Add(item); } mail.BodyEncoding = Encoding.GetEncoding("utf-8"); mail.Subject = model.Subject; using (var reader = File.OpenText(HttpContext.Current.Server.MapPath("~/Templates/Simple.html"))) { var body = reader.ReadToEnd(); body = body.Replace("{{Text}}", model.Body) .Replace("{{Email}}", aboutUs?.Email) .Replace("{{Year}}", DateTime.Now.Year.ToString()) .Replace("{{DateTime}}", PersianDateTime.Now.ToString(PersianDateTimeFormat.FullDate)) .Replace("{{Telephone}}", aboutUs?.Telphone) .Replace("{{Address}}", aboutUs?.Address) .Replace("{{GooglePlus}}", aboutUs?.GooglePlus) .Replace("{{Facebook}}", aboutUs?.Facebook) .Replace("{{LinkedIn}}", aboutUs?.LinkedIn) .Replace("{{Twitter}}", aboutUs?.Twitter) .Replace("{{Telegram}}", aboutUs?.Telegram); AlternateView plainView = AlternateView.CreateAlternateViewFromString(Regex.Replace(body, @"<(.|\n)*?>", string.Empty), null, "text/plain"); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html"); mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView); mail.Body = body; } mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(aboutUs.Email, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } } }
public ActionResult InserirEmail(string email, int IdPF) { Email _dataEmail = new Email(); EmailModel emailModel = new EmailModel() { Nome = email, IdPessoa = IdPF }; if (emailModel.IsEmailValido()) { _dataEmail.Inserir(emailModel); return PartialView("_Email", _dataEmail.Lista(IdPF)); } else throw new Exception("Erro;"); }
public ActionResult InserirEmailSession(string email) { Email _dataEmail = new Email(); EmailModel emailModel = new EmailModel() { Nome = email }; if (emailModel.IsEmailValido()) { List<EmailModel> listaEmail = new List<EmailModel>(); if (Session["EmailPF"] != null) listaEmail = (List<EmailModel>)Session["EmailPF"]; int id = listaEmail.Count == 0 ? 1 : listaEmail.Last().Id + 1; emailModel.Id = id; listaEmail.Add(emailModel); Session["EmailPF"] = listaEmail; return PartialView("_Email", listaEmail); } else throw new Exception("Erro;"); }