示例#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);
            }
        }
        /// <UpdateNewsLetter>
        /// Update News Letter
        /// </summary>
        /// <param name="nl">Set Values in a NewsLetter Class Property and Pass the Object of NewsLetter Class.(Domein.NewsLetter)</param>
        public void UpdateNewsLetter(NewsLetter nl)
        {
            //Creates a database connection and opens up a session
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction. 
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        //Proceed action, to update existing news.
                        session.CreateQuery("Update NewsLetter set NewsLetterBody =:NewsLetterBody,UserId=:UserId,SendDate=:SendDate,SendStatus=:SendStatus where Id = :adsid")
                            .SetParameter("NewsLetterBody", nl.NewsLetterBody)
                            .SetParameter("UserId", nl.UserId)
                            .SetParameter("SendDate", nl.SendDate)
                            .SetParameter("SendStatus", nl.SendStatus)
                              .SetParameter("adsid", nl.Id)
                            .ExecuteUpdate();
                        transaction.Commit();


                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        // return 0;
                    }
                }//End Transaction
            }//End Session
        }
 public void AddNewsLetter(NewsLetter nl)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             session.Save(nl);
             transaction.Commit();
         }
     }
 }
 /// <AddNewsLetter>
 /// Add News Letter
 /// </AddNewsLetter>
 /// <param name="nl">Set Values in a NewsLetter Class Property and Pass the Object of NewsLetter Class.(Domein.NewsLetter)</param>
 public void AddNewsLetter(NewsLetter nl)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction. 
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action, to save data.
             session.Save(nl);
             transaction.Commit();
         }//End Transaction
     }//End Session
 }
示例#5
0
 public void clearAll()
 {
     try
     {
         NewsLetter objNl = new NewsLetter();
         NewsLetterRepository objnlRepo = new NewsLetterRepository();
         foreach (ListItem listItem in chkUser.Items)
         {
             listItem.Selected = false;
         }
     }
     catch (Exception Err)
     {
         logger.Error(Err.Message);
         Response.Write(Err.StackTrace);
     }
 }
示例#6
0
        protected void all_Click(object sender, EventArgs e)
        {
            try
            {
                NewsLetter objNl = new NewsLetter();
                NewsLetterRepository objnlRepo = new NewsLetterRepository();
                foreach (ListItem listItem in chkUser.Items)
                {
                    listItem.Selected = true;

                }

            }
            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);

            }
        }
        protected void paid_Click(object sender, EventArgs e)
        {
            clearAll();
            try
            {
                NewsLetter objNl = new NewsLetter();
                User objUser = new User();
                UserRepository objUserRepository = new UserRepository();
                NewsLetterRepository objnlRepo = new NewsLetterRepository();
                foreach (ListItem listItem in chkUser.Items)
                {
                    objUser = objUserRepository.getUsersById(Guid.Parse(listItem.Value));
                    if (objUser.PaymentStatus.ToUpper() == "PAID")
                    {
                        listItem.Selected = true;
                    }

                }

            }
            catch (Exception Err)
            {
                logger.Error(Err.Message);
                Response.Write(Err.StackTrace);
            }
        }
        public void UpdateNewsLetter(NewsLetter nl)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        session.CreateQuery("Update NewsLetter set NewsLetterDetail =:NewsLetterDetail,UserId=:UserId,SendDate=:SendDate,SendStatus=:SendStatus where Id = :adsid")
                            .SetParameter("NewsLetterDetail", nl.NewsLetterDetail)
                            .SetParameter("UserId", nl.UserId)
                            .SetParameter("SendDate", nl.SendDate)
                            .SetParameter("SendStatus", nl.SendStatus)
                              .SetParameter("adsid", nl.Id)
                            .ExecuteUpdate();
                        transaction.Commit();

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        // return 0;
                    }
                }
            }
        }