public SelectList GetUser()
        {
            ConsultationView             con      = new ConsultationView();
            IEnumerable <SelectListItem> userlist =
                (from m in pb.GetPatients() where m.PatientId != 0 select m).AsEnumerable()
                .Select(m => new SelectListItem()
            {
                Text = m.FullName + " " + m.Surname, Value = m.PatientId.ToString()
            });

            return(new SelectList(userlist, "Value", "Text"));//,con.UserId);
        }
예제 #2
0
        public void createemail(Email_serviceViewModel emails)//, HttpPostedFileBase fileUploader)
        {
            PatientBusiness dbl = new PatientBusiness();

            using (var emailrepo = new EmailRepository())
            {
                List <MailAddress> l    = new List <MailAddress>();
                MailMessage        mail = new MailMessage();


                if (emails.To == null)
                {
                    foreach (Patient f in dbl.GetPatients())//for each friend
                    {
                        //get the email address and convert to MailAddress
                        l.Add(new MailAddress(f.Email));//add to the list of receivers
                    }

                    to = l;

                    foreach (MailAddress ma in to) //get each MailAddress in the list
                    {
                        mail.To.Add(ma);           //use to set the to list
                        Email_services _email = new Email_services
                        {
                            emailID   = emails.emailID,
                            To        = ma.ToString(),
                            Cc        = emails.Cc,
                            Bcc       = emails.Bcc,
                            Subject   = emails.Subject,
                            StaffName = emails.StaffName,
                            Body      = emails.Body
                        };

                        emailrepo.Create(_email);
                    }



                    //mail.To.Add(l);
                }

                else
                {
                    string[] ToMuliId = emails.To.Split(',');
                    foreach (string ToEMailId in ToMuliId)
                    {
                        mail.To.Add(new MailAddress(ToEMailId)); //adding multiple TO Email Id
                    }
                }

                /*mail.To.Add(emails.To);*/

                mail.From = new MailAddress("*****@*****.**");
                if (!string.IsNullOrEmpty(emails.Cc))
                {
                    string[] CCId = emails.Cc.Split(',');
                    foreach (string CCEmail in CCId)
                    {
                        mail.CC.Add(new MailAddress(CCEmail)); //Adding Multiple CC email Id
                    }
                }
                if (!string.IsNullOrEmpty(emails.Bcc))
                {
                    string[] bccid = emails.Bcc.Split(',');
                    foreach (string bccEmailId in bccid)
                    {
                        mail.Bcc.Add(new MailAddress(bccEmailId)); //Adding Multiple BCC email Id
                    }
                }
                #region

                /* if (emails.Cc == null)
                 * {
                 *  mail.CC.Add("*****@*****.**");
                 * }
                 * else
                 * {
                 *  string[] CCId = emails.Cc.Split(',');
                 *  foreach (string CCEmail in CCId)
                 *  {
                 *
                 *      mail.CC.Add(new MailAddress(CCEmail)); //Adding Multiple CC email Id
                 *  }
                 * }*/

                /*  if (emails.Bcc == null)
                 * {
                 *    mail.Bcc.Add("*****@*****.**");
                 * }
                 * else
                 * {
                 *    string[] bccid = emails.Bcc.Split(',');
                 *    foreach (string bccEmailId in bccid)
                 *    {
                 *
                 *          mail.Bcc.Add(new MailAddress(bccEmailId)); //Adding Multiple BCC email Id
                 *    }
                 *
                 * }
                 */
                #endregion
                #region
                //else
                //{
                //    mail.CC.Add(emails.Cc);
                //}
                //if (emails.Bcc == null)
                //{
                //    mail.Bcc.Add("*****@*****.**");
                //}
                //else
                //{
                //    mail.Bcc.Add(emails.Bcc);
                //}
                #endregion

                if (!string.IsNullOrEmpty(emails.Subject))
                {
                    mail.Subject = emails.Subject;
                }

                /* if (emails.Subject == null)
                 * {
                 *   mail.Subject = "No subject";
                 * }
                 * else
                 * {
                 *   mail.Subject = emails.Subject;
                 * }
                 */
                string Body = emails.Body;
                mail.Body = Body;

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                #region configurations is in the web.config

                /* smtp.Host = "localhost";//"smtp.live.com";
                 * //smtp.Host = "smtp.live.com";
                 *
                 * smtp.Port = 25; //587;
                 * // smtp.Port=587;
                 */
                #endregion


                smtp.Host = "smtp.sendgrid.net";
                smtp.Port = 2525;
                smtp.UseDefaultCredentials = false;
                smtp.EnableSsl             = true;
                smtp.Credentials           = new System.Net.NetworkCredential("bigiayomide", "123adenike");// enter seders user name and password



                smtp.Send(mail);

                if (emails.emailID == 0)
                {
                    Email_services _email = new Email_services
                    {
                        emailID   = emails.emailID,
                        To        = emails.To,
                        Cc        = emails.Cc,
                        Bcc       = emails.Bcc,
                        Subject   = emails.Subject,
                        StaffName = emails.StaffName,
                        Body      = emails.Body
                    };

                    emailrepo.Create(_email);
                }
            }
        }