public ActionResult AtaskaituSiuntimas() { AtaskaituSiuntimasViewModel siunt = new AtaskaituSiuntimasViewModel(); PopulateSelections2(siunt); return(View(siunt)); }
public void PopulateSelections2(AtaskaituSiuntimasViewModel siunt) { List <SelectListItem> selectListAtaskTipas = new List <SelectListItem>(); List <SelectListItem> selectListEmail = new List <SelectListItem>(); var email = repository.getEmail(); selectListAtaskTipas.Add(new SelectListItem() { Value = Convert.ToString(1), Text = "Neaktyvūs vartotojai (6 mėnesiai)", Selected = true }); selectListAtaskTipas.Add(new SelectListItem() { Value = Convert.ToString(2), Text = "Knygų užsakymai(1 mėnuo)" }); foreach (var em in email) { selectListEmail.Add(new SelectListItem() { Value = Convert.ToString(em), Text = em.ToString() }); } siunt.AtaskaitosList = selectListAtaskTipas; siunt.EmailList = selectListEmail; }
public ActionResult AtaskaituSiuntimas(AtaskaituSiuntimasViewModel _objModelMail) { AtaskaituSiuntimasViewModel siunt = new AtaskaituSiuntimasViewModel(); siunt.ataskaitos_tipas = _objModelMail.ataskaitos_tipas == null ? null : _objModelMail.ataskaitos_tipas; siunt.to = _objModelMail.to == null ? null : _objModelMail.to; PopulateSelections2(siunt); string text = ""; string sub = ""; if (siunt.ataskaitos_tipas == 1) { text = repository.getAtaskaitos(); sub = "Neprisijungę vartotojai per 6 mėnesius"; } else if (siunt.ataskaitos_tipas == 2) { text = repository.getAtaskaitos2(); sub = "Knygų užsakymai (1 mėnesio)"; } if (ModelState.IsValid & siunt.to != null) { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(siunt.to); mail.Subject = sub; mail.Body += text; mail.IsBodyHtml = true; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Visaigeras5"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); ViewBag.Message = "Ataskaita išsiųsta!"; } else { return(View()); } return(View(siunt)); }