示例#1
0
 public string AddNewsLatter(string ObjNewsLatter)
 {
     try
     {
         Domain.Socioboard.Domain.NewsLetter objnewsLatter = (Domain.Socioboard.Domain.NewsLetter)(new JavaScriptSerializer().Deserialize(ObjNewsLatter, typeof(Domain.Socioboard.Domain.NewsLetter)));
         objNewsLetterRepository.AddNewsLetter(objnewsLatter);
         return("Success");
     }
     catch (Exception ex)
     {
         return("Something went wrong!");
     }
 }
 public string AddNewsLatter(string ObjNewsLatter)
 {
     try
     {
         Domain.Myfashion.Domain.NewsLetter objnewsLatter = (Domain.Myfashion.Domain.NewsLetter)(new JavaScriptSerializer().Deserialize(ObjNewsLatter, typeof(Domain.Myfashion.Domain.NewsLetter)));
         ObjNewsLetterRepository.AddNewsLetter(objnewsLatter);
         return(new JavaScriptSerializer().Serialize("Success"));
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error : " + ex.StackTrace);
         return(new JavaScriptSerializer().Serialize("Something went wrong!"));
     }
 }
        //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);
            }
        }