示例#1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                NewsLetter objNl = new NewsLetter();
                NewsLetterRepository objnlRepo = new NewsLetterRepository();
                foreach (ListItem listItem in chkUser.Items)
                {
                    if (listItem.Selected)
                    {
                           objNl.Id = Guid.NewGuid();
                            objNl.Subject = txtSubject.Text;
                            objNl.NewsLetterDetail = Editor.Text;
                            objNl.SendDate = DateTime.Parse(txtSendDate.Text);
                            objNl.SendStatus = false;
                            objNl.UserId = Guid.Parse(listItem.Value);
                            if (!objnlRepo.checkNewsLetterExists(Editor.Text))
                                objnlRepo.AddNewsLetter(objNl);
                            else
                                objnlRepo.UpdateNewsLetter(objNl);
                    }
                }

            }
            catch (Exception Err)
            {
                logger.Error(Err.Message);
                Response.Write(Err.StackTrace);
            }
        }
        //protected void btnSave_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        NewsLetter objNl = new NewsLetter();
        //        NewsLetterRepository objnlRepo = new NewsLetterRepository();
        //        foreach (ListItem listItem in chkUser.Items)
        //        {
        //            if (listItem.Selected)
        //            {
        //                objNl.Id = Guid.NewGuid();
        //                objNl.Subject = txtSubject.Text;
        //                objNl.NewsLetterDetail = Editor.Text;
        //               // objNl.SendDate = DateTime.Parse(txtSendDate.Text);
        //                objNl.SendStatus = false;
        //                objNl.UserId = Guid.Parse(listItem.Value);
        //                if (!objnlRepo.checkNewsLetterExists(Editor.Text))
        //                    objnlRepo.AddNewsLetter(objNl);
        //                else
        //                    objnlRepo.UpdateNewsLetter(objNl);
        //            }
        //        }

        //    }
        //    catch (Exception Err)
        //    {
        //        logger.Error(Err.Message);
        //        Response.Write(Err.StackTrace);
        //    }
        //}

        protected void sendmail_Click(object sender, EventArgs e)
        {
            string username = ConfigurationManager.AppSettings["username"];
            string host = ConfigurationManager.AppSettings["host"];
            string port = ConfigurationManager.AppSettings["port"];
            string pass = ConfigurationManager.AppSettings["password"];
            string from = ConfigurationManager.AppSettings["fromemail"];
            int noofuserselected = 0;

            foreach (ListItem listItem in chkUser.Items)
            {
                if (listItem.Selected == true)
                {
                    noofuserselected++;
                }
            }



            if (txtSubject.Text == "" || Editor.Text == "" || noofuserselected == 0)
            {
                if (noofuserselected == 0)
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill subject/Email or select users!');", true);
                    return;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill subject/Email content!');", true);
                    return;
                }
            }

            try
            {
                NewsLetter objNl = new NewsLetter();
                User objUser = new User();
                UserRepository objUserRepository = new UserRepository();
                NewsLetterRepository objnlRepo = new NewsLetterRepository();
                foreach (ListItem listItem in chkUser.Items)
                {
                    if (listItem.Selected)
                    {


                        objUser = objUserRepository.getUsersById(Guid.Parse(listItem.Value));
                        if (objUser != null)
                        {
                            MailHelper.SendSendGridMail(host, Convert.ToInt32(port), from, "", objUser.EmailId.ToString(), string.Empty, string.Empty, txtSubject.Text, Editor.Text, username, pass);


                            objNl.Id = Guid.NewGuid();
                            objNl.Subject = txtSubject.Text;
                            objNl.NewsLetterBody = Editor.Text;
                            objNl.SendDate = DateTime.Parse(txtSendDate.Text);
                            objNl.SendStatus = false;
                            objNl.UserId = Guid.Parse(listItem.Value);
                            objNl.EntryDate = DateTime.Now;
                            //if (!objnlRepo.checkNewsLetterExists(Editor.Text))
                            //    objnlRepo.AddNewsLetter(objNl);
                            //else
                                //objnlRepo.UpdateNewsLetter(objNl);
                            objnlRepo.AddNewsLetter(objNl);
                        }
                    }
                }
                txtSubject.Text = "";
                Editor.Text = "";
                clearAll();
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('News Letter has been Added!');", true);

            }
            catch (Exception Err)
            {
                txtSubject.Text = "";
                Editor.Text = "";
                clearAll();
                logger.Error(Err.Message);
                Console.Write(Err.StackTrace);
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert(" + Err.Message + "'!');", true);

            }
        }